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 🙏

© 2026 – Pkg Stats / Ryan Hefner

auto-bind-js

v1.2.1

Published

Automatically bind class methods to their instance. Supports include/exclude filters, decorator pattern, inheritance, and lazy binding.

Readme

auto-bind-js

Automatically bind class methods to their instance. Zero dependencies.

A modern, feature-rich alternative to auto-bind with extra capabilities: lazy binding, regex pattern matching, decorators, Symbol-keyed methods, and full TypeScript support.

Install

npm install auto-bind-js

Usage

Basic

import autoBind from 'auto-bind-js';

class Unicorn {
  constructor(name) {
    this.name = name;
    autoBind(this);
  }

  message() {
    return `${this.name} is awesome!`;
  }
}

const unicorn = new Unicorn('Rainbow');
const { message } = unicorn;
message(); //=> 'Rainbow is awesome!'

CommonJS

const autoBind = require('auto-bind-js');

module.exports = class Controller {
  constructor() {
    autoBind(this);
  }

  index(req, res) {
    // `this` is always bound to the instance
    res.json(this.getData());
  }

  getData() {
    return { status: 'ok' };
  }
};

Bind specific methods (shorthand)

autoBind(this, 'handleClick', 'handleSubmit');

Options

// Only bind these methods
autoBind(this, { include: ['handleClick', 'handleSubmit'] });

// Bind all except these
autoBind(this, { exclude: ['render', 'toString'] });

// Bind only methods matching a pattern
autoBind(this, { pattern: /^handle/ });

// Lazy binding — binds on first access (better perf for large classes)
autoBind(this, { lazy: true });

React

Excludes all React lifecycle methods automatically:

import autoBindReact from 'auto-bind-js/react';

class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    autoBindReact(this);
  }

  handleClick() {
    // `this` is always the component instance
  }

  render() {
    return <button onClick={this.handleClick}>Click</button>;
  }
}

Decorators

import { boundClass, bound } from 'auto-bind-js/decorator';

// Class decorator — binds ALL methods
@boundClass
class Foo {
  constructor() {
    this.name = 'foo';
  }

  handleClick() {
    return this.name; // always bound
  }
}

// Method decorator — bind individual methods
class Bar {
  constructor() {
    this.name = 'bar';
  }

  @bound
  handleClick() {
    return this.name; // always bound
  }
}

API

autoBind(self, options?)

Bind methods of self to the instance. Returns self.

Options

| Option | Type | Description | | --------- | -------------------- | ---------------------------------------------- | | include | (string\|symbol)[] | Only bind these methods | | exclude | (string\|symbol)[] | Skip these methods | | pattern | RegExp | Only bind methods whose names match this regex | | lazy | boolean | Bind on first access instead of immediately |

autoBindReact(self, options?)

Same as autoBind but automatically excludes React lifecycle methods (render, componentDidMount, shouldComponentUpdate, etc.)

boundClass(target)

Class decorator. Auto-binds all methods when the class is instantiated.

bound(target, key, descriptor)

Method decorator. Lazily binds the decorated method to the instance on first access.

Features

  • ✅ Zero dependencies
  • ✅ Binds inherited methods
  • ✅ Supports Symbol-keyed methods
  • ✅ Include/exclude filters
  • ✅ Regex pattern matching
  • ✅ Lazy binding mode
  • ✅ React lifecycle awareness
  • ✅ Class & method decorators
  • ✅ Full TypeScript declarations
  • ✅ ESM + CommonJS dual package
  • ✅ Lightweight (~2KB)

License

MIT