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-flagger

v0.1.6

Published

Flagger is a library designed for check and manage feature flags in js ecosystem

Downloads

9

Readme

Flagger

StackBlitz

Flagger is a core library designed for feature flags. You can easily manage your features in separation, almost every feature can be modular.

Usage

const featureManagerConfig = {
    //Define features
    features: [
        {
            name: 'Feature1',
            description: 'Test feature 1',
            version: '0.1',
            default: false // Inactive by default
        }
    ]
};
const featureManager = new FlaggerFeaturesManager(featureManagerConfig);

await featureManager.loadFeatures(); // Load features and check constraint.

Feature definition

const featureDefinition = {
    name: '', // min 4 letters and max 25 letters
    default: false, // boolean, optional - means, that feature can be active for initial state
    version: string, // min 1 and max 10 letters
    hidden: false, // boolean, optional
    description: '', // string, min 5 letters and max 250 letters
    tags: undefined, // Array<string>, optional
    activators: [], // FlaggerActivator, optional
    constraint: undefined // FlaggerConstraint, optional
};

Load configuration

// Via constructor - internal config
const featureManager = new FlaggerFeaturesManager(featureManagerConfig);

// Via method - internal config
const featureManager = new FlaggerFeaturesManager();
featureManager.loadConfig(featureManagerConfig);

// Via method - external, imported as object config
// In this case constraint should be a string
const featureManager = new FlaggerFeaturesManager();
await featureManager.loadExternalConfig(featureManagerConfig);

Constraints

Constraints are used to activate feature immediately after load itself. You can define this one inside script as singular or FlaggerChainConstraint. Another possibility is string sentence but not every kind of constraint supports this capacity.

Example in js (chaining):

const flagChainConstraint = new FlaggerChainConstraint(new FlaggerOnlineConstraint())
    .and(new FlaggerDateIntervalConstraint(
        {
            startDate: new Date(2019, 9, 6),
            endDate: new Date(2022, 10, 11)
        }
    ));

Example in json:

{
   "features": [
       {
          "name": "SomeFeature",
          "version": "0.0.1",
          "description": "Some existing feature",
          "constraint": "betweenDate('2022-09-01', '2022-10-14') and isOnline"
       }
   ],
  "constraintDeserializers": [
      
  ]
}

Example in js (custom constraint):

const flaggerCustomConstraint = new FlaggerCustomConstraint({
    checker: async () => window.navigator.language.startsWith('en')
});

List constraints to use

  • FlaggerSupportsConstraint - Use feature when browser supports some features.
  • FlaggerOnlineConstraint - Use feature when user is online.
  • FlaggerDateIntervalConstraint - Use feature between date ranges.

Realtime Constraints

Realtime constraint can be used to make feature disposable according to some requirements. It can be usefully especially when your feature must be available only for some conditions.

{
    "name": "OnlineFeature",
    "description": "Feature will be available when user is online",
    "version": "0.14",
    "realtimeConstraint": [
        "whenOnline"
    ]
}

Constraint Deserializers (External config)

Custom Deserializers

externalConfig.json:

{
  "features": [
    {
      "name": "SomeFeature",
      "version": "0.0.2",
      "description": "Real feature :)",
      "constraint": "representativeName('sm')"
    }
  ],
  "constraintDeserializers": [
    "pathToExternalSerializerScript.js"
  ]
}

pathToExternalSerializerScript.js:

import FlaggerCustomConstraint from 'features-flagger';

export default {
    representativeName: 'representativeName',

    deserialize(sm) {
        return new FlaggerCustomConstraint({
            checker: async () => sm === 'sw'
        });
    }  
};