New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lazybox

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazybox

Service container based on Map()

latest
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

Lazybox

Dependency injection container based on Map()

Usage


var Lazybox = require('lazybox');

var c = new Lazybox();

// Set parameter
c.set('foo.bar', 'baz');

// Define a service
c.define('foo', () => {
	return new Service();
});

// Define a service with dependencies
c.define('answer', ['answer.value', (value) => {
	console.log('Lazily initialized');
	return {
		life: () => value,
		universe: () => value,
		everything: () => value
	};
}]);
c.set('answer.value', 42);

c.get('answer').life(); // Logs 'Lazily initialized'

// Define a generator service

c.define('nextid', function *nextId() {
	const id = 0;
	while (true) {
		yield id++;
	}
});
let id = c.get('nextid')
id(); // 0
id(); // 1
id(); // 2 ...


Dependency Injection

Providers

// Register a provider function
c.register((c) => {
	c.set('foo', 'bar');
});

// Register a provider object
c.register({
	register: (c) => {
		c.set('foo', 'bar');
	}
});

API

container.match(pattern, callback)

Use path-to-regexp to match keys.

This does not initialize any service by calling get()

Arguments

  • pattern: A key pattern
  • callback: A function (key, params, container) to call for each result.
cnt.matchKeys('foo.:bar.:baz?', (key, params, container) => { ... });

container.setdefault(key, value)

Similar to Python's dict.setdefault(key, value) method. It gets the value of a key or sets it to value if not defined.

Keywords

container

FAQs

Package last updated on 28 May 2016

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