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

toggle-point

v0.1.2

Published

Allow toggling of any function, or object method or property

Readme

Toggle Point

Feature toggles are a powerful technique, allowing teams to modify system behavior without changing code. [...] Toggles introduce complexity. We can keep that complexity in check by using smart toggle implementation practices and appropriate tools to manage our toggle configuration, but we should also aim to constrain the number of toggles in our system.

Pete Hodgson, Feature Toggles

This library takes care of the smart toggle implementation practices part by allowing you to toggle a function or object on any condition.

(right now, only function toggle is supported, with support for async functions and generators).

Written in ES6 for Node5. Support for node4 and browsers will be coming soon.

Installation

npm install --save toggle-point

Usage

import togglePoint from 'toggle-point';

function myFunctionToToggle(param) {
  return param;
}

const myToggledFunction = togglePoint(myFunctionToToggle, {
  when: (param) => param === 1,
  then: (param) => -1
});

myToggledFunction, when called, will either use the original function (when the param is anything but 1), or use the alternative version (if the param is 1)

Of course in real life, you would rather toggle depending on some context (user rights, feature activation …)

Modes

By default both the when and then are synchronous. You can use async functions too (or anything that returns a promise), by specifying mode: togglePoint.mode.async:

import togglePoint from 'toggle-point';

async function myFunctionToToggle(param) {
  return await Promise.resolve(param);
}

const myToggledFunction = togglePoint(myFunctionToToggle, {
  mode: togglePoint.mode.async,
  when: async (param) => await param === 1,
  then: async (param) => await Promise.resolve(-1)
});

The when function does not need to be async for this to work.

There is also a generator mode that allows you to toggle generator functions. Note that in generators the when function must be synchronous, as to not pollute the yield results:

import togglePoint from 'toggle-point';

function* myFunctionToToggle(param) {
  yield 1;
  yield 2;
  return param;
}

const myToggledFunction = togglePoint(myFunctionToToggle, {
  mode: togglePoint.mode.generator,
  when: (param) => param === 1,
  * then(param) {
    yield 4;
    yield 1;
    return yield param;
  }
});

The complete list of modes right now is:

(togglePoint.mode....)

  • sync: Synchronous function, toggle and alternative. The default
  • async: Asynchronous function, toggle and alternative. Any one of them may actually be synchronous
  • generator: Generator function and alternative. Toggle must be synchronous.

Testing

The lib is 100% unit-tested using Mocha and Chai. It is developed in TDD.

Roadmap

  • Toggle objects, method by method
  • Toggle object properties
  • Do some performance testing
  • Make a version that can run on Node4 and browsers
  • ~~Deploy on npm registry (once it looks good and well documented)~~ (still I could publish on just toggle-point, that would make it easier to use)
  • Develop a companion feature management library to have a complete feature toggle system
  • Use it on real production code (there's a reason why I'm developing this :) )

Building and helping

Clone the project,

npm install

In one terminal window:

npm run build:watch

In another terminal window:

npm run test:watch

All contributions and issues are welcome !