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

features-manager

v1.0.1

Published

A lightweight TypeScript-based feature flag manager that enables conditional feature activation based on user-specific rules and percentage rollouts.

Downloads

3

Readme

Features Manager

A lightweight TypeScript-based features manager that enables conditional feature activation based on user-specific rules, including username and location-based rules, and percentage rollouts.

Description

The Features Manager is designed to help developers manage the visibility of features in their applications. It allows for conditional activation based on user-specific rules (including user IDs and usernames), location-specific rules (city, state, country), and percentage rollouts, providing a flexible and controlled way to release features.

How To Get Started

Installation

To install the package, run:

npm install features-manager

Initialization

Create an instance of the FeaturesManager with your feature configurations:

import FeaturesManager from 'features-manager';


const featureFlag = new FeaturesManager({
  flags: {
    newDashboard: {
      enabled: true,
      users: ['john_doe', 'jane_smith'],
      locations: ['New York', 'California', 'USA'],
      percentage: 25,
    },
    darkMode: {
      enabled: false,
    },
    premiumFeature: {
      enabled: true,
      users: ['john_doe'],
    },
    betaFeature: {
      enabled: true,
      percentage: 50,
    },
    stableFeature: {
      enabled: true,
    },
  },
});

Example Usage

import featureFlag from './featureFlag'; // assuming your feature flag instance is in featureFlag.ts

const userContext = {
  userId: 'john_doe',
  username: 'john_doe',
};

const locationContext = {
  city: 'New York',
  state: 'New York',
  country: 'USA',
};

// Check if the 'newDashboard' feature is enabled for the given user and location context
const isNewDashboardEnabled = featureFlag.isFeatureEnabled('newDashboard', userContext, locationContext);
console.log(`Is New Dashboard Enabled: ${isNewDashboardEnabled}`); // true

// Check if the 'darkMode' feature is enabled for the given user and location context
const isDarkModeEnabled = featureFlag.isFeatureEnabled('darkMode', userContext, locationContext);
console.log(`Is Dark Mode Enabled: ${isDarkModeEnabled}`); // false

// Check if the 'premiumFeature' is enabled for the given user and location context
const isPremiumFeatureEnabled = featureFlag.isFeatureEnabled('premiumFeature', userContext, locationContext);
console.log(`Is Premium Feature Enabled: ${isPremiumFeatureEnabled}`); // true

// Check if the 'betaFeature' is enabled for the given user
const isBetaFeatureEnabled = featureFlag.isFeatureEnabled('betaFeature', userContext, locationContext);
console.log(`Is Beta Feature Enabled: ${isBetaFeatureEnabled}`); // The output will be true or false based on percentage rollout

// Check if the 'stableFeature' is enabled for the given user
const isStableFeatureEnabled = featureFlag.isFeatureEnabled('stableFeature', userContext, locationContext);
console.log(`Is Stable Feature Enabled: ${isStableFeatureEnabled}`); // true

Sample Outputs

  1. Feature: newDashboard

    • User ID: john_doe
    • Username: john_doe
    • Location: New York, New York, USA
    • Output: true (enabled for this user and location)
  2. Feature: darkMode

    • User ID: unknown_user
    • Location: California, USA
    • Output: false (feature is disabled)
  3. Feature: premiumFeature

    • User ID: john_doe
    • Output: true (enabled for this user)
  4. Feature: betaFeature

    • User ID: john_doe
    • Username: john_doe
    • Location: New York, New York, USA
    • Output: true or false (depends on percentage rollout)
  5. Feature: stableFeature

    • User ID: john_doe
    • Username: john_doe
    • Location: New York, New York, USA
    • Output: true (feature is enabled)

Benefits

  • User-Specific Rules: Target features to specific users by ID or username.
  • Location-Based Rules: Enable features based on user's city, state, or country.
  • Percentage Rollouts: Gradually roll out features to a percentage of users.
  • Flexible Configuration: Easily manage feature flags through a centralized configuration.

This Features Manager provides a simple yet powerful way to manage feature visibility and ensure controlled feature rollouts, improving your development workflow and user experience.

Author: Micheal Ighietsemhe