Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

string.prototype.matchall

Package Overview
Dependencies
8
Maintainers
1
Versions
13
Issues
File Explorer

Advanced tools

string.prototype.matchall

Spec-compliant polyfill for String.prototype.matchAll

    4.0.7latest

Version published
Maintainers
1
Weekly downloads
12,367,893
increased by1.78%

Weekly downloads

Changelog

Source

v4.0.7 - 2022-03-18

Commits

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

What is string.prototype.matchall?

Spec-compliant polyfill for String.prototype.matchAll

Is string.prototype.matchall popular?

The npm package string.prototype.matchall receives a total of 10,038,656 weekly downloads. As such, string.prototype.matchall popularity was classified as popular.

Is string.prototype.matchall well maintained?

We found that string.prototype.matchall demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 19 Mar 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc