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

colt

v4.0.1

Published

A sequencing library with a chainable api

Downloads

4,245

Readme

Colt

Greenkeeper badge

A sequencing library with a chainable api

Example usage

colt()
.createUser('marc', {email: '[email protected]', name: 'Marc Bachmann'})
.createDocumentForUser('document', 'marc', {title: 'Foobar'})
.fire(function done (err, resInCallback) {
    // resInCallback equals resAsReturn
    // resAsReturn.user equals {id: 1, name: 'Marc Bachmann', ema...}
})

API

var colt = require('colt')

colt

Is a colt api instance

colt.forge(), colt.create(), colt.new()

Creates a new colt api instance

colt1.mixin(colt2)

Extends colt1 with all the methods from colt2

colt.clone()

Returns a new colt api instance with all the methods from colt

colt.register(yourMethodName, function (content[, callback]))

Is used to register a method, content contains a name and a value object.

colt()

Returns an object which contains all colt methods you registered

colt()[yourMethodName](mapName, value)

yourMethodName is the name of a method you registered using colt.register

colt().end, colt().fire, colt().exec

Are methods which accept a node type callback callback(err, res) res contains all values which get populated during the execution

How to register methods

// Register methods
var colt = require('colt').forge()

colt.register('set', function (content) {
  return content.value
})

colt.register('createUser', function (content, callback) {
  request.post('/users', function (err, user) { callback(err, user) })
})

colt.register({name: 'createDocumentForUser', evaluate: false}, function (content, callback) {
  var data = _.extend(content.args[1], {user_id: this[content.args[0]].id })
  request.post('/documents', data, function (err, document) {
    callback(err, document)
  })
})

More examples

// The main module returns a colt api instance
// If you register methods on this instance, they will be global
// and will be returned if you require colt.
var colt = require('colt')
colt.load('methodName', function (content[, callback]){
    // content = {name: 'valueKey', value: value}
})

// create a new instance
var chain = colt.forge()

// Or clone an instance
chain = colt.clone()

// You can use .mixin to inherit from specific colt instances
chain.mixin(colt)


chain.load('set', function (content) { callback(null, content.value) })

// Execute a registered method
var res = chain().set('user', {id: 1}).exec(callback)
function callback (err) {
    if (err) throw err
    // res.user is the result of the method defined in chain.load('set', ...
}

// exit
chain.exec(callback)
chain.fire(callback)
chain.end(callback)

How we use it (sorry for the coffee-script)

describe 'User api:', ->

  // Colt version
  before (done) ->
    @res = colt()
    .createUser('normalUser')
    .createUser('adminUser', {admin: true})
    .createDocumentForUser('document', 'normalUser', {title: 'Foobar'})
    .end(done)


  // What this would look like with async.js
  // This structures get really complex if you want
  // to create relations and depend on previous results
  before (done) ->
    async.series
      normalUser: (done) =>
        userSupport.createUser (err, user) =>
          @_userId = user.id
          done(err, user)

      document: (done) ->
        userSupport.createDocument({
          title: 'Foobar',
          user_id: @_userId
        }, done)

      adminUser: (done) -> userSupport.createUser({admin: true}, done)
    , (err, res) =>
      @res = res
      done(err)


  it 'requires admin access to access users endpoint', (done) ->
    request.get('/users')
    .withUser(@res.normalUser)
    .expect(401)
    .end(done)

  it 'allows admins to access the page', (done) ->
    request.get('/users')
    .withUser(@res.adminUser)
    .expect(200)
    .end(done)