npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

collapse-object

v0.1.0

Published

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.

Downloads

1,128

Readme

collapse-object NPM version

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 = 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 an object

collapse({a: 'b'})
//=> 'a:b'

expand('a:b')
//=> {a: 'b'}

collapse objects with number values

collapse({a: 0})
//=> 'a:0'
collapse({a: 1})
//=> 'a:1'

expand('a:0')
//=> {a: 0}
expand('a:1')
//=> {a: 1}

collapse objects with boolean values

collapse({a: false})
//=> 'a:false'
collapse({a: true})
//=> 'a:true'

expand('a:false')
//=> {a: false}
expand('a:true')
//=> {a: true}

collapse array with boolean values

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 nested objects with boolean values

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 complex objects

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'}]}}

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.