Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.
(TOC generated by verb using markdown-toc)
InstallInstall with npm
$ npm i expand-object --save
Also see collapse-object, for doing the reverse of this library.
Examples
Type castingexpand('a')
Â
expand('a.b')
Â
expand('a|b')
Â
expand('a|b', {toBoolean: true})
Â
expand('a:b')
Â
expand('a,b')
Introduced in v0.2.2, some values are cast to their JavaScript type.
Booleans
If the value is "true"
or "false"
it will be coerced to a boolean value.
expand('a:true')
expand('a:false')
Numbers
If the value is an integer it will be coerced to a number.
expand('a:1')
expand('a:123')
Regex
If the value is a simple regular expression it will be coerced to a new RegExp()
.
Installexpand('a:/foo/')
expand('a.b.c:/^bar/gmi')
Install with npm
CLI$ npm i expand-object --save
Usage with cli:
node.jsâ¯Â expand-object --help
Â
  Usage: expand-object [options] <string>
Â
  Expand a string into a JavaScript object using a simple notation.
Â
  Options:
Â
    -h, --help     output usage information
    -V, --version  output the version number
    -r, --raw      Output as raw javascript object - not stringified
Â
  Examples:
Â
    $ expand-object "a:b"
    $ expand-object --raw "a:b"
    $ echo "a:b" | expand-object
To use as a node.js library:
childrenvar expand = require('expand-object');
Expand dots into child objects:
siblingsexpand('a')
expand('a.b')
expand('a.b.c')
expand('a.b.c.d')
expand-object supports two kinds of siblings, general and adjacent. It's much easier to understand the difference in the last example.
general siblingsUse pipes (
|
) to expand general siblings:
adjacent siblingsexpand('a|b')
expand('a|b|c')
expand('a|b|c|d')
expand('a:b|c:d')
Use plus (
+
) to expand adjacent siblings:
Adjacent siblings are objects that immediately follow one another.
difference between sibling typesexpand('a:b+c:d')
expand('a.b:c+d:e')
In the example below:
d
is a sibling to a
d
is a sibling to b
key-value pairsexpand('a.b:c|d:e')
Â
expand('a.b:c+d:e')
Expand colons into key-value pairs:
arraysexpand('a:b')
expand('a.b:c')
expand('a.b.c:d')
Expand comma separated values into arrays:
Usage examplesexpand('a,b')
expand('a,b,c')
expand('a:b,c,d|e:f,g,h')
Expand siblings with comma separated values into arrays:
expand('a:b,c,d|e:f,g,h')
Expand children with comma separated values into arrays:
expand('a.b.c:d,e,f|g.h:i,j,k')
Expand sibling objects into key-value pairs:
expand('a:b|c:d')
expand('a:b|c:d|e:f')
expand('a:b|c:d|e:f|g:h')
Expand child objects into key-value pairs:
expand('a.b:c')
expand('a.b.c:d')
expand('a.b.c.d:e')
Expand sibling and child objects into key-value pairs:
Related projectsexpand('a:b|c:d')
expand('a.b.c|d.e:f')
expand('a.b:c|d.e:f')
expand('a.b.c:d|e.f.g:h')
expand-args: Expand parsed command line arguments using expand-object. | homepage
Running testsInstall dev dependencies:
Contributing$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
AuthorJon Schlinkert
LicenseCopyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb on December 23, 2015.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4