is-regex

Is this value a JS regex? Works cross-realm/iframe, and despite ES6 @@toStringTag

MIT 14 个版本
安装
npm install is-regex
yarn add is-regex
pnpm add is-regex
bun add is-regex
README

is-regex Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Is this value a JS regex? This module works cross-realm/iframe, and despite ES6 @@toStringTag.

Example

var isRegex = require('is-regex');
var assert = require('assert');

assert.notOk(isRegex(undefined));
assert.notOk(isRegex(null));
assert.notOk(isRegex(false));
assert.notOk(isRegex(true));
assert.notOk(isRegex(42));
assert.notOk(isRegex('foo'));
assert.notOk(isRegex(function () {}));
assert.notOk(isRegex([]));
assert.notOk(isRegex({}));

assert.ok(isRegex(/a/g));
assert.ok(isRegex(new RegExp('a', 'g')));

Tests

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

版本列表
1.2.1 2024-12-12
1.2.0 2024-11-30
1.1.4 2021-08-06
1.1.3 2021-05-08
1.1.2 2021-02-01
1.1.1 2020-08-04
1.1.0 2020-06-04
1.0.5 2019-12-15
1.0.4 2017-02-18
1.0.3 2015-01-30
1.0.2 2015-01-29
1.0.1 2015-01-28
1.0.0 2014-05-19
0.0.0 2014-01-15