@nxworker/workspace
Version:
Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports
25 lines (24 loc) • 981 B
JavaScript
/**
* Escape characters with special meaning outside character classes.
* Use a simple backslash escape when it’s always valid.
* Prevents ReDoS (Regular Expression Denial of Service) attacks
* @remarks To escape character classes, use `RegExp.escape` or a `core-js-pure` polyfill.
* @param str - The string to escape
* @returns The escaped string safe for use in regular expressions
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "escapeRegex", {
enumerable: true,
get: function() {
return escapeRegex;
}
});
function escapeRegex(str) {
// Escape characters that have special meaning in regular expressions.
// Hyphen (`-`) does not need escaping outside of character classes, so leave it as-is
// to match existing test expectations and avoid altering harmless filenames.
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
}
//# sourceMappingURL=escape-regex.js.map