{"_id":"collapse-object","_rev":"45993","name":"collapse-object","description":"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.","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"time":{"modified":"2021-06-03T10:14:09.000Z","created":"2015-08-05T23:27:20.491Z","0.1.0":"2015-08-05T23:27:20.491Z"},"users":{},"author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/jonschlinkert/collapse-object.git"},"versions":{"0.1.0":{"name":"collapse-object","description":"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.","version":"0.1.0","homepage":"https://github.com/jonschlinkert/collapse-object","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/jonschlinkert/collapse-object.git"},"bugs":{"url":"https://github.com/jonschlinkert/collapse-object/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"dependencies":{"expand-object":"^0.3.6","kind-of":"^2.0.0","regex-flags":"^0.1.0"},"devDependencies":{"mocha":"*","should":"*"},"keywords":["data","fixtures","get","has","hasown","key","keys","nested","notation","object","prop","properties","property","props","set","value","values"],"gitHead":"cd5346ffac9725e53969ea33d284f7367e7adb39","_id":"collapse-object@0.1.0","_shasum":"5c53f7da34e464e697011ce6f4aee73b88882c15","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"dist":{"shasum":"5c53f7da34e464e697011ce6f4aee73b88882c15","size":2944,"noattachment":false,"key":"/collapse-object/-/collapse-object-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/collapse-object/download/collapse-object-0.1.0.tgz"},"directories":{},"publish_time":1438817240491,"_cnpm_publish_time":1438817240491,"_hasShrinkwrap":false}},"readme":"# collapse-object [![NPM version](https://badge.fury.io/js/collapse-object.svg)](http://badge.fury.io/js/collapse-object)\n\n> 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.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/)\n\n```sh\n$ npm i collapse-object --save\n```\n\n## Usage\n\n```js\nvar collapse = require('collapse-object');\n\ncollapse({a: {b: {c: [1, 2, 3]}}})\n//=> 'a.b.c:1,2,3'\n```\n\nRe-expand a collapsed string with [expand-object](https://github.com/jonschlinkert/expand-object):\n\n```js\nvar expand = require('expand-object');\n//=> {a: {b: {c: [1, 2, 3]}}}\n```\n\n### collapse an object\n\n```js\ncollapse({a: 'b'})\n//=> 'a:b'\n\nexpand('a:b')\n//=> {a: 'b'}\n```\n\n### collapse objects with number values\n\n```js\ncollapse({a: 0})\n//=> 'a:0'\ncollapse({a: 1})\n//=> 'a:1'\n\nexpand('a:0')\n//=> {a: 0}\nexpand('a:1')\n//=> {a: 1}\n```\n\n### collapse objects with boolean values\n\n```js\ncollapse({a: false})\n//=> 'a:false'\ncollapse({a: true})\n//=> 'a:true'\n\nexpand('a:false')\n//=> {a: false}\nexpand('a:true')\n//=> {a: true}\n```\n\n### collapse array with boolean values\n\n```js\ncollapse({a: [1, 2, 3]})\n//=> 'a:1,2,3'\ncollapse({a: {b: [1, 2, 3]}, c: 'd'})\n//=> 'a.b:1,2,3|c:d'\n\nexpand('a:1,2,3')\n//=> {a: [1, 2, 3]}\nexpand('a.b:1,2,3|c:d')\n//=> {a: {b: [1, 2, 3]}, c: 'd'}\n```\n\n### collapse nested objects with boolean values\n\n```js\ncollapse({a: {b: true}})\n//=> 'a.b:true'\ncollapse({a: {b: [true]}})\n//=> 'a.b:true,'\ncollapse({a: {b: [true, false]}})\n//=> 'a.b:true,false'\ncollapse({a: {b: [true, false], c: {d: 'e'}}})\n//=> 'a.b:true,false|a.c.d:e'\n\nexpand('a.b:true')\n//=> {a: {b: true}}\nexpand('a.b:true')\n//=> {a: {b: true}}\nexpand('a.b:true,')\n//=> {a: {b: [true]}}\nexpand('a.b:true,false')\n//=> {a: {b: [true, false]}}\nexpand('a.b:true,false|a.c.d:e')\n//=> {a: {b: [true, false], c: {d: 'e'}}}\n```\n\n### collapse complex objects\n\n```js\ncollapse({a: {b: 'c', d: 'e'}, f: 'g'})\n//=> 'a.b:c|a.d:e|f:g'\ncollapse({a: 'b', c: 'd', e: {f: 'g', h: 'i', j: {k: {l: 'm'}}}})\n//=> 'a:b|c:d|e.f:g|e.h:i|e.j.k.l:m'\ncollapse({a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k']}})\n//=> 'a:b|c:d|e.f:g|e.h:i,j,k'\ncollapse({a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k', {one: 'two'}]}})\n//=> 'a:b|c:d|e.f:g|e.h:i,j,k,one:two'\n\nexpand('a.b:c|a.d:e|f:g')\n//=> {a: {b: 'c', d: 'e'}, f: 'g'}\nexpand('a:b|c:d|e.f:g|e.h:i|e.j.k.l:m')\n//=> {a: 'b', c: 'd', e: {f: 'g', h: 'i', j: {k: {l: 'm'}}}}\nexpand('a:b|c:d|e.f:g|e.h:i,j,k')\n//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k']}}\nexpand('a:b|c:d|e.f:g|e.h:i,j,k,one:two')\n//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k', {one: 'two'}]}}\n```\n\n## Related projects\n\n* [expand-object](https://github.com/jonschlinkert/expand-object): Expand a string into a JavaScript object using a simple notation. Use the CLI or… [more](https://github.com/jonschlinkert/expand-object)\n* [kind-of](https://github.com/jonschlinkert/kind-of): Get the native type of a value.\n* [regex-flags](https://github.com/jonschlinkert/regex-flags): Does one simple thing - gets the flags from a regular expression. Useful for cloning… [more](https://github.com/jonschlinkert/regex-flags)\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm i -d && npm test\n```\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/collapse-object/issues/new)\n\n## Author\n\n**Jon Schlinkert**\n\n+ [github/jonschlinkert](https://github.com/jonschlinkert)\n+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n## License\n\nCopyright © 2015 Jon Schlinkert\nReleased under the MIT license.\n\n***\n\n_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 05, 2015._","_attachments":{},"homepage":"https://github.com/jonschlinkert/collapse-object","bugs":{"url":"https://github.com/jonschlinkert/collapse-object/issues"},"license":"MIT"}