Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
object-to-arguments
Advanced tools
Transforms object's properties into an array of arguments tailored for a specific function, respecting the expected order and handling destructuring and rest parameters when needed.
Transforms object's properties into an array of arguments tailored for a specific function, respecting the expected order and handling destructuring and rest parameters when needed.
npm install object-to-arguments
CLI
npm install object-to-arguments -g
objectToArguments.call(fn, object);
objectToArguments.call(fn, object);
fn must be a function reference or a function stringified (e.g. fn.toString()
) for which the arguments array will be created for.
object is a flat object literal containing all the parameters names and its desired arguments. Note that in case of destructuring parameters, the object must still be flat, and the engine will create the structure needed for it.
const objectToArguments = require('object-to-arguments');
const fn = (a = 'defaultA', b, ...args) => {
return { a, b, args};
};
const objectArgs = {
extra1: 'EXTRA1',
b: 'argB',
extra2: 'EXTRA2'
};
// fnArguments = [ undefined, 'argB', 'EXTRA1', 'EXTRA2' ]
const fnArguments = objectToArguments(fn, objectArgs);
// fnReturn = { a: 'defaultA', b: 'argB', args: [ 'EXTRA1', 'EXTRA2' ] }
const fnReturn = fn(...fnArguments);
An example with complex destructuring parameters and default values set in many ways
const objectToArguments = require('object-to-arguments');
const fn = function([a, [b, [c, [d,e] = ['dD', 'dE'] ]]] = ['dA', ['dB', ['dC', ]]], {f} = {}, {g = 'dG'} = {}, {h: {i} = {}} = {},{j: {k = 'dK'} = {}} = {},{l: {m, n: {o} = {}} = {}} = {}, {p,q = 'dQ', r} = {}, [[[s,{t: {u} = {}} = {}]]] = [[[]]], {v: [{w} = {}, x = 'dX'] = []} = {}) {
return { a, b, c, d, e, f, g, i, k, m, o, p, q, r, s, u, w, x, arguments };
};
const objectArgs = {
a: 'aA',
b: 'aB',
c: 'aC',
f: 'aF',
k: 'aK',
p: 'aP',
q: 'aQ',
s: 'aS',
u: 'aU',
v: 'aV',
w: 'aW',
x: 'aX',
extra1: 'EXTRA1',
extra2: 'EXTRA2'
};
const fnArgs = objectToArguments(fn, objectArgs);
const fnReturn = fn(...fnArgs);
/////////////////////
// fnArgs will be: //
/////////////////////
// [
// [
// "aA",
// [
// "aB",
// [
// "aC",
// undefined
// ]
// ]
// ],
// {
// "f": "aF"
// },
// undefined,
// undefined,
// {
// "j": {
// "k": "aK"
// }
// },
// undefined,
// {
// "p": "aP",
// "q": "aQ"
// },
// [
// [
// [
// "aS",
// {
// "t": {
// "u": "aU"
// }
// }
// ]
// ]
// ],
// {
// "v": [
// {
// "w": "aW"
// },
// "aX"
// ]
// },
// "aV",
// "EXTRA1",
// "EXTRA2"
// ]
///////////////////////
// fnReturn will be: //
///////////////////////
// {
// "a": "aA",
// "b": "aB",
// "c": "aC",
// "d": "dD",
// "e": "dE",
// "f": "aF",
// "g": "dG",
// "k": "aK",
// "p": "aP",
// "q": "aQ",
// "s": "aS",
// "u": "aU",
// "w": "aW",
// "x": "aX",
// "arguments": {
// "0": [
// "aA",
// [
// "aB",
// [
// "aC",
// null
// ]
// ]
// ],
// "1": {
// "f": "aF"
// },
// "4": {
// "j": {
// "k": "aK"
// }
// },
// "6": {
// "p": "aP",
// "q": "aQ"
// },
// "7": [
// [
// [
// "aS",
// {
// "t": {
// "u": "aU"
// }
// }
// ]
// ]
// ],
// "8": {
// "v": [
// {
// "w": "aW"
// },
// "aX"
// ]
// },
// "9": "aV",
// "10": "EXTRA1",
// "11": "EXTRA2"
// }
// }
FAQs
Transforms object's properties into an array of arguments tailored for a specific function, respecting the expected order and handling destructuring and rest parameters when needed.
The npm package object-to-arguments receives a total of 34,092 weekly downloads. As such, object-to-arguments popularity was classified as popular.
We found that object-to-arguments demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.