parse-strings-in-object
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -20,3 +20,14 @@ let before = { | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
ipAddress: '192.168.1.101', | ||
listOfNumbers: ['0', '1', '2'], | ||
listOfObjects: [ | ||
{ | ||
id: 0, | ||
value: 'hello' | ||
}, | ||
{ | ||
id: 1, | ||
value: 'world' | ||
} | ||
] | ||
} | ||
@@ -23,0 +34,0 @@ |
@@ -8,4 +8,8 @@ const parseKeys = (obj) => | ||
if (typeof val === 'object') { | ||
let subtree = parseKeys(val); | ||
return {...acc, [key]: subtree}; | ||
if (Array.isArray(val)) { | ||
return {...acc, [key]: val}; | ||
} else { | ||
let subtree = parseKeys(val); | ||
return {...acc, [key]: subtree}; | ||
} | ||
} else { | ||
@@ -12,0 +16,0 @@ if (val === 'true') val = true; |
{ | ||
"name": "parse-strings-in-object", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Convert string values in object to boolean and numbers", | ||
@@ -13,5 +13,7 @@ "repository": "https://github.com/anselanza/parse-strings-in-object", | ||
"devDependencies": { | ||
"expect.js": "^0.3.1", | ||
"mocha": "^5.0.1" | ||
}, | ||
"dependencies": { | ||
"chai": "^4.1.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
const expect = require('expect.js'); | ||
const expect = require('chai').expect; | ||
const parser = require('../lib/index.js'); | ||
@@ -11,52 +11,96 @@ | ||
const result = parser(before); | ||
expect(result).to.eql({ foo: true, bar: false }); | ||
// expect(result).to.equal({ foo: true, bar: false }); | ||
expect(result.foo).to.equal(true); | ||
expect(result.bar).to.equal(false); | ||
}); | ||
it ('should parse a nested structure properly', () => { | ||
const before = { | ||
topLevel: true, | ||
topNumber: 1, | ||
foo: { | ||
active: 'true', | ||
number: '0', | ||
anotherNumber: '3.17', | ||
}, | ||
bar: { | ||
active: 'false', | ||
number: '10', | ||
aString: 'yo', | ||
subSub: { | ||
thisIsTrue: 'true', | ||
thisIsFalse: 'false', | ||
thisIsNumber: '0.00006' | ||
it('should retain arrays properly', () => { | ||
const before = { foo: 'true', list: ['one', 'two', 'three']}; | ||
const result = parser(before); | ||
expect(result).to.deep.equal({ foo: true, list: ['one', 'two', 'three']}); | ||
expect(result.list.length).to.equal(3); | ||
}); | ||
it('should retain array of objects properly', () => { | ||
const before = { | ||
foo: 'true', | ||
someObjs: [ | ||
{ | ||
id: 0, | ||
value: 'hello' | ||
}, | ||
{ | ||
id: 1, | ||
value: 'world' | ||
} | ||
}, | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
} | ||
] | ||
}; | ||
const result = parser(before); | ||
const expected = { | ||
topLevel: true, | ||
topNumber: 1, | ||
foo: { | ||
active: true, | ||
number: 0, | ||
anotherNumber: 3.17, | ||
}, | ||
bar: { | ||
active: false, | ||
number: 10, | ||
aString: 'yo', | ||
subSub: { | ||
thisIsTrue: true, | ||
thisIsFalse: false, | ||
thisIsNumber: 0.00006 | ||
} | ||
}, | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
} | ||
expect(result).to.eql(expected); | ||
expect(result).to.deep.equal( | ||
{ | ||
foo: true, | ||
someObjs: [ | ||
{ | ||
id: 0, | ||
value: 'hello' | ||
}, | ||
{ | ||
id: 1, | ||
value: 'world' | ||
} | ||
] | ||
} | ||
); | ||
expect(result.foo).to.equal(true); | ||
expect(result.someObjs.length).to.equal(2); | ||
}); | ||
}); | ||
// it ('should parse a nested structure properly', () => { | ||
// const before = { | ||
// topLevel: true, | ||
// topNumber: 1, | ||
// foo: { | ||
// active: 'true', | ||
// number: '0', | ||
// anotherNumber: '3.17', | ||
// }, | ||
// bar: { | ||
// active: 'false', | ||
// number: '10', | ||
// aString: 'yo', | ||
// subSub: { | ||
// thisIsTrue: 'true', | ||
// thisIsFalse: 'false', | ||
// thisIsNumber: '0.00006' | ||
// } | ||
// }, | ||
// justAString: 'hello', | ||
// ipAddress: '192.168.1.101' | ||
// } | ||
// const result = parser(before); | ||
// const expected = { | ||
// topLevel: true, | ||
// topNumber: 1, | ||
// foo: { | ||
// active: true, | ||
// number: 0, | ||
// anotherNumber: 3.17, | ||
// }, | ||
// bar: { | ||
// active: false, | ||
// number: 10, | ||
// aString: 'yo', | ||
// subSub: { | ||
// thisIsTrue: true, | ||
// thisIsFalse: false, | ||
// thisIsNumber: 0.00006 | ||
// } | ||
// }, | ||
// justAString: 'hello', | ||
// ipAddress: '192.168.1.101' | ||
// } | ||
// expect(result).to.equal(expected); | ||
// }); | ||
}); |
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
6625
1
155
1
+ Addedchai@^4.1.2
+ Addedassertion-error@1.1.0(transitive)
+ Addedchai@4.5.0(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addeddeep-eql@4.1.4(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedloupe@2.3.7(transitive)
+ Addedpathval@1.1.1(transitive)
+ Addedtype-detect@4.1.0(transitive)