# typescript-singleton

> Class to handler singleton

Latest version **0.1.3** (published 2023-08-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install typescript-singleton
pnpm add typescript-singleton
yarn add typescript-singleton
bun add typescript-singleton
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-08-16 |
| First published | 2023-05-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Renato Miawaki |
| Maintainers | reytuty |
| Keywords | ts-singleton, singleton, class, typescript, singleeton |

## Links

- npm: https://www.npmjs.com/package/typescript-singleton
- Repository: https://github.com/reytuty/typescript-singleton
- Homepage: https://github.com/reytuty/typescript-singleton#readme
- Issues: https://github.com/reytuty/typescript-singleton/issues
- npm.io page: https://npm.io/package/typescript-singleton

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^5.0.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2023-08-16
- 0.1.2 — 2023-05-23
- 0.1.1 — 2023-05-16
- 0.1.0 — 2023-05-16

## README

# typescript-singleton

Lib to simple handler singleton classes em typescript

## Install

```
npm i typescript-singleton
```

## Usage

```
import { Singleton } from "typescript-singleton";

Singleton.getInstance<MyClassThatIWannaToBeUnique>(
'here-my-unique-key',
MyClassThatIWannaToBeUnique,
//put your parameters here if you want
);

```

```

import { Singleton } from "typescript-singleton";

class MyClassThatIWannaToBeUnique {
public name: string;
public total: number;
constructor(name: string, total: number) {
this.name = name;
this.total = total;
}
}

//If your class use json to config or other parameters, stringfy all of them and use as a key, like this example

const myClassConfig: any = {
user:"root",
pass:"abc",
port: 11027
}

//in this case if some other equal config was used to instance the same class, that will be the same instance class

const privateKey: string = JSON.stringfy(myClassConfig);
const total = 10;
const myClassInstance1: MyClassThatIWannaToBeUnique =
Singleton.getInstance<MyClassThatIWannaToBeUnique>(
privateKey,
MyClassThatIWannaToBeUnique,
"test",
total
);
const myClassInstance2: MyClassThatIWannaToBeUnique =
Singleton.getInstance<MyClassThatIWannaToBeUnique>(
privateKey,
MyClassThatIWannaToBeUnique,
"test",
total
);
//to prove that be the same instance, I will change a name of instance 1
myClassInstance1.name = "There is no test anymore";
console.log(myClassInstance1.name === myClassInstance2.name, "same name and same memory location");

```

```

```

---
_Source: https://npm.io/package/typescript-singleton · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
