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

@hazeljs/feature-toggle

v1.0.5

Published

Feature toggle module for HazelJS framework

Readme

@hazeljs/feature-toggle

Feature flags with one decorator. Protect routes or branch in code.

In-memory flags, optional env seeding, and @FeatureToggle('name') on controllers or methods. When the flag is off, the route returns 403. No external SDK — just core.

npm version npm downloads License: Apache-2.0

Features

  • Decorator-first@FeatureToggle('name') on a controller or method; no manual guards
  • In-memory – Simple flag store; optional seed from initialFlags or env prefix
  • Env integration – Use envPrefix (e.g. FEATURE_) to load flags from environment variables
  • Programmatic API – Inject FeatureToggleService and call isEnabled(), set(), get()
  • TypeScript – Full type support, no extra dependencies beyond @hazeljs/core

Installation

npm install @hazeljs/feature-toggle

Quick Start

1. Register the module

import { HazelModule } from '@hazeljs/core';
import { FeatureToggleModule } from '@hazeljs/feature-toggle';

@HazelModule({
  imports: [
    FeatureToggleModule.forRoot({
      initialFlags: { newCheckout: true },
      envPrefix: 'FEATURE_', // FEATURE_X from env → flag "x"
    }),
  ],
})
export class AppModule {}

2. Protect routes with the decorator

import { Controller, Get } from '@hazeljs/core';
import { FeatureToggle } from '@hazeljs/feature-toggle';

@Controller('checkout')
export class CheckoutController {
  @Get('new')
  @FeatureToggle('newCheckout')
  getNewCheckout() {
    return { flow: 'new' };
  }

  @Get('legacy')
  getLegacyCheckout() {
    return { flow: 'legacy' };
  }
}

// Or require the flag for the whole controller:
@Controller('beta')
@FeatureToggle('betaApi')
export class BetaController {
  @Get()
  index() {
    return { message: 'Beta API' };
  }
}

3. Use in services (programmatic)

import { Service } from '@hazeljs/core';
import { FeatureToggleService } from '@hazeljs/feature-toggle';

@Service()
export class OrderService {
  constructor(private readonly featureToggle: FeatureToggleService) {}

  createOrder(data: OrderData) {
    if (this.featureToggle.isEnabled('newCheckout')) {
      return this.createWithNewFlow(data);
    }
    return this.createWithLegacyFlow(data);
  }
}

API

FeatureToggleModule

  • FeatureToggleModule.forRoot(options?)
    Registers the module. Options:
    • initialFlags?: Record<string, boolean> – Flags to set on load
    • envPrefix?: string – Env var prefix (e.g. FEATURE_); vars like FEATURE_NEW_UI become flag newUi. Values true, 1, yes (case-insensitive) → true.

FeatureToggleService

  • isEnabled(name: string): boolean – Returns whether the flag is on (default false if unset).
  • get(name: string): boolean | undefined – Raw value; undefined if not set.
  • set(name: string, value: boolean): void – Set or override a flag at runtime (in-memory).

Decorator

  • @FeatureToggle(featureName: string) – Method or class decorator. Applies a guard so that when the flag is disabled, the request is rejected (403) and the handler is not run.

Environment variables

With envPrefix: 'FEATURE_':

FEATURE_NEW_CHECKOUT=true
FEATURE_BETA_API=0
FEATURE_NEW_UI=yes

Flag names are derived in camelCase: FEATURE_NEW_CHECKOUTnewCheckout.

Testing

npm test

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

Apache 2.0 © HazelJS

Links