singletonify.js
v0.1.1
Published
Implementation of Singleton design pattern
Downloads
2
Maintainers
Readme
singletonify.js
Create Singleton version of a class with ease
Installation
Via NPM
$ npm install singletonify.js
Via Yarn
$ yarn add singletonify.js
Usage
// 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()) // true
API
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 test
Build
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