singa
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i singa

Weekly Downloads

132

Version

1.0.0

License

MIT

Unpacked Size

12.6 kB

Total Files

10

Last publish

Collaborators

  • tada5hi