Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

string.prototype.matchall

es-shims98.7mMIT4.0.12TypeScript support: definitely-typed

Spec-compliant polyfill for String.prototype.matchAll

ES2020, ES, String.prototype.matchAll, matchAll, match, regex, regexp, regular, expression, matches

readme

string.prototype.matchall Version Badge

github actions coverage 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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v4.0.12 - 2024-12-19

Commits

  • [actions] split out node 10-20, and 20+ ec6bcb6
  • [Deps] update call-bind, es-abstract, get-intrinsic, gopd, has-symbols, internal-slot, regexp.prototype.flags, side-channel 993a80c
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, auto-changelog, mock-property, object-inspect, object.assign, tape 50e0c52
  • [Refactor] use call-bound directly 72c0fe1
  • [Tests] replace aud with npm audit 3a4bccb
  • [readme] remove dead badges ae4bdb2
  • [Dev Deps] add missing peer dep 14ceede

v4.0.11 - 2024-03-19

Commits

  • [Deps] update call-bind, define-properties, es-abstract, get-intrinsic, internal-slot, regexp.prototype.flags, set-function-name, side-channel 628a475
  • [Dev Deps] update aud, mock-property, npmignore, object-inspect, object.assign, object.entries, tape 21b67f2
  • [actions] remove redundant finisher 27e8b80
  • [Robustness] better cache original RegExp 92e9c59
  • [Robustness] use es-errors f6de643
  • [Refactor] use gopd 965a357
  • [Refactor] use es-object-atoms where possible 1d15123
  • [meta] add missing engines.node 04bdb31

v4.0.10 - 2023-09-12

Commits

  • [Refactor] use set-function-name a851cbb

v4.0.9 - 2023-08-28

Commits

  • [Deps] update define-properties, es-abstract, get-intrinsic, internal-slot, regexp.prototype.flags 819a5dd
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, es6-shim, object-inspect, object.entries, tape 6f479ee

v4.0.8 - 2022-11-07

Commits

  • [meta] use npmignore to autogenerate an npmignore file a08a8a1
  • [Deps] update define-properties, es-abstract, get-intrinsic, regexp.prototype.flags 6273f0f
  • [Tests] use mock-property 94e83a3
  • [Dev Deps] update @ljharb/eslint-config, aud, es5-shim, functions-have-names, object-inspect, object.assign, object.entries, tape 8024497
  • [actions] update rebase action to use reusable workflow 028abc0
  • [Tests] use for-each instead of foreach f68b771

v4.0.7 - 2022-03-18

Commits

  • [actions] reuse common workflows 798d359
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, es5-shim, object-inspect, tape 8733fa4
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape 2f0ac7d
  • [actions] update codecov uploader 40ea9ce
  • [Robustness] use call-bound indexOf b035fdc
  • [Deps] update has-symbols, regexp.prototype.flags 95768f2

v4.0.6 - 2021-10-04

Commits

  • [Refactor] use CreateRegExpStringIterator from es-abstract 5c2cf33
  • [patch] remove unused helpers 280f47e
  • [meta] add auto-changelog 2d26eda
  • [Deps] update es-abstract 857c8b0
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, es5-shim, object-inspect, object.entries, tape 9349ea2

v4.0.5 - 2021-05-25

Commits

  • [actions] use node/install instead of node/run; use codecov action a6a7af2
  • [readme] update badges, spec year 9532ccc
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, object-inspect 8ea3e71
  • [Deps] update es-abstract, has-symbols e906e75
  • [Dev Deps] update eslint, tape fcf2270
  • [actions] update workflows ba642c5
  • [Refactor] use get-intrinsic directly fca987f
  • [meta] use prepublishOnly script for npm 7+ 4c5ba45
  • [Deps] update es-abstract 39d34df

4.0.4 / 2021-02-21

  • [readme] fix repo URLs; remove travis badge
  • [meta] gitignore coverage output
  • [Deps] update call-bind, es-abstract, internal-slot, regexp.prototype.flags, side-channel
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, es5-shim, functions-have-names, object-inspect, object.entries, tape
  • [Tests] increase coverage
  • [actions] update workflows

4.0.3 / 2020-11-19

  • [meta] do not publish github action workflow files
  • [Deps] update es-abstract, side-channel; use call-bind where applicable; remove function-bind
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, es5-shim, es6-shim, functions-have-names, object-inspect, object.assign, object.entries, tape
  • [actions] add "Allow Edits" workflow
  • [actions] switch Automatic Rebase workflow to pull_request_target event
  • [Tests] migrate tests to Github Actions
  • [Tests] run nyc on all tests
  • [Tests] run es-shim-api in postlint; use tape runner
  • [Tests] only audit prod deps

4.0.2 / 2019-12-22

  • [Refactor] use internal-slot
  • [Refactor] use side-channel instead of "hidden" helper
  • [Deps] update es-abstract, internal-slot, regexp.prototype.flags, side-channel
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape

4.0.1 / 2019-12-13

  • [Refactor] use split-up es-abstract (61% bundle size decrease)
  • [Fix] fix error message: matchAll requires global
  • [Deps] update es-abstract, has-symbols
  • [Dev Deps] update eslint, @ljharb/eslint-config, functions-have-names, object-inspect, evalmd, object.entries; add safe-publish-latest
  • [meta] add funding field
  • [Tests] use shared travis-ci configs
  • [actions] add automatic rebasing / merge commit blocking

4.0.0 / 2019-10-03

  • [Breaking] throw on non-global/nullish flags
  • [Deps] update es-abstract

3.0.2 / 2019-10-02

  • [Fix] ensure that flagsGetter is only used when there is no flags property on the regex
  • [Fix] RegExp.prototype[Symbol.matchAll]: ToString the flags property
  • [Refactor] provide a consistent way to determine the polyfill for RegExp.prototype[Symbol.matchAll]
  • [meta] create FUNDING.yml
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, evalmd, functions-have-names, es5-shim, es6-shim, object.entries, tape
  • [Tests] up to node v12.11, v11.15, v10.16, v8.16, v6.17
  • [Tests] use functions-have-names
  • [Tests] bump audit level, due to https://github.com/reggi/evalmd/issues/13
  • [Tests] use npx aud instead of npm audit with hoops

3.0.1 / 2018-12-11

  • [Fix] update spec to follow committee feedback
  • [Deps] update define-properties
  • [Dev Deps] update eslint, @ljharb/eslint-config, es5-shim, es6-shim, tape
  • [Tests] use npm audit instead of nsp
  • [Tests] up to node v11.4, v10.14, v8.14, v6.15

3.0.0 / 2018-05-31

  • [Breaking] update to match latest spec
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, nsp, object-inspect, tape
  • [Tests] up to node v10.3, v9.11, v8.11, v6.14, v4.9
  • [Tests] regexes now have a "groups" property in ES2018
  • [Tests] run evalmd in prelint

2.0.0 / 2018-01-24

  • [Breaking] change to handle nonmatching regexes
  • [Breaking] non-regex arguments that are thus coerced to RegExp now get the global flag
  • [Deps] update es-abstract, regexp.prototype.flags
  • [Dev Deps] update es5-shim, eslint, object.assign
  • [Tests] up to node v9.4, v8.9, v6.12; pin included builds to LTS
  • [Tests] improve and correct tests and failure messages

1.0.0 / 2017-09-28

  • Initial release