flatulence
Advanced tools
Comparing version 0.2.2 to 0.2.4
@@ -7,3 +7,9 @@ | ||
inflate(map, prefix = '', result = {}) { | ||
inflate(map, prefix = '', result) { | ||
if(!result) { | ||
if(pointsAtArray(map, prefix)) result = [] | ||
else result = {} | ||
} | ||
const subMap = buildMatchingMap(map, prefix) | ||
@@ -21,3 +27,8 @@ | ||
const pointsAtArray = (map, prefix) => { | ||
const key = Object.keys(map).find(key => key.startsWith(prefix)) | ||
return key && key.charAt(prefix.length) === '[' | ||
} | ||
// Returns an object with all key-value pairs | ||
@@ -24,0 +35,0 @@ // matching the given prefix |
{ | ||
"name": "flatulence", | ||
"version": "0.2.2", | ||
"version": "0.2.4", | ||
"description": "Flatten objects and arrays so that each key is the full path to a primitive value. Paths are lodash-compatible. Inflate flattened objects and make them regular JS objects again.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,5 +8,5 @@ const assert = require('assert') | ||
describe('#deflate()', () => { | ||
describe('#flatten()', () => { | ||
it('should flatten object', () => { | ||
const flattened = fl.deflate(data) | ||
const flattened = fl.flatten(data) | ||
@@ -20,3 +20,3 @@ console.log(flattened) | ||
const prefix = 'this.is.my.custom.prefix' | ||
const flattened = fl.deflate( | ||
const flattened = fl.flatten( | ||
{ | ||
@@ -36,19 +36,29 @@ id: 'anid', | ||
describe('#inflate()', () => { | ||
it('should reverse flattened object to an inflated one', () => { | ||
describe('#unflatten()', () => { | ||
it('should reverse flattened object to an unflattened one', () => { | ||
const flattened = fl.flatten(data) | ||
const inflated = fl.unflatten(flattened) | ||
const unflattened = fl.unflatten(flattened) | ||
assert.deepEqual(data, inflated) | ||
assert.deepEqual(data, unflattened) | ||
}) | ||
it('should reverse flattened object to an inflated one at a prefix', () => { | ||
const flattened = fl.deflate(data) | ||
const inflated = fl.inflate(flattened, 'cc') | ||
it('should reverse flattened object to an unflattened one at a prefix', () => { | ||
const flattened = fl.flatten(data) | ||
const unflattened = fl.unflatten(flattened, 'cc') | ||
assert.deepEqual(data.cc, inflated) | ||
assert.deepEqual(data.cc, unflattened) | ||
}) | ||
it('should produce an unflat array when prefix points at array', () => { | ||
const flattened = fl.flatten(data) | ||
const unflattened = fl.unflatten(flattened, 'cc.contract.multiContractSetup') | ||
console.log('unflattened', unflattened) | ||
assert.ok(Array.isArray(unflattened)) | ||
}) | ||
}) | ||
}) |
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
9079
229