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

extra-decorators

v0.1.1

Published

A collection of some additional useful decorators

Downloads

5

Readme

This is a set of additional decorators I found usefull while developing my projects. More will be added as I discover new ones. Pull requests are welcome.

This is a modular build meaning you can, if you want, only include what you really need. Use require('extra-decorators/mydecorator'). For a full reference, see below.

:warning: Some of these decorators are still experimental and may change in the future!

Reference

:warning: Order matters! Decorators which define the property must go after those that only hook into the property. For example, @alias should go after @onupdate. As a special case, core-decorator's @nonconfigurable should go before the rest.

@autoconstruct(Class)

Marks the property as being able to reconstruct itself using the underlying class and based on what has been given to it.

class Color {

  constructor(name: string) {
    this.name = name
  }

  // ...
}

class Shape {

  @autoconstruct(Color)
  color

  // ...
}

const shape = new Shape()
shape.color = "blue"
shape.color instanceof Color // true
shape.color.name // "blue"

Caveats

TypeScript does not know that the object gets converted to the appropriate type. Therefore, in order to avoid compiler errors, the type of the property has to be set to "any".

@alias(property)

Marks the property as being an alias for another property. The property can be a key referring to another property of the class, or it can be a full path using JavaScipt dot notation, e.g. foo[1].baz.bar.

class Foo {

  baz = {
    bar: 1
  }

  @alias('baz.bar')
  bar: number

}

const foo = new Foo()
foo.bar // gives 1
foo.bar = 3
foo.baz.bar // gives 3

@onupdate(callback)

Plain and simple: runs callback each time the given property gets updated.

this refers to the current instance.

@onaccess(callback)

Runs callback each time the given property gets accessed.

this refers to the current instance.

See Also

License

The MIT License