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

rn-stash

v1.0.2

Published

Dependency injection for your JavaScript applications

Downloads

5

Readme

stash

stash is an angularjs-style dependency injection framework for JavaScript that makes it easy to define modules, singletons and constants. All dependencies are resolved on demand, freeing you from loading your code in any particular order.

This project was ported from "lukevenediger/dingu" to TypeScript as one of my side projects while learning TypeScript. It is a great framework!

Features

  • Bring in dependencies simply by naming them as a function parameter
  • Load your javascript files in any arbitrary order
  • Store singleton instances
  • Store constant values like settings and magic numbers
  • Protects against circular dependencies
  • Can be locked to prevent further changes at runtime.

How It Works

Example 1: ModuleA depends on ModuleB

rnStash.module('ModuleA', function(ModuleB) {
  return {
    doSomething: function() {
      return 'Hi from ModuleA (' + ModuleB.doSomething() + ')';
    }
  };
});

rnStash.module('ModuleB', function() {
  return {
    doSomething: function() {
      return 'Hi from ModuleB';
    }
  };
});

Next we'll ask stash for an instance of ModuleA and call the doSomething method.

var a = rnStash.get('ModuleA');
console.log(a.doSomething());

Example 2: Using Singletons

stash lets you define a module that will only initialise once, and always return the same instance back. Any dependencies it needs will be resolved and injected the first time it's created.

rnStash.singleton('OneOnly', function() {
  var counter = 0;
  return {
    nextID: function() {
      counter += 1;
      return counter;
    }
  }
});

console.log(rnStash.get('OneOnly').nextID() === 1); // true
console.log(rnStash.get('OneOnly').nextID() === 2); // true

Example 3: Storing Constant Values

Use stash to store settings, magic numbers and other common values and include them in your modules by name.

// Store a string
rnStash.value('apiUrl', 'http://foo.com/api');

// or an object - stash isn't fussy
rnStash.value('systemInfo', {
  apiVersion: '1.2',
  token: 'aab23510' 
});

// And then have them ready in your module
rnStash.module('apiClient', function(apiUrl, systemInfo) {
  // profit!
});

Download and Install

There are many ways to get stash:

  • Download stash.js
  • Install it via npm - npm install rn-stash

Project Information

Maintainers:

Original Code / Developer:

License:

  • MIT