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

flattener

v0.4.0

Published

[![Build Status](https://secure.travis-ci.org/goliatone/flattener.png)](http://travis-ci.org/goliatone/flattener)

Downloads

10

Readme

Flattener

Build Status

Object flattener helper library. Convert (nested) objects to and from flat objects of keypath values.

Documentation

flatten

flatten(source,[delimeter='.'])

Transform any deep nested object in a flat object of keypath values. You can specify a custom path delimiter (defaults to .)

Flattener.flatten({user: { name: 'peperone' }});
{'user.name': 'peperone'}

Custom delimiter:

Flattener.flatten({user: { name: 'peperone' }}, '/');
{'user/name': 'peperone'}

unflatten

unflatten(flatObject,[delimeter='.'])

Transform a flattened object into a regular object.

Flattener.flatten({'user.name': 'peperone'});
{user: { name: 'peperone' }}

Custom delimiter:

Flattener.flatten({'user/name': 'peperone'}, '/');
{user: { name: 'peperone' }}

glob

glob(flatObject,regexp)

Iterate over all keys and return the ones matching a given regexp.

Examples

The following is an example of flattening a user object:

let user = {
  name: { title: 'mr', first: 'brad', last: 'gibson' },
  location: {
    street: '9278 new road',
    city: 'kilcoole',
    state: 'waterford',
    postcode: '93027',
    coordinates: { latitude: '20.9267', longitude: '-7.9310' },
    timezone: { offset: '-3:30', description: 'Newfoundland' }
  },
  email: '[email protected]',
  handles: [
    { site: 'twitter', handle: 'mr.brad' },
    { site: 'github', handle: 'bradC0d3z' }
  ]
};

let flatUser = Flattener.flatten(user);
console.log(flatUser);

The output in the console would show something similar to the following:

{
  'name.title': 'mr',
  'name.first': 'brad',
  'name.last': 'gibson',
  'location.street': '9278 new road',
  'location.city': 'kilcoole',
  'location.state': 'waterford',
  'location.postcode': '93027',
  'location.coordinates.latitude': '20.9267',
  'location.coordinates.longitude': '-7.9310',
  'location.timezone.offset': '-3:30',
  'location.timezone.description': 'Newfoundland',
  email: '[email protected]',
  'handles.0.site': 'twitter',
  'handles.0.handle': 'mr.brad',
  'handles.1.site': 'github',
  'handles.1.handle': 'bradC0d3z'
}

You can go back to a regular object:

let obj = Flattener.unflatten(flatUser);

Getting Started

Download the production version or the development version.

Development

npm install && bower install

If you need to sudo the npm command, you can try to:

sudo chown $(whoami) ~/.npm
sudo chown $(whoami) /usr/local/share/npm/bin
sudo chown -R $(whoami) /usr/local/lib/node_modules

If you bump versions, remember to update:

  • package.json
  • bower.json
  • component.json
  • etc.

Bower

Bower is a package manager for the web. It offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. There are no system wide dependencies, no dependencies are shared between different apps, and the dependency tree is flat.

To register flattener in the bower registry: bower register flattener git://github.com/goliatone/gflattener.git

Then, make sure to tag your module:

git tag -a v0.1.0 -m "Initial release."

And push it:

git push --tags

Travis

In order to enable Travis for this specific project, you need to do so on your Travi's profile. Look for the entry goliatone/flattener, activate, and sync.

Release History

(Nothing yet)