Socket
Socket
Sign inDemoInstall

flags-js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flags-js

js client lib for feature flags api


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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".

FAQs

Package last updated on 13 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc