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

@sadbox/service-locator

v1.0.2

Published

An implementation of Service Locator pattern

Downloads

2

Readme

Version License Dependencies

Service Locator

An implementation of Service Locator pattern.

Install

yarn add @sadbox/service-locator

or

npm install -S @sadbox/service-locator

Usage

import ServiceLocator from '@sadbox/service-locator';
import Service1 from './Service1';
import Service2 from './Service2';

const services = new ServiceLocator();

services.register({
  name: 'Service1',
  constructor: Service1,
  args: ['option'],
});

services.register({
  name: 'Service2',
  constructor: Service2,
  deps: ['Service1'],
  singleton: false,
});

const {
  Service1: service1, // instance of Service1
  Service2: service2, // instance of Service2
} = services;

API

ServiceLocator.register({
  name,
  constructor,
  instance,
  args,
  deps,
  singleton,
});

Registers service and allow to take it instance later.

name (string) - Unique name of the service.

constructor ({ new (): any }) - The service "newable" class.

instance (any) - Instance of the service. Whenever you will ask to instance, it will be returned.

args (Array<any>) - Arguments to pass to the constructor when creating an instance.

deps (Array<string>) - List of service names to resolve and pass to the constructor when creating an instance.

singleton (boolean) - If true, only first resolve will create instanse of the service. Subsequent resolves will return the same instance. If false new instanse will be created on each resolve. Default is false.


ServiceLocator.resolve(name);

or

ServiceLocator[name];

Returns an instance of the service.

name (string) - Name of the service.


ServiceLocator.evict(name: string)

Removes the instance of the service and all instances of the services that depends on it.

name (string) - Name of the service.