singletonify.js
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

singletonify.js

Create Singleton version of a class with ease

Commitizen friendly

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

License

MIT

Package Sidebar

Install

npm i singletonify.js

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

10.4 kB

Total Files

14

Last publish

Collaborators

  • 3vil_arthas