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

dolce

v0.0.14

Published

Collections with syntactic sugar

Downloads

555

Readme

Dolce is a collection library used primarily for routing. Build Status

Use Cases:

Basic Example:

var dolce = require('dolce'),
col1 = dolce.collection(),
col2 = dolce.collection(),
col3 = dolce.collection(),
col4 = dolce.collection(),
col5 = dolce.collection();

//explicit chain
col1.add('hello', 'HELLO');
col1.add('hello -> world', 'WORLD');

console.log(col1.get('world')); //[{ value: 'HELLO' }, { value: 'WORLD' }]

//parameters
col5.add('validate/:name');
col5.add('validate/:firstName -> add/user/:firstName/:lastName');
console.log(col5.get('add/user/craig/condon')); //[{ value: 'HELLO' }, { value: 'WORLD' }]

//implicit chain
col2.add('hello/*', 'HELLO')
col2.add('hello', 'WORLD');

console.log(col2.get('hello')); //[{ value: 'HELLO' }, { value: 'WORLD' } ]

//greedy chain
col3.add('hello/**', 'HELLO')
col3.add('hello/awesome/**', 'AWESOME');
col3.add('hello/awesome/world', 'WORLD');

console.log(col3.get('hello/awesome/world')); //[{ value: 'HELLO' }, { value: 'AWESOME' }, { value: 'WORLD' } ]

//filtering chains
col4.add('-method=UPDATE users/:userid','update user');
col4.add('-method=DELETE users/:userid', 'delete user');
col4.add('-method=GET users/:userid', 'get user');

console.log(col4.get('users/14732843', { tags: { method: 'GET' } })); //[{ tags: { method: 'GET' }, value: 'get user' }];

API

.add(type, value);

Adds data to the collection

.addObject(value);

Adds an object to the collection


collection.addObject({
	'key': 1,
	'key2': 2
})

.get(channel[, ops])

Returns a collection based on the params given

  • channel - the path to the value, e.g., 'add/user', 'validate/some/stuff'
  • ops - the options for fetching data
    • tags - the tags to filter against

A returned value may look something like this:


{
  "paths": [
    {
      "value": "users",
      "param": false
    },
    {
      "value": "14732843",
      "param": false
    }
  ],
  "tags": {
    "method": "GET"
  },
  "chains": [
    [
      {
        "paths": [
          {
            "value": "users",
            "param": false
          },
          {
            "value": "userid",
            "param": true
          }
        ],
        "params": {
          "userid": "14732843"
        },
        "tags": {
          "method": "GET"
        },
        "value": "get user"
      }
    ]
  ]
}

.contains(channel[, ops])

TRUE if the given channel exists in the collection. API is the same as .get

Caveats


collection.add('-anotherTag validate/**');
collection.add('-method=POST validate/**');
collection.get('-method=POST validate/login');

//goes through -method=POST validate/** before getting to login, NOT -anotherTag validate/** 
collection.get('validate/login'); 


collection.add('-method=POST validate/**');
collection.get('-method validate/login');

//does NOT go through validate/** because the method is not POST
collection.get('validate/login'); 



//this doesn't work
collection.add(':param/*');

//with this.
collection.add('path');

//but with this this:
collection.add('someParam');