JSPM

string-match-all

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 785
  • Score
    100M100P100Q101457F
  • License MIT

`String.prototype.matchAll` ponyfill.

Package Exports

  • string-match-all
  • string-match-all/package.json

Readme

string-match-all

Build Status BrowserStack Status

String.prototype.matchAll ponyfill.

The String.prototype.matchAll returns an iterator of all results matching a string against a regular expression, including capturing groups.

Install

npm install string-match-all --save

Usage

import matchAll from 'string-match-all';

const matches = [...matchAll('test1test2', /t(e)(st(\d?))/g)];

// ["test1", "e", "st1", "1", index: 0, input: "test1test2"]
// ["test2", "e", "st2", "2", index: 5, input: "test1test2"]

You can use named export preferNative if you wish to use native implementation if it’s available. In all other cases, ponyfill will be used. Beware of caveats!

API

matchAll(string, matcher)

Returns: Iterator

string

Type: string

String to match.

matcher

Type: string|RegExp

Value to match original string.

If a non-RegExp object is passed, it is implicitly converted to a RegExp by using new RegExp(regexp, 'g').

The RegExp object must have the global flag, otherwise a TypeError will be thrown.

Browser support

Tested in IE11+ and all modern browsers.

Test

Test suite is taken and modified from es-shims test suite.

For automated tests, run npm run test:automated (append :watch for watcher support).

License

MIT © Ivan Nikolić