
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
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(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 56,872 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
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.