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

skippy

v4.0.2

Published

Simple and robust dependency container.

Downloads

13

Readme

Skippy

npm Build Status

Skippy is designed to be an easy to use, robust, and well tested dependencies container. No magic inside.

What Skippy do

  • Instantiate service as described in the dependencies configuration.
  • Configure what should be used as service constructor parameters: you can pass another services as reference, parameters, or any values you have configured.
  • Manage singleton instance of service (not defined by design pattern, but by configuration).
  • Call custom method on service instance to finish it configuration.
  • Check the dependencies graph to avoid cyclic dependencies.
  • Allowing injection of service mock (only in test environment: NODE_ENV="test").

What Skippy don't do (and never will)

  • Introspect JSDoc or parameters name to determine witch service should be inject in a constructor function. You have to define service dependencies in a configuration file.
  • Coffee

What Skippy don't do at the moment (maybe one day)

  • Manage service scope (allowing private service, who can only be used to instantiate other service, not exposed to the world)
  • Use factory service to generate another service (delayed, the post service creation hooks do a part of the job for now)
  • Generate a lazy loading proxy function (delayed, until ES6 proxy is well supported)

Installation

npm install --save skippy

Usage

var SkippyFactory = require('skippy').ContainerFactory;

// See configuration section for the configuration details
var services = [/* ... */];
var parameters = {/* ... */}

var container = SkippyFactory.create(services, parameters);

var fooServiceInstance = container.getService('foo');

var barParameterValue = container.getParameter('bar');

container.destroy();

Configuration

Parameters

The parameter configuration format is a simple key/value object:

var foo = "foo value";

module.exports = {
    "parameterName": "parameterValue",
    "foo": foo,
    "bar": 42
}

The parameter name should be a string. The value could be anything.

Services

The services configuration format is an array of individual service configuration:

module.exports = [
    {
        "name": "foo.serviceA",
        "service": require("./ServiceA"),
        "singleton": true
    },
    {
        "name": "foo.serviceB",
        "service": require("./ServiceB"),
        "singleton": false,
        "arguments": [
            "@foo.serviceC"
        ]
    },
    {
        "name": "foo.serviceC",
        "service": require("./ServiceC"),
        "arguments": [
            "%baz%",
            42,
            "@foo.serviceA"
        ]
    },
    {
        "name": "foo.serviceD",
        "service": require("./ServiceD"),
        "arguments": [
            "@foo.serviceA",
            "@foo.serviceB"
        ]
    },
    {
        "name": "foo.serviceD",
        "service": require("./ServiceD"),
        "calls": {
            "setLocale": [
                "@foo.serviceB",
                "%default.locale%"
        ]
    }
];

A service configuration have four possible keys:

  • name (string, mandatory): the service name.
  • service (function, mandatory): the service constructor function reference.
  • singleton (boolean, optional, default true): If true, the service will be a singleton. If false, a new service will be instantiated each time.
  • arguments (array, optional, default empty array): An array of the value to inject in the service constructor (see "Arguments" section for more informations).
  • calls (object, optional, default empty array): A map of the method to call on the service, each method should have it arguments array (see "Arguments" section for more informations).

Arguments

3 types of arguments type:

  • A string like @foo: use another service as argument value (here an instance of the service named foo).
  • A string like %baz%: use the corresponding parameter value as argument (here the baz parameter).
  • Any other value (scalar, object, function...) will be directly used as an argument.