class-composer
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

class-composer

What it does?

it allows you to easily compose typed class from other JS\TS classes with IntelliSense!

How to use it?

imagine we have the following classes

import { compose } from 'class-composer';

class User {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
}
class Activateable {
  activated: boolean = false;

  activate() {
    this.activated = true;
  }

  deactivate() {
    this.activated = false;
  }
}
class Shareable {
  name!: string;
  private shared: boolean = false;

  share() {
    this.shared = true;
  }

  unshare() {
    this.shared = false;
  }

  getShareInfo() {
    return `${this.name} share is ${this.shared ? '' : 'not'} shared`;
  }
}

we can compose them together like this

const ComposedClass = compose(User, Shareable, Activateable);
// or another option is
class ComposedClass extends compose(User, Shareable, Actiavteable) {...}

and usage would look like

const instance = new ComposedClass('some_name');
instance.activate();

console.log(instance.name); // some_name
console.log(instance.activated); // true
console.log(instance.getShareInfo()); // some_name is not shared

Readme

Keywords

none

Package Sidebar

Install

npm i class-composer

Weekly Downloads

0

Version

1.0.11

License

ISC

Unpacked Size

10.6 kB

Total Files

10

Last publish

Collaborators

  • assafbarash