All Projects → es-shims → String.prototype.matchAll

es-shims / String.prototype.matchAll

Licence: MIT License
Spec-compliant polyfill for String.prototype.matchAll, in ES2020

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to String.prototype.matchAll

regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+42.86%)
Mutual labels:  regex, regexp, match
html-comment-regex
Regular expression for matching HTML comments
Stars: ✭ 15 (+7.14%)
Mutual labels:  string, regexp, match
String.prototype.trim
ES5 spec-compliant shim for String.prototype.trim
Stars: ✭ 13 (-7.14%)
Mutual labels:  polyfill, string, shim
Object.getOwnPropertyDescriptors
Spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5.
Stars: ✭ 19 (+35.71%)
Mutual labels:  polyfill, shim
array-includes
Array.prototype.includes spec-compliant polyfill
Stars: ✭ 42 (+200%)
Mutual labels:  polyfill, shim
is-regex
Is this value a JS regex?
Stars: ✭ 22 (+57.14%)
Mutual labels:  regex, regexp
js-diacritic-regex
Creates the inverse of transliterated string to a regex. What? Basically, diacritic insensitiveness
Stars: ✭ 20 (+42.86%)
Mutual labels:  regex, regexp
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (+85.71%)
Mutual labels:  regex, regexp
globrex
Glob to regular expression with support for extended globs.
Stars: ✭ 52 (+271.43%)
Mutual labels:  regex, regexp
RgxGen
Regex: generate matching and non matching strings based on regex pattern.
Stars: ✭ 45 (+221.43%)
Mutual labels:  regex, regexp
object-keys
Object.keys shim
Stars: ✭ 41 (+192.86%)
Mutual labels:  polyfill, shim
RegExp-Learning
学习正则表达式
Stars: ✭ 30 (+114.29%)
Mutual labels:  regex, regexp
dobbi
An open-source NLP library: fast text cleaning and preprocessing
Stars: ✭ 21 (+50%)
Mutual labels:  string, regexp
python-hyperscan
A CPython extension for the Hyperscan regular expression matching library.
Stars: ✭ 112 (+700%)
Mutual labels:  regex, regexp
es6-template-regex
Regular expression for matching es6 template delimiters in a string.
Stars: ✭ 15 (+7.14%)
Mutual labels:  regex, match
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+564.29%)
Mutual labels:  polyfill, shim
retrie
Efficient Trie-based regex unions for blacklist/whitelist filtering and one-pass mapping-based string replacing
Stars: ✭ 35 (+150%)
Mutual labels:  regex, regexp
regexp-expand
Show the ELisp regular expression at point in rx form.
Stars: ✭ 18 (+28.57%)
Mutual labels:  regex, regexp
IronRure
.NET Bindings to the Rust Regex Crate
Stars: ✭ 16 (+14.29%)
Mutual labels:  regex, regexp
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+307.14%)
Mutual labels:  regex, regexp

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].