https://github.com/tada5hi/singa
A tiny library to create and manage singleton instances.
https://github.com/tada5hi/singa
instance singleton singleton-design-pattern
Last synced: 2 days ago
JSON representation
A tiny library to create and manage singleton instances.
- Host: GitHub
- URL: https://github.com/tada5hi/singa
- Owner: tada5hi
- License: mit
- Created: 2024-02-03T10:52:16.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-10-13T19:30:54.000Z (4 months ago)
- Last Synced: 2025-10-15T04:48:30.039Z (4 months ago)
- Topics: instance, singleton, singleton-design-pattern
- Language: TypeScript
- Homepage:
- Size: 445 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# singa 🏛️
[![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]
This is a tiny library to create and manage singleton instances.
**Table of Contents**
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
## Installation
```bash
npm install singa --save
```
## Usage
The **singa** function returns an object of type [Singa](#singa),
with all input parameters, including name and factory, being entirely optional.
**Sync**
```typescript
import { singa } from 'singa';
class Foo {
}
const singleton = singa({
name: 'singleton',
factory() {
return new Foo();
},
});
const instance = singleton.use();
```
**Async**
```typescript
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](./CONTRIBUTING.md) and the [code of conduct](./CODE_OF_CONDUCT.md).
These guidelines will help to ensure that contributions are made effectively and are accepted.
## License
Made with 💚
Published under [MIT License](./LICENSE).
[npm-version-src]: https://badge.fury.io/js/singa.svg
[npm-version-href]: https://npmjs.com/package/singa
[codecov-src]: https://codecov.io/gh/Tada5hi/singa/branch/master/graph/badge.svg?token=4KNSG8L13V
[codecov-href]: https://codecov.io/gh/Tada5hi/singa
[workflow-src]: https://github.com/Tada5hi/singa/workflows/CI/badge.svg
[workflow-href]: https://github.com/Tada5hi/singa
[snyk-src]: https://snyk.io/test/github/Tada5hi/singa/badge.svg?targetFile=package.json
[snyk-href]: https://snyk.io/test/github/Tada5hi/singa?targetFile=package.json
[conventional-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white
[conventional-href]: https://conventionalcommits.org