Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexp-match-indices

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-match-indices

RegExp Match Indices polyfill

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1M
decreased by-21.69%
Maintainers
1
Weekly downloads
 
Created
Source

regexp-match-indices

This package provides a polyfill/shim for the 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

npm install regexp-match-indices

Usage

Standalone

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

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:

require("regexp-match-indices").config.mode = "spec-compliant"; // or "lazy"
// or
require("regexp-match-indices/config").mode = "spec-compliant"; // or "lazy"

FAQs

Package last updated on 23 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc