HckApm/node_modules/string.prototype.matchall
minicx 99e5f883a3 second commit 2023-12-23 14:56:27 +03:00
..
.github second commit 2023-12-23 14:56:27 +03:00
test second commit 2023-12-23 14:56:27 +03:00
.editorconfig second commit 2023-12-23 14:56:27 +03:00
.eslintrc second commit 2023-12-23 14:56:27 +03:00
.nycrc second commit 2023-12-23 14:56:27 +03:00
CHANGELOG.md second commit 2023-12-23 14:56:27 +03:00
LICENSE second commit 2023-12-23 14:56:27 +03:00
README.md second commit 2023-12-23 14:56:27 +03:00
auto.js second commit 2023-12-23 14:56:27 +03:00
implementation.js second commit 2023-12-23 14:56:27 +03:00
index.js second commit 2023-12-23 14:56:27 +03:00
package.json second commit 2023-12-23 14:56:27 +03:00
polyfill-regexp-matchall.js second commit 2023-12-23 14:56:27 +03:00
polyfill.js second commit 2023-12-23 14:56:27 +03:00
regexp-matchall.js second commit 2023-12-23 14:56:27 +03:00
shim.js second commit 2023-12-23 14:56:27 +03:00

README.md

string.prototype.matchall Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

ES2020 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 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