# regexp-match-indices

> RegExp Match Indices polyfill

Latest version **1.0.2** (published 2019-08-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install regexp-match-indices
pnpm add regexp-match-indices
yarn add regexp-match-indices
bun add regexp-match-indices
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-08-23 |
| First published | 2019-07-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 89.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ron Buckton |
| Maintainers | rbuckton |

## Links

- npm: https://www.npmjs.com/package/regexp-match-indices
- npm.io page: https://npm.io/package/regexp-match-indices

## Dependencies (1)

- [regexp-tree](https://npm.io/package/regexp-tree.md) ^0.1.11

## Recent versions

- 1.0.2 (latest) — 2019-08-23
- 1.0.1 — 2019-07-26
- 1.0.0 — 2019-07-26

## README

# regexp-match-indices

This package provides a polyfill/shim for the [RegExp Match Indices](https://github.com/tc39/proposal-regexp-match-indices) proposal.

The implementation is a replacement for `RegExp.prototype.exec` that approximates the beahvior of the proposal. Because `RegExp.prototype.exec` depends on a receiver (the `this` value), the main export accepts the `RegExp` to operate on as the first argument.

## Installation

```sh
npm install regexp-match-indices
```

## Usage

### Standalone

```js
const execWithIndices = require("regexp-match-indices");

const text = "zabbcdef";
const re = new RegExp("ab*(cd(?<Z>ef)?)");
const result = execWithIndices(re, text);
console.log(result.indices);    // [[1, 8], [4, 8], [6, 8]]
```

### Shim

```js
require("regexp-match-indices").shim();
// or
require("regexp-match-indices/shim")();
// or
require("regexp-match-indices/auto");

const text = "zabbcdef";
const re = new RegExp("ab*(cd(?<Z>ef)?)");
const result = re.exec(re, text);
console.log(result.indices);    // [[1, 8], [4, 8], [6, 8]]
```

## Configuration

The polyfill can be run in two modes: `"lazy"` (default) or `"spec-compliant"`. In `"spec-compliant"` mode, the `indices` property is populated and stored on the result as soon as `exec()` is called. This can have a significant performance penalty for existing RegExp's that do not use this feature. By default, the polyfill operates in `"lazy"` mode, where the `indices` property is defined using a getter and is only computed when first requested.

You can specify the configuration globally using the following:

```js
require("regexp-match-indices").config.mode = "spec-compliant"; // or "lazy"
// or
require("regexp-match-indices/config").mode = "spec-compliant"; // or "lazy"
```

---
_Source: https://npm.io/package/regexp-match-indices · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
