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.1.4 to 1.1.5

2

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

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