Socket
Socket
Sign inDemoInstall

string.prototype.matchall

Package Overview
Dependencies
65
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    string.prototype.matchall

Spec-compliant polyfill for String.prototype.matchAll


Version published
Weekly downloads
14M
decreased by-21.9%
Maintainers
1
Created
Weekly downloads
 

Package description

What is string.prototype.matchall?

The string.prototype.matchall npm package is a polyfill for the `String.prototype.matchAll` method, which returns an iterator of all results matching a string against a regular expression, including capturing groups. This package is particularly useful for environments that do not yet support the `matchAll` method natively.

What are string.prototype.matchall's main functionalities?

Matching all occurrences of a pattern

This feature allows you to find all occurrences of the pattern `/test/g` in the string `"test1test2"`. It returns an iterator that contains all matches.

"test1test2".matchAll(/test/g)

Capturing groups in matches

This demonstrates how to use capturing groups with `matchAll`. The regular expression `/(te)(st\d)/g` includes two capturing groups that match parts of the string. The result is an iterator of matches, where each match includes the full matched text and the text matched by each capturing group.

"test1test2".matchAll(/(te)(st\d)/g)

Other packages similar to string.prototype.matchall

Changelog

Source

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
<!-- auto-changelog-above -->

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

Readme

Source

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

Keywords

FAQs

Last updated on 25 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc