ts-singleton-decorator
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Typescript Singleton Decorator (ts-singleton-dactorator)

This decorator help to turn any of you typescript class into singleton class.

How To Install

npm i --save ts-singleton-dactorator

and then you need to enable experimentalDecorators in your tsconfig.json file

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

Usage

@SingletonClass()
class SingletonTester {
    public date: Date;
    constructor() {
        this.date = Date.now();
    }
}

const obj = new SingletonTester();
const obj2 = new SingletonTester();

console.log(obj.date === obj2.date)
// -> true

/ts-singleton-decorator/

    Package Sidebar

    Install

    npm i ts-singleton-decorator

    Weekly Downloads

    8

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    34.4 kB

    Total Files

    22

    Last publish

    Collaborators

    • malis90