ezzy-config-setup
Advanced tools
Comparing version 0.1.16 to 0.1.17
{ | ||
"name": "ezzy-config-setup", | ||
"description": "A complex function configuration", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"author": { | ||
@@ -16,3 +16,2 @@ "name": "Moises Romero", | ||
"coverage": "node node_modules/ezzy-testing/coverage", | ||
"pretest": "npm install", | ||
"test": "node node_modules/ezzy-testing", | ||
@@ -19,0 +18,0 @@ "prebuild": "npm install", |
@@ -41,3 +41,3 @@ /*! | ||
* ["method:string"], | ||
* ["config:object", "callback"] | ||
* ["config:object", "callback:function|undefined"] | ||
* ); | ||
@@ -124,3 +124,4 @@ * | ||
let name; | ||
let type; | ||
let types; | ||
let optional; | ||
let value; | ||
@@ -167,8 +168,12 @@ let origConfig; | ||
value = allArgs[i][s].split(':'); | ||
name = value[0]; | ||
type = value[1] || '*'; | ||
name = value[0].trim(); | ||
types = (value[1] || '').replace(/\s/g, '').split(/[,|]/); | ||
optional = /\?/.test(value[1]) || | ||
types.includes('*') || types.includes('undefined'); | ||
if (name === 'this' && trueTypeOf(args[s]) === 'object') { | ||
extend(config, args[s]); | ||
} else if (type === '*' || trueTypeOf(args[s]) === type) { | ||
} else if (optional) { | ||
config[name] = args[s] === undefined ? config[name] : args[s]; | ||
} else if (types.includes(trueTypeOf(args[s]))) { | ||
config[name] = args[s]; | ||
@@ -175,0 +180,0 @@ } else { |
@@ -82,2 +82,16 @@ const configSetup = require('./configSetup'); | ||
it('should define an optional configuration properly', () => { | ||
const getConfig = (...args) => configSetup({ | ||
arrayProp: [], | ||
optionalBoolean: false | ||
}, args, | ||
['arrayProp : array?', 'optionalBoolean : boolean | undefined']); | ||
let config = getConfig(undefined, true); | ||
expect(config.arrayProp).toEqual([]); | ||
expect(config.optionalBoolean).toBe(true); | ||
config = getConfig([1,2,3], undefined); | ||
expect(config.arrayProp).toEqual([1,2,3]); | ||
expect(config.optionalBoolean).toBe(false); | ||
}); | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13768
8
265
1