4.0.11 • Published 9 days ago

string.prototype.matchall v4.0.11

Weekly downloads
6,916,688
License
MIT
Repository
github
Last release
9 days ago

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

eslint-plugin-reactairbnb-js-shims@surma/rollup-plugin-off-main-thread@yattho/stylelint-configeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imagereact-native-template-rfbaseairscanairscan-examplevulcan-cra-starterreact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdkgql_din_modcycle-utilsmutasi-bca@saeon/quick-formreact-native-printer-brothersxiao-dkreact-native-shekhar-bridge-testpriceitcogoportutilswilscanner@oiti/documentoscopy-react-nativequoc-test@infinitebrahmanuniverse/nolb-string_@saaspe/componentsexpand-react-bridgeluminos-ui-corestylelint-config-primersklif-ui-kitsklif-api@everything-registry/sub-chunk-2836jawwy-sdkjawwy_gamification_release@deepakorg/test@deepak757/testreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uimachinebeemrcapsreact-native-jawwy_samplekaaperkrondoleletherego932letsgoobraderhoteakarvickytea93klosokhaled-salem-custom-componentskintilidin15komodaa-react-native-controlled-mentionslembah1leonardsinggihtea46ihza32jonbitco12jmeter-to-k6joalvonsoanonsjohncarlonice21jp-gedenjordy-frijters-test-libjpearcey-eslint-plugin-react-safeminatonamikaze63mono-node-startermoonwalkerswap-default-token-lists@maxxim/mxmilsmxmilsmyzallnka-gantt-task-reactmicroend-componenthtml-mark-latin-stringjulien-easy-modaljrennsoh88-react-native-scroll-indicatorjsdoc-plugin-typescriptjusmelon204my-rizki-appnative-date-picker-modulenative-modal-damage-vehiclenative-kakao-loginnative-google-loginnative-apple-loginmy-library-buttonnew-awesome-4321next-i18n-keysmenyalatea021mama-exporternovacap-componentsnpm_qwertynpm_one_12_34_1_npm_one_1_2_3npm_one_2_2nukmytabru-envsub
4.0.11

9 days ago

4.0.9

7 months ago

4.0.10

7 months ago

4.0.8

1 year ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.2

4 years ago

3.0.1

5 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago