UNPKG

@nodescript/stdlib

Version:
42 lines (41 loc) 1.08 kB
export const module = { version: '1.5.0', moduleName: 'Object', description: ` Creates an object with computed values per each key. Key can be a JSON pointer or a dot-delimited path. `, params: { properties: { schema: { type: 'object', properties: {}, additionalProperties: { type: 'any' }, }, }, }, result: { schema: { type: 'object', properties: {}, additionalProperties: { type: 'any' }, }, }, }; export const compute = (params, ctx) => { const { properties } = params; const obj = {}; for (const [key, value] of Object.entries(properties)) { if (key.startsWith('...')) { Object.assign(obj, value); } else if (key.startsWith('"') && key.endsWith('"')) { const k = key.substring(1, key.length - 1); obj[k] = value; } else { ctx.lib.set(obj, key, value); } } return obj; };