regexp.prototype.flags

ES6 spec-compliant RegExp.prototype.flags shim.

MIT 17 个版本
安装
npm install regexp.prototype.flags
yarn add regexp.prototype.flags
pnpm add regexp.prototype.flags
bun add regexp.prototype.flags
README

RegExp.prototype.flags Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

An ES6 spec-compliant RegExp.prototype.flags shim. Invoke its "shim" method to shim RegExp.prototype.flags if it is unavailable. Note: RegExp#flags requires a true ES5 environment - specifically, one with ES5 getters.

This package implements the es-shim API interface. It works in an ES5-supported environment and complies with the spec.

Most common usage:

var flags = require('regexp.prototype.flags');
var assert = require('assert');

assert(flags(/a/) === '');
assert(flags(new RegExp('a')) === '');
assert(flags(/a/mig) === 'gim');
assert(flags(new RegExp('a', 'mig')) === 'gim');

if (!RegExp.prototype.flags) {
	flags.shim();
}

assert(flags(/a/) === /a/.flags);
assert(flags(new RegExp('a')) === new RegExp('a').flags);
assert(flags(/a/mig) === /a/mig.flags);
assert(flags(new RegExp('a', 'mig')) === new RegExp('a', 'mig').flags);

Tests

Simply clone the repo, npm install, and run npm test

版本列表
1.5.4 2025-01-03
1.5.3 2024-10-03
1.5.2 2024-02-11
1.5.1 2023-09-13
1.5.0 2023-04-19
1.4.3 2022-04-15
1.4.2 2022-04-13
1.4.1 2022-01-14
1.4.0 2022-01-14
1.3.2 2022-01-13
1.3.1 2021-01-15
1.3.0 2019-12-15
1.2.0 2017-10-25
1.1.1 2015-08-16
1.1.0 2015-08-16
1.0.1 2014-12-13
1.0.0 2014-12-10