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

@karhoo/lib-feature-flags

v20.1.4

Published

Feature flags 🚩 library for Karhoo web apps. It provides possibility to enable/disable certain feature per environment without redeployment πŸ™ƒ

Downloads

28

Readme

This library was created in order to have a possibility to enable/disable certain feature per environment without redeployment.

License

Installation

npm i @karhoo/lib-feature-flags

Warnings

This library uses Promise, async/await and other modern JS features so currently it works only in modern browsers by default. For old browsers you must run babel on it.

Usage

In order to get Feature flags config you need to make request for remoteConfig:

import { FeatureFlags, RemoteConfig } from '@karhoo/lib-feature-flags'
import { getApi } from '@karhoo/demand-api'

const defaultOptions = { defaultValueForMissingKeys: false }

let flagsInstance

const initFlagsInstance = config => {
  const api = getApi({
  url: 'api',
  defaultRequestOptionsGetter: () => ({
    headers: {
      identifier: 'XXXX',
      referrer: 'https://example-referer.com/',
    },
  }),
})

  const { session, flags } = config
  const organisationId = 'organisationId'
  const remoteConfigFetcher = () =>
    api.flagsService.getLatestVersion({ organisationId, platform: 'web' }).then(data => {
      return data.body?flags || {}
    })

  flagsInstance = new FeatureFlags(new RemoteConfig(remoteConfigFetcher), flags || defaultOptions)
}

const getFlagsInstance = () => {
  return flagsInstance
}

After creating getFlagsInstances funtion you can use it, for example:

 if (someCondition && getFlagsInstance().isEnabled(MY_FEATURE))) {
   // do thomething...
 }

FeatureFlags

It takes config and has such functionality as enable/disable feature and isEnabled method that returns boolean for feature flag that is passed to it. By default it returns false if key is missing. This behavior can be changed by passing options to it.

FeatureProvider

FeatureProvider is a provider of FeatureFlags. Use it in your App component so that every component can use this functionality.

Feature component could be used for every feature that you want to have a possibility to enable/disable. Example of usage:

<Feature name="pageLogo"> <PageLogo /> </Feature>

ObjectConfig

It can be used if you want to use simple object as a config for feature toggling. It takes config and environment so different configs could be used per different environments.

Issues

Looking to contribute?

πŸ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior with a label FEATURE_FLAGS

πŸ’‘ Feature Requests

Please file an issue to suggest new features with a label FEATURE_FLAGS. Vote on feature requests by adding a πŸ‘. This helps maintainers prioritize what to work on.

❓ Questions

For questions related to using the library, please re-visit a documentation first. If there are no answer, please create an issue with a label help needed and FEATURE_FLAGS.

Contributing

License

BSD-2-Clause