1.1.3 • Published 3 years ago

basic-injector v1.1.3

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

BasicInjector

BasicInjector is a javascript module that allows you to call your functions without sending them their arguments. The Injector class allows you to set a parameter dictionary, so that when you call your function using inject, the appropriate parameter wiil be passed according to the parameter names in the function signature.

Basic Usage

Use injector to inject parameters to function

$ npm install basic-injector
const Injector = require('basic-injector');

var injector = new Injector({
  config: require('./config'),
  env: 'production',
  utils: require('./utils')
});

injector.inject((utils, config, env) => {
  console.log(env) // production
});

Adding parameters

Add more parameters to inject

injector.set("port", 8080);

Removing parameters

Remove parameters to inject

injector.remove("port");

Set thisArg

Set the fucntions this

var obj = {};

injector.inject(function(port){
  this.port = port;
}, obj);

console.log(obj) // { port: 8080 }

Use function as constructor

Run the function with the new keyword to create an instance of it

var Example = function(port){
  this.port = port;
}

var example = injector.construct(Example);

console.log(example) // Example { port: 8080 }
1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago