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.5 to 1.4.0

2

dist/index.js

@@ -59,4 +59,4 @@ "use strict";

};
const arrayLikeStringToArray = (s, token = ",") => s.split(token).map(element => element.trim());
const arrayLikeStringToArray = (s, token = ",") => s.split(token).map(element => element.trim()).filter(element => element !== "" && element !== null);
module.exports = parseKeys;
//# sourceMappingURL=index.js.map

@@ -169,2 +169,19 @@ "use strict";

});
test("single-element array (string)", () => {
const before = { list: "one," };
const result = _1.default(before);
expect(Array.isArray(result.list)).toBeTruthy();
expect(typeof result.list).toBe("object");
expect(result.list.length).toEqual(1);
expect(result).toEqual({ list: ["one"] });
});
test("single-element array (number)", () => {
const before = { list: "0.05," };
const result = _1.default(before);
expect(Array.isArray(result.list)).toBeTruthy();
expect(typeof result.list).toBe("object");
expect(result.list.length).toEqual(1);
expect(result.list[0]).toEqual(0.05);
expect(result).toEqual({ list: [0.05] });
});
test("array of numnbers", () => {

@@ -171,0 +188,0 @@ const before = { list: "0,1,2,4,8" };

{
"name": "parse-strings-in-object",
"version": "1.3.5",
"version": "1.4.0",
"description": "Convert string values in object to boolean and numbers",

@@ -5,0 +5,0 @@ "keywords": [

@@ -18,2 +18,6 @@ # Parse Strings in JS Object

Single-element arrays need you to provide a trailing comma to cue the parser appropriately:
* `"1.1,"` becomes `[1.1]` (single-element array of numbers)
* `"someString,"` becomes `["someString"]` (single-element array of strings)
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).

@@ -20,0 +24,0 @@

@@ -180,2 +180,21 @@ import parser from "./";

test("single-element array (string)", () => {
const before = { list: "one," };
const result = parser(before) as { list: string[] };
expect(Array.isArray(result.list)).toBeTruthy();
expect(typeof result.list).toBe("object");
expect(result.list.length).toEqual(1);
expect(result).toEqual({ list: ["one"]});
})
test("single-element array (number)", () => {
const before = { list: "0.05," };
const result = parser(before) as { list: number[] };
expect(Array.isArray(result.list)).toBeTruthy();
expect(typeof result.list).toBe("object");
expect(result.list.length).toEqual(1);
expect(result.list[0]).toEqual(0.05);
expect(result).toEqual({ list: [0.05]})
});
test("array of numnbers", () => {

@@ -182,0 +201,0 @@ const before = { list: "0,1,2,4,8" };

@@ -68,4 +68,4 @@ const parseKeys = <T>(obj: object): T =>

const arrayLikeStringToArray = (s: string, token: string = ",") =>
s.split(token).map(element => element.trim());
s.split(token).map(element => element.trim()).filter(element => element !== "" && element !== null);
export = parseKeys;

Sorry, the diff of this file is not supported yet

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