util-ex
Version:
Browser-friendly enhanced util fully compatible with standard node.js
21 lines (20 loc) • 650 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.isRegExpStr = isRegExpStr;
/**
* Determines if a string represents a valid JavaScript RegExp.
* @param {string} aRegExpString - The string to test.
* @returns {boolean} - True if the string represents a valid EegExp, false otherwise.
* @example
* isRegExpStr('/[a-z]/g') // true
* isRegExpStr('/not a regexp') // false
*/
function isRegExpStr(value) {
const result = typeof value === 'string' && value.length > 2 && value[0] === '/' && value.lastIndexOf('/') > 0;
return result;
}
;
var _default = exports.default = isRegExpStr;