FlagsterFlagster

JavaScript vanilla

This library can be used with pure JavaScript, React (and all other popular frameworks/libraries).

Usage

npm install flagster

initialize the client and get the flags

import { createFlagster } from 'flagster';
 
const flagster = createFlagster()
 
flagster.init({
  environment: 'YOUR_ENVIRONMENT'
})
 
const flags = flagster.getFlags()
 
if(flags.github_auth) {
    // do something
}

Configuration

When initializing the client, you can pass the following options:

PropTypeDefault
environment
string
-
identity?
string
-
defaultFlags?
Record<string, boolean>
{}
onChange?
function
-

defaultFlags

You can pass default flags when initializing the client. These flags will be used until the client receives the flags from the server.

import { createFlagster } from 'flagster';
 
const flagster = createFlagster()
 
flagster.init({
  environment: 'YOUR_ENVIRONMENT',
  defaultFlags: {
    github_auth: true,
    sms_verification: false
  }
})

onChange

You can pass a callback function that will be called when the flags are updated.

import { createFlagster } from 'flagster';
 
const flagster = createFlagster()
 
flagster.init({
  environment: "YOUR_ENVIRONMENT",
  onChange: (oldFlags, newFlags) => {
    if(newFlags.github_auth) {
      // do something
    }
  }
})

Methods

getFlags

Get all flags from the client. This dont trigger a request to the server.

import { createFlagster } from 'flagster';
 
const flagster = createFlagster()
 
flagster.init({
  environment: 'YOUR_ENVIRONMENT'
  }
})
 
const flags = flagster.getFlags()
 
if(flags.github_auth) {
    // do something
}

onChange

On change occurs when the flags are updated. This is useful when you want to execute something based on the flags. This can be triggered by a change from cached flags or a change from the server.

import { createFlagster } from 'flagster';
 
const flagster = createFlagster()
 
flagster.init({
  environment: 'YOUR_ENVIRONMENT'
})
 
flagster.onChange((oldFlags, newFlags) => {
  if(newFlags.github_auth) {
    // do something
  }
})

On this page