flags-js

1.1.0 • Public • Published

JS Client SDK for Feature Flags API

Install

npm i flags-js

Usage

import Features from "flags-js";
const apiKey = "123456790";
 
async function Example() {
  const user = {
    key: "johnDoe@gmail.com", // must be unique
    attributes: {
      age: 25,
      gender: "male",
      sports: ["basketball", "hockey"],
    },
  };
 
  const features = await Features.initializeClient(apiKey, user);
 
  // simple on/off flag
  const shouldShowNewModal = features.isEnabled("new-modal-flag-key");
  // string flag
  const newToolbarColor = features.getFlagVariation("new-toolbar-flag");
}
  • initializeClient makes api call to fetch all flags
  • attributes are what is matched in user targeting / segments

isEnabled(flagKey): Boolean

Returns evaluation of flag for user. If flag is disabled or client initialization fails it returns false by default.

getFlagVariation(flagKey): String

Returns name of variation if exists, otherwise null. Using this for flag keys associated with boolean flags will return "On" or "Off".

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.00
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i flags-js

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

4.83 kB

Total Files

5

Last publish

Collaborators

  • logojoydev