🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

containerr.js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

containerr.js

A simple container for manage dependency injection.

0.2.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

containerr.js

This library include a simple container for manage dependency injection

  • Container accept functions as dependencies
  • Function dependencies are singleton and are instantiated only when get it

Methods

/**
* Check if the dependence is in the container
*
* @param key
* @returns {boolean}
* @throws Error: The key must be a string
*/
has(key);
/**
* Get dependence
*
* @param key
* @returns {boolean}
* @throws Error: The key must be a string
* @throws Error: $key is not in the container
*/
get(key);
/**
* Load dependence
*
* @param key
* @param object
* @returns {boolean}
* @throws Error: The key must be a string
* @throws Error: $key is already in the container
*/
share(key, object);

Example

const { Containerr } = require('./containerr');

let container = new Containerr();
let dependence = {
    name: 'dependence1'
};
let key = 'dependence1';
let key2 = 'dependence2';
let key3 = 'dependence2';

container.has(key); //false
container.share(key, dependence); //true
container.share(key2, () => {
    return { obj: 'obj' };
}); //true
container.has(key); //true
container.get(key); //return dependence variable
container.get(key2); //return dependence variable
container.share(key, dependence); //Exception = Error: key is already in the container
container.get(key3); //Exception = Error: key is not in the container

Keywords

container

FAQs

Package last updated on 09 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts