Skip to content

Latest commit

 

History

History
85 lines (62 loc) · 2.71 KB

README.md

File metadata and controls

85 lines (62 loc) · 2.71 KB

Monorepo for packages published under the @decorators/* scope on JSR.


Packages

Alias class members to simplify stack traces.

import { alias } from "@decorators/alias";

class Foo {
  // alias() can be used to create multiple aliases from one original member
  @alias("qux", "nurp")
  bar(): string {
    return "baz";
  }

  // declare the aliased members to avoid compilation errors
  declare qux: Foo["bar"];
  declare nurp: Foo["bar"];

  // or, use @alias.for on the alias itself and pass it the original member name.
  @alias.for("bar")
  baz(): string {
    return this.bar();
  }
}

const foo = new Foo();

console.assert(foo.bar === "baz"); // OK
console.assert(foo.bar === foo.baz); // OK
console.assert(foo.qux === foo.bar); // OK
console.assert(foo.nurp === foo.bar); // OK

Bind methods, getters, and setters to the appropriate context object, with support for static members and inheritance.

import { bind } from "@decorators/bind";

class Foo {
  @bind bar(): Foo {
    return this;
  }

  @bind static self(): typeof Foo {
    return this;
  }
}
const { self } = Foo, { bar } = new Foo();

console.log(self === Foo); // true
console.log(bar() instanceof Foo); // true

MIT © Nicholas Berlette. All rights reserved.