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

deepen

v1.0.0

Published

DeePen is a light weight dependency injection

Downloads

4

Readme

Deepen

Another dependency injection module? why not

Example:

const lodash = require('lodash'),
      bluebird = require('bluebird'),
      dp = require('deepen')();

let barModel = {
  text: 'hello world!'
};
barModel.$name = 'BarModel';
barModel.$single = true;
barModel.$deps = ['_'];
barModel.$register = (dp) => {
  let _ = dp.resolver('_');
  barModel.text = _.startCase(barModel.text);
};
barModel.$after = (_) => {
  console.log('before: ' + barModel.text + ' after: ' + _.camelCase(barModel.text));
};

let fooModule = function Foo (promise) {
  this.bar = (text) => {
      return promise.resolve(text.toUpperCase());
  };
};
fooModule.$name = 'Foo';
fooModule.$deps = ['Promise'];
fooModule.$exports = [barModel];


dp.add(bluebird, { $name: 'Promise', $deps: [], $single: true});
dp.add(lodash, { $name: '_', $deps: [], $single: true});
dp.add(fooModule);

dp.finish();

let foo = dp.resolver('Foo');
foo.bar('hi')
  .then((text) => {
      console.log(text);
  });

Outputs:

before: Hello World after: helloWorld
HI

Documentation (Look in code or I can copy pasta below)

/**
 * DependencyExportRequest - Object containing dependency / options
 * @typedef {Object} DependencyExportRequest
 * @property {Dependency} $dependency - Dependency
 * @property {DependencyOptions} [$options] - Dependency Options
 */

/**
 * DependencyOptions - Options for a dependency if not provided the required options
 * must be properties on the dependency itself.
 * @typedef {Object} DependencyOptions
 * @property {string} $name - Name / Unique Key
 * @property {Array<string>} [$deps] - Array of dependencies required using their name
 * @property {boolean} [$single] - If the dependency is a singleton defaults to false
 * @property {Array<Dependency|DependencyExportRequest>} [$exports] - Defines other dependencies that this dependency wants to register with the DependencyResolver
 * @property {function} [$register] - Function called when added to the DependencyResolver but after all exports are added.  The dependency resolver is passed in as the only argument
 * @property {function} [$after] - Function called after DependencyResolver.finish() is called
 */

/**
 * Dependency - Singleton Object or Function that should extend DependencyOptions
 * if none will be passed to DependencyResolver.add()
 * - If no options are provided to the add function, they must be set as properties on this object
 * - Unless single is set to true, Function will be called with New operator
 * @typedef {Object|Function} Dependency
 * @see {DependencyOptions}
 */

/**
 * DependencyResolver - Stores / Resolves Dependencies
 * @method add - Adds dependencies to the container
 * @method resolver - Resolves a dependency by name
 * @method finish - Calls after on all dependencies that have an after
 * @return {DependencyResolver}  DependencyResolver
 */

     /**
      * add - Adds dependencies to the container
      *
      * @param  {Dependency} dep     Object or Constructor
      * @param  {DependencyOptions} [options] Options for dependency if not attached to Constructor
      */

      /**
       * resolver - Resolves a dependency from the container by the dependency name
       *
       * @param {string} key - the name of the dependency to resolve
       * @throws If key is not found
       * @return {Object|Instance<T>|Function} - Can return an object/function if $single = true
       * otherwise it creates a new Instance of the found dependency
       */

       /**
        * finish - Should be called after your code has added all of the required dependencies
        * - It will call the after function with the dependencies that were defined in $deps
        * - It will overwrite the $after method to an empty function after completion to ensure it never runs again
        */