@nodescript/stdlib
Version:
Standard Node Definitions
26 lines (25 loc) • 646 B
JavaScript
export const module = {
version: '1.2.4',
moduleName: 'RegExp / Match',
description: `
Matches a string against a regular expression.
Returns an array of matched groups, or an empty array if nothing matched.
`,
params: {
string: {
schema: { type: 'string' },
},
regexp: {
schema: { type: 'any' },
},
},
result: {
schema: { type: 'any' },
}
};
export const compute = (params, ctx) => {
const { string } = params;
const regexp = ctx.lib.toRegExp(params.regexp);
const match = regexp.exec(string);
return match ?? [];
};