string.prototype.matchall

Spec-compliant ES2020 polyfill for String.prototype.matchAll.

Library
npm
v4.0.12
17stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
21/100Needs Attention
Development Activity0
Maintenance0
Community12
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture78
Code Quality82
Innovation62
Learning Curve80

string.prototype.matchall is an ES2020 spec-compliant shim for the native String.prototype.matchAll method, which returns an iterator of all matches of a global regular expression against a string, including capture groups and match indices. It lets you rely on matchAll semantics even in older or noncompliant JavaScript engines.

Built on the es-shim API, the package can be used directly as a standalone function or installed as a polyfill that patches the String prototype only when the native implementation is missing or broken. It is one of the most widely depended-upon packages on npm, downloaded tens of millions of times each week as a transitive dependency of build tooling and libraries.

What You Get

  • A standalone matchAll(string, regexp) function with spec-compliant behavior
  • A shim() method that patches String.prototype.matchAll only when required
  • Coercion of non-regex and non-global arguments to match the spec
  • Correct throwing on non-global regexes, matching native semantics
  • Compatibility down to ES3-supported environments

Common Use Cases

  • Supporting String.prototype.matchAll in older browsers or runtimes
  • Guaranteeing spec-correct matchAll behavior regardless of engine
  • Serving as a transitive polyfill dependency for build and lint tooling
  • Iterating over all regex matches with capture groups and indices

Under The Hood

Architecture - The package follows the standard es-shim layout: implementation.js holds the actual matchAll algorithm, polyfill.js decides whether the native method is usable or the shim is needed, shim.js installs it on String.prototype via define-properties, auto.js applies the shim on import, and index.js exposes the callable function plus .shim, .getPolyfill, and .implementation. Supporting regexp-matchall.js and polyfill-regexp-matchall.js provide the iterator plumbing.

Tech Stack - Plain JavaScript targeting ES3+ environments, leaning on a suite of es-shims/ljharb helper packages (es-abstract, call-bind, get-intrinsic, define-properties, regexp.prototype.flags, internal-slot, side-channel) to faithfully implement abstract operations from the ECMAScript spec. It conforms to the es-shim API, validated by es-shim-api in the lint step.

Code Quality - Testing is thorough: the test directory runs under tape with nyc coverage and includes es-shim’s shared harness, and the CI additionally runs a production audit. ESLint plus markdown eval (evalmd) guard the source and documentation examples. The library is authored by ljharb, a TC39 delegate, giving it strong spec fidelity.

API Design - The API is the well-established es-shim convention shared across dozens of sibling polyfills: a default callable that takes the receiver as its first argument, with attached shim/getPolyfill/implementation helpers. This consistency makes it predictable for anyone who has used another es-shim, with minimal boilerplate to either call directly or install globally.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search