inspect-parameters-declaration
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -7,5 +7,5 @@ 'use strict'; | ||
const isArrayLike = p => p.match(/^\[+/) || null; | ||
const isObjectLike = p => p.match(/^{+/) || null; | ||
const matchObjectProperty = p => p.match(/^([^{]+):(.*)/) || null; | ||
const isArrayLike = p => p.match(/^\[+/); | ||
const isObjectLike = p => p.match(/^{+/); | ||
const matchObjectProperty = p => p.match(/^([^{]+):(.*)/); | ||
@@ -62,9 +62,6 @@ function splitSkipBrackets(string, delimiter) { | ||
parametersArray.forEach(param => { | ||
if (isArrayLike(param)) { | ||
return destructureParametersFromArray(param, parameters); | ||
if (isArrayLike(param) || isObjectLike(param)) { | ||
return destructureParameter(param, parameters); | ||
} | ||
// const { parameter, defaultValue, declaration } = getParameterSpec(param); | ||
// parameters.push({ parameter, defaultValue, declaration }); | ||
parameters.push(getParameterSpec(param)); | ||
@@ -83,10 +80,8 @@ }); | ||
let [, key, value] = objectProperty.map(v => v.trim()); | ||
if (isObjectLike(value)) { | ||
return destructureParametersFromObject(value, parameters); | ||
if (isArrayLike(value) || isObjectLike(value)) { | ||
return destructureParameter(value, parameters); | ||
} | ||
} | ||
// const { parameter, defaultValue, declaration } = getParameterSpec(param); | ||
// parameters.push({ parameter, defaultValue, declaration }); | ||
parameters.push(getParameterSpec(param)); | ||
@@ -98,2 +93,12 @@ }); | ||
function destructureParameter(parameter, parameters) { | ||
if (isArrayLike(parameter)) { | ||
return destructureParametersFromArray(parameter, parameters); | ||
} | ||
if (isObjectLike(parameter)) { | ||
return destructureParametersFromObject(parameter, parameters); | ||
} | ||
} | ||
function destructureParameters(param) { | ||
@@ -131,6 +136,2 @@ const parametersArray = getParametersArray(param); | ||
if(!parametersArray || parametersArray.length === 1){ | ||
return inspectParameterFromString(parameters); | ||
} | ||
const inspectedParameters = parametersArray.reduce((result, parameter) => { | ||
@@ -137,0 +138,0 @@ const parameterSpec = inspectParameterFromString(parameter); |
{ | ||
"name": "inspect-parameters-declaration", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Inspects function's parameters declaration and returns information about it (e.g. names, default values, if needs destructuring, destructured parameters names and default values)", | ||
@@ -5,0 +5,0 @@ "main": "./lib/inspect-parameters-declaration.js", |
@@ -243,3 +243,3 @@ 'use strict'; | ||
input: `[p1,[p2 = '',[p3]]]=[]`, | ||
expectedResult: { | ||
expectedResult: [{ | ||
"parameter": "[p1,[p2 = '',[p3]]]", | ||
@@ -263,3 +263,3 @@ "defaultValue": "[]", | ||
] | ||
} | ||
}] | ||
}, | ||
@@ -269,3 +269,3 @@ | ||
input: function ([p1,[p2 = '',[p3]]]=[]) { return; }, | ||
expectedResult: { | ||
expectedResult: [{ | ||
"parameter": "[p1,[p2 = '',[p3]]]", | ||
@@ -289,3 +289,3 @@ "defaultValue": "[]", | ||
] | ||
} | ||
}] | ||
} | ||
@@ -292,0 +292,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
410
16330