
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
collapse-object
Advanced tools
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.
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 with npm
$ npm i collapse-object --save
var collapse = require('collapse-object');
collapse({a: {b: {c: [1, 2, 3]}}})
//=> 'a.b.c:1,2,3'
Re-expand a collapsed string with expand-object:
var expand = require('expand-object');
//=> {a: {b: {c: [1, 2, 3]}}}
collapse({a: 'b'})
//=> 'a:b'
expand('a:b')
//=> {a: 'b'}
collapse({a: 0})
//=> 'a:0'
collapse({a: 1})
//=> 'a:1'
expand('a:0')
//=> {a: 0}
expand('a:1')
//=> {a: 1}
collapse({a: false})
//=> 'a:false'
collapse({a: true})
//=> 'a:true'
expand('a:false')
//=> {a: false}
expand('a:true')
//=> {a: true}
collapse({a: [1, 2, 3]})
//=> 'a:1,2,3'
collapse({a: {b: [1, 2, 3]}, c: 'd'})
//=> 'a.b:1,2,3|c:d'
expand('a:1,2,3')
//=> {a: [1, 2, 3]}
expand('a.b:1,2,3|c:d')
//=> {a: {b: [1, 2, 3]}, c: 'd'}
collapse({a: {b: true}})
//=> 'a.b:true'
collapse({a: {b: [true]}})
//=> 'a.b:true,'
collapse({a: {b: [true, false]}})
//=> 'a.b:true,false'
collapse({a: {b: [true, false], c: {d: 'e'}}})
//=> 'a.b:true,false|a.c.d:e'
expand('a.b:true')
//=> {a: {b: true}}
expand('a.b:true')
//=> {a: {b: true}}
expand('a.b:true,')
//=> {a: {b: [true]}}
expand('a.b:true,false')
//=> {a: {b: [true, false]}}
expand('a.b:true,false|a.c.d:e')
//=> {a: {b: [true, false], c: {d: 'e'}}}
collapse({a: {b: 'c', d: 'e'}, f: 'g'})
//=> 'a.b:c|a.d:e|f:g'
collapse({a: 'b', c: 'd', e: {f: 'g', h: 'i', j: {k: {l: 'm'}}}})
//=> 'a:b|c:d|e.f:g|e.h:i|e.j.k.l:m'
collapse({a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k']}})
//=> 'a:b|c:d|e.f:g|e.h:i,j,k'
collapse({a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k', {one: 'two'}]}})
//=> 'a:b|c:d|e.f:g|e.h:i,j,k,one:two'
expand('a.b:c|a.d:e|f:g')
//=> {a: {b: 'c', d: 'e'}, f: 'g'}
expand('a:b|c:d|e.f:g|e.h:i|e.j.k.l:m')
//=> {a: 'b', c: 'd', e: {f: 'g', h: 'i', j: {k: {l: 'm'}}}}
expand('a:b|c:d|e.f:g|e.h:i,j,k')
//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k']}}
expand('a:b|c:d|e.f:g|e.h:i,j,k,one:two')
//=> {a: 'b', c: 'd', e: {f: 'g', h: ['i', 'j', 'k', {one: 'two'}]}}
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 05, 2015.
FAQs
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.
The npm package collapse-object receives a total of 213 weekly downloads. As such, collapse-object popularity was classified as not popular.
We found that collapse-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.