Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc