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

morphine

v1.0.5

Published

almost DI, for situations where DI is too much, and you want to avoid the hard stuff

Downloads

13

Readme

morphine

living high on simple DI

Heavily inspired by Angular ui.router $resolve. I wrote this after a stressful day of Shepherd.js and other DI libs making me feel stupid. I am making some micro-services and didn't want to deal with proper DI, I just wanted something like a recursive Promise.all()

Ripped some regex magic out of Angular's $inject code, combined with a rewrite of ui.router's $resolve, and you get some sexy Promise dependency injection thing that looks like it was made with sweet.js.

Example:


var resolve = require("morphine");

resolve({
  now: function(path){
    return path;
  },
  future: function(path, now){
    return path + now;
  }
},{path: "something"})
.then(console.log);

output

{ path: 'something',
  now: 'something',
  future: 'somethingsomething' }

API

resolve(invokables, [knowns]) -> promise

invokeables:

An invokeable is a name (key) and a function with zero or more arguments that map to some or all of the keys in the invokeables object (resursive), or the knowns object. The return values for the invokeables functions can be promises. internally they get converted to promises anyway.

knowns:

an object of primative values (strings, ints).

resolve():

The return value (promise) that resolve gives is an object with the keys from both the invokeables and knowns list, and the resolved values from all of the invokeables (primatives).


More Examples:

resolve({
  now: function(path){
    return "something";
  }
})
.then(console.log);

output

{ path: 'something'}

var fs = require("q-io/fs");
resolve({
  config: function(configPath){
    return fs.read(configPath).then(JSON.parse);
  }
},{configPath: "config.json"})
.then(console.log);

output

{ configPath: 'config.json',
  config: { obj: { field: [Object] }, server: { port: 1111 } } }

what happens when you you make typos

resolve({
  path: function(){
    return "something";
  },
  fail: function(noResolution, path){
    return noResolution + path;
  }
})
.then(null, _.partial(console.log, "failure case"));

output

failure case [Error: can not resolve all dependencies: noResolution]