Skip to content

Commit

Permalink
arrays handled differently, more like JSON.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
anselanza committed Jul 6, 2022
1 parent b6f0bc3 commit a4330eb
Show file tree
Hide file tree
Showing 5 changed files with 6,360 additions and 210 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ So:

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)

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)
Array-like strings (anything between `[]` brackets inside the string), 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).

Expand Down
Loading

0 comments on commit a4330eb

Please sign in to comment.