@zerodep/is-regex
v2.0.7
Published
A utility to determine if a value is a regular expression
Downloads
14
Readme
@zerodep/is-regex
A simple, performant utility to determine if a value is a regular expression.
Full documentation is available at the zerodep.app page.
Examples
All @zerodep packages support both ESM and CJS.
import { isRegex } from '@zerodep/is-regex';
// or
const { isRegex } = require('@zerodep/is-regex');
Positive Response
isRegex(/[regex]+/gi); // true
isRegex(new RegExp('$[a-c]{2}]', 'gi')); // true
Negative Response
isRegex(['a', 'b', 'c']); // false
isRegex(1000n); // false
isRegex(true); // false
isRegex(new Date()); // false
isRegex(''); // false
isRegex(new Error('message')); // false
isRegex(3.14); // false
isRegex(() => 'function'); // false
isRegex(42); // false
isRegex(
new Map([
['a', 1],
['b', 2],
])
); // false
isRegex(null); // false
isRegex({ an: 'object' }); // false
isRegex(new Promise(() => {})); // false
isRegex(new Set([1, 2, 3])); // false
isRegex('a string'); // false
isRegex(Symbol()); // false
isRegex(new Int32Array(2)); // false
isRegex(undefined); // false