UNPKG

@nodescript/stdlib

Version:
29 lines (28 loc) 824 B
export const module = { version: '1.2.4', moduleName: 'RegExp / Replace', description: ` Replaces all occurrences of a regular expression in a string. If the regexp is a string, it is converted to a regular expression with Global flag. Use RegExp node to create a regular expression with custom flags.' `, params: { string: { schema: { type: 'string' }, }, regexp: { schema: { type: 'any' }, }, replacement: { schema: { type: 'string' }, }, }, result: { schema: { type: 'string' }, } }; export const compute = (params, ctx) => { const { string, replacement } = params; const regexp = ctx.lib.toRegExp(params.regexp); return string.replace(regexp, replacement); };