parse-strings-in-object
Advanced tools
Comparing version 1.1.4 to 1.1.5
{ | ||
"name": "parse-strings-in-object", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Convert string values in object to boolean and numbers", | ||
@@ -5,0 +5,0 @@ "keywords": ["json", "parser", "types", "configuration", "utilities", "strings", "objects"], |
@@ -33,5 +33,6 @@ # Parse Strings in JS Object | ||
``` | ||
let before = { | ||
topLevel: true, | ||
topNumber: 1, | ||
const before = { | ||
active: true, | ||
anInt: 1, | ||
aFloat: 1.1, | ||
justAString: 'hello', | ||
@@ -41,6 +42,4 @@ ipAddress: '192.168.1.101' | ||
let after = require('parse-strings-in-object')(before); | ||
console.log('before:', before); | ||
console.log('after:', JSON.stringify(after, null, 4)); | ||
let after = require("parse-strings-in-object")(before); | ||
console.log(JSON.stringify(after, null, 4), typeof after.aFloat, 'and also a', typeof after.anInt); | ||
``` | ||
@@ -51,8 +50,13 @@ | ||
{ | ||
"topLevel": true, | ||
"topNumber": 1, | ||
"justAString": "hello", | ||
"ipAddress": "192.168.1.101" | ||
active: true, | ||
anInt: 1, | ||
aFloat: 1.1, | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
} | ||
number | ||
and also a | ||
number | ||
``` | ||
Notice that both ints and floats are converted correctly to the single `number` type, and a number-like string such as an IP address is left alone (stays a string). | ||
@@ -59,0 +63,0 @@ ## Development and testing |
@@ -23,2 +23,11 @@ const expect = require('chai').expect; | ||
it('should convert strings-as-numbers into real numbers', () => { | ||
const before = { aNumber: '1', another: '0', andAnother: '42' }; | ||
const result = parser(before); | ||
expect(result.aNumber).to.equal(1); | ||
expect(typeof result.aNumber).to.equal('number'); | ||
expect(typeof result.another).to.equal('number'); | ||
expect(typeof result.andAnother).to.equal('number'); | ||
}); | ||
it('should retain array of objects properly', () => { | ||
@@ -25,0 +34,0 @@ const before = { |
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
7584
168
66