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

@decorize/bind

v1.0.3

Published

Decorator to bind the method or all methods of the class to the context used to access it

Downloads

222

Readme

chat build quality coverage dependencies min+gzip typescript

Decorator to bind the method or all methods of the class to the context used to access it.

Install

npm install @decorize/bind --save

Usage

Decorate the method:

import { bind } from '@decorize/bind';

class Example {
  @bind
  public method(): boolean {
    return this instanceof Example;
  }
}

new Example().method.call(null); // True

Decorate the class:

import { bind } from '@decorize/bind';

@bind
class Example {
  public method(): boolean {
    return this instanceof Example;
  }
}

new Example().method.call(null); // True

Typing

export declare function bind(): ClassDecorator & MethodDecorator;
export declare function bind<T extends Function>(target: T): T;
export declare function bind(target: object, property: PropertyKey, descriptor: PropertyDescriptor): PropertyDescriptor;

Feature

  • Support different naming conventions.
    Available in lowercase @bind or capital letter @Bind.

  • Support different coding conventions.
    Applicable directly to the declaration @bind or as the decorator's factory @bind().

  • Support method and class decoration.
    Particular method or class (methods on the constructor's prototype) can be decorated with automated binding to the context on the fly with subsequent caching.

  • Cache of own and inherited bound methods.
    Bound methods are added to context-dependent cache to avoid unnecessary bindings and increase performance.

  • Polyfill free, TypeScript and ES5 compatibility.
    There is no need for any polyfill and can be fully used with TypeScript (d.ts) and ES5.

  • Intelligent and backward compatible (ES5 vs ES2015+).
    Ensures correct use of the decorator and verifies whether the method can be decorated by checking the attributes of the descriptor. Methods derived from the prototype or by using the super will not be bound.

  • Advanced decoration and synergy with other decorators.
    Logic respects the original method and other decorators, so all the attributes of the descriptor not related to this decorator will be kept or adapted.

  • Extensive source documentation and testing coverage.
    Source code is fully documented and tested for each line.

Future

The package includes an implementation of the decorator using the TypeScript syntax and will be extended in future with the new proposal from TC39.

We are actively supporting the package, so please contact us at GitHub or Gitter if you have any suggestions or questions.