UNPKG

@amplience/dc-cli

Version:
21 lines (20 loc) 685 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isRegexString = isRegexString; exports.hasRegexSpecialCharacter = hasRegexSpecialCharacter; exports.removeEscapes = removeEscapes; function isRegexString(regex) { return regex.length > 1 && regex[0] === '/' && regex[regex.length - 1] === '/'; } function hasRegexSpecialCharacter(regex) { const regexMatch = /([^\\]|^)(\\\\)*[-\/^$*+?.()|[\]{}]/g; return regexMatch.test(regex); } function removeEscapes(regex) { for (let i = 0; i < regex.length; i++) { if (regex[i] === '\\') { regex = regex.substr(0, i) + regex.substr(i + 1); } } return regex; }