Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-strings-in-object

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-strings-in-object - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

13

example/example.js

@@ -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

lib/index.js

@@ -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);
// });
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc