parse-strings-in-object
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -42,2 +42,3 @@ "use strict"; | ||
} | ||
return result; | ||
}; | ||
@@ -44,0 +45,0 @@ const convertArray = (a) => a.map(el => convert(el)); |
{ | ||
"name": "parse-strings-in-object", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Convert string values in object to boolean and numbers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,9 +7,13 @@ # Parse Strings in JS Object | ||
So: | ||
* `'true'` and `'false'` becomes `true` and `false` | ||
* `'1'` and `'3.147'` become `1` and `3.147` | ||
* `'192.168.1.1'` is left alone even though it "looks" like a number | ||
* `'null'` becomes `null` | ||
* `"true"` and `"false"` becomes `true` and `false` | ||
* `"1"` and `"3.147"` become `1` and `3.147` | ||
* `"192.168.1.1"` is left alone even though it "looks" like a number | ||
* `"null"` becomes `null` | ||
It works recursively, so nested structures are no problem. | ||
Array-like strings (currently, only comma-separated values are intepreted like this), are converted too: | ||
* `"test,one,two,three"` becomes `["test","one","two","three"]` (an array of strings) | ||
* `"0,1,2,3"` becomes `[0,1,2,3]` (an array of numbers) | ||
This module was originally inspired by the experience of using a configuration module ([rc](https://www.npmjs.com/package/rc)) and having to check things like `active === false || active === 'false'` repeatedly. I have therefore provided an example of this use case [below](#example-in-rc-config). | ||
@@ -36,4 +40,4 @@ | ||
aFloat: 1.1, | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
justAString: "hello", | ||
ipAddress: "192.168.1.101" | ||
} | ||
@@ -51,4 +55,4 @@ | ||
aFloat: 1.1, | ||
justAString: 'hello', | ||
ipAddress: '192.168.1.101' | ||
justAString: "hello", | ||
ipAddress: "192.168.1.101" | ||
} | ||
@@ -59,3 +63,3 @@ 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). | ||
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). | ||
@@ -69,3 +73,3 @@ | ||
const conf = require('parse-strings-in-object')(require('rc')('myapp', { | ||
anOrdinaryString: 'test', | ||
anOrdinaryString: "test", | ||
aBoolean: true, | ||
@@ -82,4 +86,4 @@ aNumber: 9000 | ||
``` | ||
'isMaster': 'true', | ||
myNumber: '0' | ||
"isMaster": "true", | ||
myNumber: "0" | ||
``` | ||
@@ -86,0 +90,0 @@ So, now: |
@@ -49,3 +49,3 @@ const parseKeys = <T>(obj: object): T => | ||
return result; | ||
}; | ||
@@ -52,0 +52,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28702
518
100
0