@nodescript/stdlib
Version:
Standard Node Definitions
23 lines (22 loc) • 637 B
JavaScript
export const module = {
version: '1.0.4',
moduleName: 'RegExp / Escape',
description: `
Escapes the characters that have special meaning in regular expressions.
Used to create regular expressions that match characters like dot, question mark, dollar sign,
curly and square brackets, parentheses, etc.
`,
params: {
string: {
schema: { type: 'string' },
},
},
result: {
schema: { type: 'string' },
}
};
export const compute = params => {
return params.string
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
.replace(/-/g, '\\x2d');
};