npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@slietar/decorators

v0.2.0-beta.4

Published

An advanced library of ES16 decorators

Downloads

2

Readme

Decorators

Highly experimental.

Install

$ npm install @slietar/decorators
$ tsd link # if using TypeScript

Decorators appliance

| Name | Class | Method | Parameter | Property | Status | |--------------------|:-----:|:------:|:---------:|:--------:|:------:| | @abstract | ✓ | ✓ (?) | ✗ | ✓ (?) | ❋ | | @animationFrame | ✗ | ✓ | ✗ | ✗ | ◉ | | @autobind | ✓alias: factorize() | ✓ | ✗ | ✗ | ◎ | | @check | ✓ (?) | ✓ | ✗ | ✓ (?)only: set() | ❋ | | @curry | ✗ | ✓ | ✗ | ✗ | ◎ | | @defaults | ✗ | ✗ | ✓ | ✗ | ✪ | | @defaults (extended implementation) | ✗ | ✗ | ✓ | ✓only: set() | ❋ | | @deprecate | ✓ | ✓ | ✓ | ✓ | ✪ | | @desync or @async | ✗ | ✓ | ✗ | ✓ | ◎ | | @experiment | ✓ | ✓ | ✓ | ✓ | ◉ | | @memoize | ✗ | ✓ | ✗ | ✗ | ❋ | | @nonconfigurable | ✗ | ✓ | ✗ | ✓ | ◎ | | @nonenumerable | ✗ | ✓ | ✗ | ✓ | ◎ | | @once | ✓ | ✓ | ✗ | ✗ | ◉ | | @once (extended implementation) | ✓ | ✓ | ✗ | ✓ | ❋ | | @readonly or @nonwritable | ✗ | ✓ | ✗ | ✓ | ◎ | | @serialize | ✓ | ✗ (?) | ✗ | ✗ (?) | ❋ | | @stage | ✓ | ✓ | ✓ | ✓ | ❋ |

❖ ..., ❋ not confirmed, ◎ not implemented, ◉ implemented, ✪ tested (coverage 100%) and fully typed

Maybe:

  • @promise: Q(r) if !isPromise(r) (Method, Property (?))

Usage

@deprecate()

@deprecate()
class A {
  @deprecate()
  p;

  @deprecate('Custom message')
  m() { }

  n(a, @deprecate(void 0, customLogger) b) { }
}

let a = new A() // on console.warn - DEPRECATION A: This feature is deprecated and will be removed in future versions
a.m(); // DEPRECATION A#m(): Custom message

a.n('1'); // nothing
a.n('1', '2') // on customLogger.warn - DEPRECATION A#n(1): ...

a.p; // DEPRECATION A#p: ...
a.p = 3; // nothing

Notes on @desync

On method:

class A {
  @desync(done => setTimeout(done, 500)) // same as @debounce(500)
  b() {

  }
}

On parameter:

class Auth {
  save(@desync() user) {
    this.user = user;
  }
}

var a = new Auth();

a.save(getPromise());

Notes on @serialize

@serialize()
class A {
  constructor() {
    this.a = 42;
  }

  getA() {
    return this.a;
  }
}

let json = JSON.stringify(new A());
// => { constructor: 'A', properties: { a: 42 } }

let parsed = JSON.parse(json);
let obj = A.fromJSON(parsed);
// => { a: 42, getA: [Function: getA] } }
@serialize()
class A {
  @serialize()
  a = 'John Doe';

  @nonserializable()
  b = 42;

  //        (     stringify     ) (       parse       )
  @serialize(c => c.toUpperCase(), c => c.toLowerCase())
  c = 'lorem ipsum';
}

new A()
  .__serializeProperties = {
    a: true,
    b: false,
    c: { serialize: [Fn], deserialize: [Fn] }
  };

TypeScript definitions

declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void;