source: imaps-frontend/node_modules/string.prototype.matchall/README.md

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.3 KB
Line 
1# string.prototype.matchall <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![dependency status][deps-svg]][deps-url]
6[![dev dependency status][dev-deps-svg]][dev-deps-url]
7[![License][license-image]][license-url]
8[![Downloads][downloads-image]][downloads-url]
9
10[![npm badge][npm-badge-png]][package-url]
11
12ES2020 spec-compliant shim for String.prototype.matchAll. Invoke its "shim" method to shim `String.prototype.matchAll` if it is unavailable or noncompliant.
13
14This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment, and complies with the [spec](https://tc39.es/ecma262/#sec-string.prototype.matchall).
15
16Most common usage:
17```js
18const assert = require('assert');
19const matchAll = require('string.prototype.matchall');
20
21const str = 'aabc';
22const nonRegexStr = 'ab';
23const globalRegex = /[ac]/g;
24const nonGlobalRegex = /[bc]/i;
25
26// non-regex arguments are coerced into a global regex
27assert.deepEqual(
28 [...matchAll(str, nonRegexStr)],
29 [...matchAll(str, new RegExp(nonRegexStr, 'g'))]
30);
31
32assert.deepEqual([...matchAll(str, globalRegex)], [
33 Object.assign(['a'], { index: 0, input: str, groups: undefined }),
34 Object.assign(['a'], { index: 1, input: str, groups: undefined }),
35 Object.assign(['c'], { index: 3, input: str, groups: undefined }),
36]);
37
38assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw
39
40matchAll.shim(); // will be a no-op if not needed
41
42// non-regex arguments are coerced into a global regex
43assert.deepEqual(
44 [...str.matchAll(nonRegexStr)],
45 [...str.matchAll(new RegExp(nonRegexStr, 'g'))]
46);
47
48assert.deepEqual([...str.matchAll(globalRegex)], [
49 Object.assign(['a'], { index: 0, input: str, groups: undefined }),
50 Object.assign(['a'], { index: 1, input: str, groups: undefined }),
51 Object.assign(['c'], { index: 3, input: str, groups: undefined }),
52]);
53
54assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw
55
56```
57
58## Tests
59Simply clone the repo, `npm install`, and run `npm test`
60
61[package-url]: https://npmjs.com/package/string.prototype.matchall
62[npm-version-svg]: https://versionbadg.es/es-shims/String.prototype.matchAll.svg
63[deps-svg]: https://david-dm.org/es-shims/String.prototype.matchAll.svg
64[deps-url]: https://david-dm.org/es-shims/String.prototype.matchAll
65[dev-deps-svg]: https://david-dm.org/es-shims/String.prototype.matchAll/dev-status.svg
66[dev-deps-url]: https://david-dm.org/es-shims/String.prototype.matchAll#info=devDependencies
67[npm-badge-png]: https://nodei.co/npm/string.prototype.matchall.png?downloads=true&stars=true
68[license-image]: https://img.shields.io/npm/l/string.prototype.matchall.svg
69[license-url]: LICENSE
70[downloads-image]: https://img.shields.io/npm/dm/string.prototype.matchall.svg
71[downloads-url]: https://npm-stat.com/charts.html?package=string.prototype.matchall
72[codecov-image]: https://codecov.io/gh/es-shims/String.prototype.matchAll/branch/main/graphs/badge.svg
73[codecov-url]: https://app.codecov.io/gh/es-shims/String.prototype.matchAll/
74[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/String.prototype.matchAll
75[actions-url]: https://github.com/es-shims/String.prototype.matchAll/actions
Note: See TracBrowser for help on using the repository browser.