@cdxoo/flat
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "@cdxoo/flat", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "does not flatten cats", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -46,3 +46,2 @@ 'use strict'; | ||
handlePropertiesOnNonObjects = 'throw', | ||
extraHandling, | ||
} = options; | ||
@@ -77,10 +76,2 @@ | ||
if (extraHandling) { | ||
({ token, value } = extraHandling({ | ||
route, | ||
token, | ||
value | ||
})); | ||
} | ||
//let containerValue = container.getValue(); | ||
@@ -95,9 +86,5 @@ var containerValue = container.getValue(); | ||
route, | ||
root: out, | ||
parent: parent.getValue(), | ||
erroneousPath: path.slice(0, i), | ||
erroneousKey: container.token, | ||
erroneousValue: containerValue, | ||
currentKey: token, | ||
currentValue: value, | ||
path: currentPath, | ||
token, | ||
value | ||
}) | ||
@@ -104,0 +91,0 @@ } |
@@ -166,12 +166,5 @@ 'use strict'; | ||
}, { handlePropertiesOnNonObjects: (bag) => { | ||
var { | ||
route, | ||
parent, | ||
erroneousKey, | ||
erroneousValue, | ||
currentKey, | ||
currentValue, | ||
} = bag; | ||
parent[erroneousKey] = { [currentKey]: currentValue }; | ||
var { route, token, value } = bag; | ||
var [ container, parent ] = route; | ||
parent.getValue()[container.token] = { [token]: value }; | ||
}}); | ||
@@ -191,24 +184,18 @@ | ||
}, { handlePropertiesOnNonObjects: (bag) => { | ||
var { | ||
root, | ||
parent, | ||
erroneousPath, | ||
erroneousKey, | ||
erroneousValue, | ||
currentKey, | ||
currentValue | ||
} = bag; | ||
if (typeof parent !== 'object') { | ||
var current = root; | ||
for (var [ ix, token ] of erroneousPath.entries()) { | ||
if (typeof current[token] !== 'object') { | ||
current[token] = {}; | ||
var { route, path, token, value } = bag; | ||
var [ root ] = route.slice(-1); | ||
var [ container, parent ] = route; | ||
if (typeof parent.getValue() !== 'object') { | ||
var current = root.getValue(); | ||
for (var it of path.slice(0, -1)) { | ||
if (typeof current[it] !== 'object') { | ||
current[it] = {}; | ||
} | ||
current = current[token]; | ||
current = current[it]; | ||
} | ||
current[currentKey] = currentValue; | ||
current[token] = value; | ||
} | ||
else { | ||
parent[erroneousKey] = { [currentKey]: currentValue }; | ||
parent.getValue()[container.token] = { [token]: value }; | ||
} | ||
@@ -227,23 +214,11 @@ }}); | ||
var out = unflatten({ | ||
'foo.[0]': 'a', | ||
'foo.[1]': 'b', | ||
'foo.[2]': 'c', | ||
}, { | ||
traverseArrays: true, | ||
extraHandling: (bag) => { | ||
var { route, token, value } = bag; | ||
var [ container, parent ] = route | ||
if ( | ||
!Array.isArray(container.getValue()) | ||
&& /\[\d+\]/.test(token) | ||
) { | ||
parent.getValue()[container.token] = [] | ||
} | ||
return { token: token.replace(/[\[\]]/g, ''), value }; | ||
} | ||
'foo': [], | ||
'foo.0': 'a', | ||
'foo.1': 'b', | ||
'foo.2.x': 'c', | ||
}); | ||
expect(out).to.eql({ | ||
foo: [ 'a', 'b', 'c' ] | ||
foo: [ 'a', 'b', { x: 'c' }] | ||
}); | ||
}) | ||
}) |
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
11865
307