github-pages-deploy-action/node_modules/string.prototype.matchall
2020-03-06 22:45:40 -05:00
..
.github Dependencies 2020-03-06 22:45:40 -05:00
helpers Dependencies 2020-03-06 22:45:40 -05:00
node_modules/has-symbols Dependencies 2020-03-06 22:45:40 -05:00
test Dependencies 2020-03-06 22:45:40 -05:00
.eslintignore Dependencies 2020-03-06 22:45:40 -05:00
.eslintrc Dependencies 2020-03-06 22:45:40 -05:00
.travis.yml Dependencies 2020-03-06 22:45:40 -05:00
auto.js Dependencies 2020-03-06 22:45:40 -05:00
CHANGELOG.md Dependencies 2020-03-06 22:45:40 -05:00
implementation.js Dependencies 2020-03-06 22:45:40 -05:00
index.js Dependencies 2020-03-06 22:45:40 -05:00
LICENSE Dependencies 2020-03-06 22:45:40 -05:00
package.json Dependencies 2020-03-06 22:45:40 -05:00
polyfill-regexp-matchall.js Dependencies 2020-03-06 22:45:40 -05:00
polyfill.js Dependencies 2020-03-06 22:45:40 -05:00
README.md Dependencies 2020-03-06 22:45:40 -05:00
regexp-matchall.js Dependencies 2020-03-06 22:45:40 -05:00
shim.js Dependencies 2020-03-06 22:45:40 -05:00

string.prototype.matchall Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

ES Proposal spec-compliant shim for String.prototype.matchAll. Invoke its "shim" method to shim String.prototype.matchAll if it is unavailable or noncompliant.

This package implements the es-shim API interface. It works in an ES3-supported environment, and complies with the proposed spec.

Most common usage:

const assert = require('assert');
const matchAll = require('string.prototype.matchall');

const str = 'aabc';
const nonRegexStr = 'ab';
const globalRegex = /[ac]/g;
const nonGlobalRegex = /[bc]/i;

// non-regex arguments are coerced into a global regex
assert.deepEqual(
	[...matchAll(str, nonRegexStr)],
	[...matchAll(str, new RegExp(nonRegexStr, 'g'))]
);

assert.deepEqual([...matchAll(str, globalRegex)], [
	Object.assign(['a'], { index: 0, input: str, groups: undefined }),
	Object.assign(['a'], { index: 1, input: str, groups: undefined }),
	Object.assign(['c'], { index: 3, input: str, groups: undefined }),
]);

assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw

matchAll.shim(); // will be a no-op if not needed

// non-regex arguments are coerced into a global regex
assert.deepEqual(
	[...str.matchAll(nonRegexStr)],
	[...str.matchAll(new RegExp(nonRegexStr, 'g'))]
);

assert.deepEqual([...str.matchAll(globalRegex)], [
	Object.assign(['a'], { index: 0, input: str, groups: undefined }),
	Object.assign(['a'], { index: 1, input: str, groups: undefined }),
	Object.assign(['c'], { index: 3, input: str, groups: undefined }),
]);

assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw

Tests

Simply clone the repo, npm install, and run npm test