string.prototype.matchall (4.0.12)
Published 2026-02-24 14:05:38 +00:00 by atheaadmin
Installation
registry=npm install string.prototype.matchall@4.0.12"string.prototype.matchall": "4.0.12"About this package
string.prototype.matchall 
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
Dependencies
Dependencies
| ID | Version |
|---|---|
| call-bind | ^1.0.8 |
| call-bound | ^1.0.3 |
| define-properties | ^1.2.1 |
| es-abstract | ^1.23.6 |
| es-errors | ^1.3.0 |
| es-object-atoms | ^1.0.0 |
| get-intrinsic | ^1.2.6 |
| gopd | ^1.2.0 |
| has-symbols | ^1.1.0 |
| internal-slot | ^1.1.0 |
| regexp.prototype.flags | ^1.5.3 |
| set-function-name | ^2.0.2 |
| side-channel | ^1.1.0 |
Development Dependencies
| ID | Version |
|---|---|
| @es-shims/api | ^2.5.1 |
| @ljharb/eslint-config | ^21.1.1 |
| auto-changelog | ^2.5.0 |
| encoding | ^0.1.13 |
| es5-shim | ^4.6.7 |
| es6-shim | ^0.35.8 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| for-each | ^0.3.3 |
| functions-have-names | ^1.2.3 |
| in-publish | ^2.0.1 |
| mock-property | ^1.1.0 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| object-inspect | ^1.13.3 |
| object.assign | ^4.1.7 |
| object.entries | ^1.1.8 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.9.0 |
Keywords
ES2020
ES
String.prototype.matchAll
matchAll
match
regex
regexp
regular
expression
matches
