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

@armscye/container

v0.5.0

Published

A collection of shared standard TypeScript definitions (@container)

Downloads

175

Readme

@armscye/container

A collection of shared standard TypeScript definitions (@container).

Installation

Using npm:

npm install --save-dev @armscye/container

or using yarn:

yarn add @armscye/container --dev

Reference

ClassProvider Interface

Configures the Container to return an instance of useClass for a token.

interface ClassProvider {
  provide: ProviderToken;

  useClass: NoArgument<any>;

  shared?: boolean;
}

Properties

| Property | Description | | --------------------------- | ------------------------------------------ | | provide: ProviderToken | A provider token. | | useClass: NoArgument<any> | A class to instantiate for the token. | | shared?: boolean | When true, the created instance is cached. |

Container Interface

Describes the interface of a container that exposes methods to read its entries.

interface Container {
  get<T>(token: ProviderToken): T;

  has(token: ProviderToken): boolean;
}

Methods

get<T>(token: ProviderToken): T

Retrieves an entry from the container based on its provider token.

Parameters

  • token: The unique identifier of the entry to retrieve.

Returns

The entry associated with the provided token, if found.

Throws

Error if the entry doesn't exist or an error occurs during retrieval.

has(token: ProviderToken): boolean

Checks whether an entry for a specific provider token exists in the container.

Parameters

  • token: The unique identifier of the entry to check for.

Returns

true if an entry for the provided token exists, false otherwise.

ExistingProvider Interface

Configures the Container to return a value of another useExisting token.

interface ExistingProvider {
  provide: ProviderToken;

  useExisting: ProviderToken;

  shared?: boolean;
}

Properties

| Property | Description | | ---------------------------- | ------------------------------------------ | | provide: ProviderToken | A provider token. | | useExisting: ProviderToken | Existing token to return. | | shared?: boolean | When true, the created instance is cached. |

FactoryProvider Interface

Configures the Container to return a value by invoking a useFactory function.

interface FactoryProvider {
  provide: ProviderToken;

  useFactory: Factory<any>;

  shared?: boolean;
}

Properties

| Property | Description | | -------------------------- | ----------------------------------------------------------------- | | provide: ProviderToken | A provider token. | | useFactory: Factory<any> | A factory function to invoke to create an object for the token. | | shared?: boolean | When true, the created instance is cached. |

Factory Type

A function to invoke to create an object. The function is invoked with an instance of the container in order to access required dependencies.

type Factory<T = any> = (container: Container) => T;

ProviderToken Type

Token that can be used to retrieve an instance from a container.

type ProviderToken = string | symbol;

Provider Type

Describes how the Container should be configured.

type Provider =
  | ValueProvider
  | ClassProvider
  | FactoryProvider
  | ExistingProvider;

ValueProvider Interface

Configures the Container to return a value for a token.

interface ValueProvider {
  provide: ProviderToken;

  useValue: any;
}

Properties

| Property | Description | | ------------------------ | ----------------------------------------------------------- | | provide: ProviderToken | A provider token. | | useValue: any | The actual value that will be provided for the given token. |

License

This project is licensed under the MIT license.

See LICENSE for more information.