1.0.0 • Published 4 months ago

singa v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

singa 🏛️

npm version npm version Master Workflow Known Vulnerabilities Conventional Commits

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.

1.0.0

4 months ago