collapse-object
Collapse an object into a string using the syntax from expand-object. This syntax is pretty handy for setting command line arguments, for expanding/collapsing test fixtures, etc.
Install
Install with npm
$ npm i collapse-object --save
Usage
var collapse = ; //=> 'a.b.c:1,2,3'
Re-expand a collapsed string with expand-object:
var expand = ;//=> {a: {b: {c: [1, 2, 3]}}}
collapse an object
//=> 'a:b' //=> {a: 'b'}
collapse objects with number values
//=> 'a:0'//=> 'a:1' //=> {a: 0}//=> {a: 1}
collapse objects with boolean values
//=> 'a:false'//=> 'a:true' //=> {a: false}//=> {a: true}
collapse array with boolean values
//=> 'a:1,2,3'//=> 'a.b:1,2,3|c:d' //=> {a: [1, 2, 3]}//=> {a: {b: [1, 2, 3]}, c: 'd'}
collapse nested objects with boolean values
//=> 'a.b:true'//=> 'a.b:true,'//=> 'a.b:true,false'//=> 'a.b:true,false|a.c.d:e' //=> {a: {b: true}}//=> {a: {b: true}}//=> {a: {b: [true]}}//=> {a: {b: [true, false]}}//=> {a: {b: [true, false], c: {d: 'e'}}}
collapse complex objects
//=> 'a.b:c|a.d:e|f:g'//=> 'a:b|c:d|e.f:g|e.h:i|e.j.k.l:m'//=> 'a:b|c:d|e.f:g|e.h:i,j,k'//=> 'a:b|c:d|e.f:g|e.h:i,j,k,one:two' //=> {a: {b: 'c', d: 'e'}, f: 'g'}//=> {a: 'b', c: 'd', e: {f: 'g', h: 'i', j: {k: {l: 'm'}}}}//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k']}}//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k', {one: 'two'}]}}
Related projects
- expand-object: Expand a string into a JavaScript object using a simple notation. Use the CLI or… more
- kind-of: Get the native type of a value.
- regex-flags: Does one simple thing - gets the flags from a regular expression. Useful for cloning… more
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 05, 2015.