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

salyne

v1.13.0

Published

light weight dependency injection library

Downloads

6

Readme

salyne

Join the chat at https://gitter.im/from-nibly/salyne Build Status

Salyne (saline) is a dependency injection library that is largely compatible with electrolyte but is lighter, simpler, and more flexible.

here is a quick example.

// ~/project/index.js  
var Salyne = require('salyne'),
  injector = new Salyne();

injector.load('./lib/foobar.js')

var foobar = injector.create('foobar');

console.log('testing', foobar.foo, foobar.bar);

// ~/project/lib/foobar.js
exports = module.exports = function() {
  this.foo = 5;
  this.bar = 10;
};

This will create a new instance of the foobar dependency. It got its name from the file name. But like I said earlier salyne is flexible. Here are some of the ways you can name your dependencies.

//salyne will grab from the function name if it's available
exports = module.exports = function Foobar() {
  // name will be 'Foobar'
};
// you can also pass a name at load time
injector.load('FooBar', './lib/foobar.js');
// name will be FooBar

I also said that this is a dependency injection library. Here are some ways you can define your dependencies inside a file.

// salyne will take just the argument names just like angular (but they have to be exact)
exports = module.exports = function (foo, bar, bang) {
};
// saylne will also take properties on the function (the params no longer have to be exact or even close)
exports - module.exports = function (foo, bar, bang) {

};
exports.requires = [ 'Foo', 'Baur', 'Zip']
//you can also do the following
exports['@requires'] = [ 'Foo', 'Baur', 'Zip']
exports.require = [ 'Foo', 'Baur', 'Zip']
exports['@require'] = [ 'Foo', 'Baur', 'Zip']

you can also use the define function instead of module.exports. This way you can define multiple dependencies per file

define('Test1', ['Bar', 'Foo'], function(bar, foo) {

});
define(function Test2(Bar, Foo) {

});

You can also create a singleton really easily!

var foo = 0;
exports = module.exports = function() {
  //foo will never change because you will always be given the same instance.
  this.foo = foo++;
};
exports.singleton = true;
//you can also do the following
exports['@singleton'] = true;

You can also bind constructors directly.

injector.bind('bar', function() {
  this.item = 'testing';
});
var bar = injector.create('bar');

These are also flexible.

injector.bind({ singleton : true }, function Bang() {
  this.bang = 'also testing';
});
var bang = injector.create('Bang');

Factories! You can also create factories.

var foo = 3;
injector.bind(function bar() {
  this.foo = foo++;
});
var Bar = injector.factory('bar');
var bar1 = Bar();
var bar2 = Bar();

You can also exclude dependencies for your factory.

injector.bind(function bang() {
  this.bang = 'testing';
});
injector.bind(function bar(bang, foo) {
  this.bang = bang;
  this.foo = foo;
});

var Bar = injector.factory('bar', 'foo');
var bar = Bar(5);
assert(bar.foo, 5);
assert(bar.bang, 'testing');

It will parse the require string and traverse to sub properties

define(['child_process->execSync'], function(exec) {
  exec('ls');
});
//or
define(['config->http', 'expressApp'], function(http, app) {
  app.listen(http.port);
});