1.0.11 • Published 2 years ago

class-composer v1.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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
1.0.11

2 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago