@nodescript/stdlib
Version:
Standard Node Definitions
35 lines (34 loc) • 963 B
JavaScript
export const module = {
version: '1.1.6',
moduleName: 'Web / Search Params',
description: `
Creates a search parameters from key/value pairs,
suitable for using in URL query string, as well as
request POST body with application/x-www-urlencoded content type.
`,
params: {
params: {
schema: {
type: 'object',
properties: {},
additionalProperties: { type: 'any' },
},
},
},
result: {
schema: { type: 'any' },
},
};
export const compute = params => {
const searchParams = new URLSearchParams();
for (const [key, value] of Object.entries(params.params)) {
if (value === undefined) {
continue;
}
const arr = Array.isArray(value) ? value : [value];
for (const value of arr) {
searchParams.append(key, value);
}
}
return searchParams;
};