Skip to content

tada5hi/singa

Repository files navigation

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.

Sync

import { singa } from 'singa';

class Foo {

}

const singleton = singa({
    name: 'singleton',
    factory() {
        return new Foo();
    },
});

const instance = singleton.use();

Async

import { singaAsync } from 'singa';

class Foo {

}

const singleton = singaAsync({
    name: 'singleton',
    async factory() {
        await Promise.resolve();
        return new Foo();
    },
});

const instance = await singleton.use();

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.

About

A tiny library to create and manage singleton instances.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •