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.3.0 to 1.3.1

1

dist/index.js

@@ -42,2 +42,3 @@ "use strict";

}
return result;
};

@@ -44,0 +45,0 @@ const convertArray = (a) => a.map(el => convert(el));

2

package.json
{
"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

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