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

1.0.2 • Public • Published

ts-singleton Decorator

This decorator let's you turn any class into a singleton.

To install:

npm i ts-singleton

Then enable decorators in your tsconfig.json:

{
    "compilerOptions": {
        "target": "ES5", 
        "experimentalDecorators": true   
    }
}

Usage

@singleton
class Dummy{
    date
    constructor(){
        this.date = Date.now()
    }
}
const dummy = new Dummy()
const dummy2 = new Dummy()
console.log(dummy.date === dummy2.date)
// -> true

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i ts-singleton

    Weekly Downloads

    116

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    6.78 kB

    Total Files

    13

    Last publish

    Collaborators

    • kanian77