singletonify.js
v0.1.1
Published
Implementation of Singleton design pattern
Downloads
7
Maintainers
Readme
singletonify.js
Create Singleton version of a class with ease
Installation
Via NPM
$ npm install singletonify.jsVia Yarn
$ yarn add singletonify.jsUsage
// ESM
import { Singletonify } from "singletonify.js";
// CommonJS
// const { Singletonify } = require("singletonify.js");
class Car {
brand: string;
constructor() {
this.brand = "Mercedes";
}
}
const SingletonifiedCar = Singletonify.singletonify(Car);
const car = SingletonifiedCar.getInstance();
console.log(car === SingletonifiedCar.getInstance()) // trueAPI
Library exports the Singletonify class.
static singletonify(Class)
The Singletonify class implements singletonify static method which accepts any class as an argument and returns a singletonified copy of it.
Tests
The tests are launched by the following command:
npm run testBuild
A production ready bundle is built using npm run build command.
After a successful build the following files will be generated in the dist folder:
├── singletonify.common.js
├── singletonify.esm.js
├── singletonify.js