1. is-regex
Is this value a JS regex? Works cross-realm/iframe, and despite ES6 @@toStringTag
is-regex
Package: is-regex
Created by: inspect-js
Last modified: Fri, 09 Jun 2023 21:33:14 GMT
Version: 1.1.4
License: MIT
Downloads: 131,682,988
Repository: https://github.com/inspect-js/is-regex

Install

npm install is-regex
yarn add is-regex

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code