singa
v1.0.0
Published
[![npm version][npm-version-src]][npm-version-href] [![npm version][codecov-src]][codecov-href] [![Master Workflow][workflow-src]][workflow-href] [![Known Vulnerabilities][snyk-src]][snyk-href] [![Conventional Commits][conventional-src]][conventional-href
Downloads
1,172
Readme
singa 🏛️
This is a tiny library to create and manage singleton instances.
Table of Contents
Installation
npm install singa --save
Usage
The singa function returns an object of type Singa, with all input parameters, including name and factory, being entirely optional.
import { singa } from 'singa';
class Foo {
}
const singleton = singa({
name: 'singleton',
factory() {
return new Foo();
},
});
const instance = singleton.use();
Types
Singa
declare type Singa<T> = {
/**
* Create or us existing singleton instance.
*/
use: () => T,
/**
* Set the singleton instance.
*
* @param instance
*/
set: (instance: T) => void,
/**
* Set factory fn for instance creation.
*
* @param factory
*/
setFactory: (factory: Factory<T>) => void,
/**
* Reset the singleton instance.
*/
reset: () => void,
/**
* Check if the singleton instance is set.
*/
has: () => boolean,
/**
* Check if a factory fn is set.
*/
hasFactory: () => boolean
};
Contributing
Before starting to work on a pull request, it is important to review the guidelines for contributing and the code of conduct. These guidelines will help to ensure that contributions are made effectively and are accepted.
License
Made with 💚
Published under MIT License.