0.1.10 • Published 4 months ago

flagfrog v0.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

FlagFrog

A simple library for managing feature flags in your applications.

Installation

# install
npm install flagfrog

CLI

The CLI provides the following commands:

  • list
    • Displays where Flag is used
  • remove
    • Remove Flag from files

List Command

Displays where Flag is used

# input (Display the list of flags under src)
npx flagfrog list './src/**/*.{ts,tsx}'
# output
FlagName
├──/path/to/file1
├──/path/to/file2
└──/path/to/file3

Remove Command

Remove Flag from files.

# input (Remove Flag from files under src)
npx flagfrog remove './src/**/*.{ts,tsx}'

Remove the flag from the implementation as shown below. Please execute this when branching by flag is no longer necessary.

// before
import { flagHandler } from "flagfrog";

FlagHandler({
  name: "FlagName",
  value: true,
  on: () => {
    console.log("ON");
  },
  off: () => {
    console.log("OFF");
  },
});
// after
console.log("ON");

API

FlagFrog provides a simple API for feature flag;

flagHandler

Branch processing depending on whether the flag is ON or OFF.

ArgumentTypeDescription
namestringFlag naming, used in the CLI
valuebooleanWhether flag is on or off
on() => TDispatches when the value is ON
off() => UDispatches when the value is OFF

The following is a sample code.

import { flagHandler } from "flagfrog";

flagHandler({
  name: "FlagName",
  value: true,
  on: () => {
    // Dispatches when the flag is ON
    console.log("ON");
  },
  off: () => {
    // Dispatches when the flag is OFF
    console.log("OFF");
  },
});

When you run the remove command, it will be converted to the following:

console.log("ON");

flagSwitcher

Branch the value returned depending on whether the flag is ON or OFF.

ArgumentTypeDescription
namestringFlag naming, used in the CLI
valuebooleanWhether flag is on or off
onTReturn when the value is ON
offUReturn when the value is OFF

The following is a sample code.

import { flagSwitcher } from "flagfrog";

const result = flagSwitcher({
  name: "FlagName",
  value: true,
  on: "ON Text!!"
  off: "OFF Text!!"
});

When you run the remove command, it will be converted to the following:

const result = "ON Text!!";

FlagRenderer

Branch the component to be displayed depending on the ON/OFF of the flag

PropsTypeDescription
namestringFlag naming, used in the CLI
valuebooleanWhether flag is on or off
onReactNodeRender when the value is ON
offReactNodeRender when the value is OFF

The following is a sample code.

import { flagHandler } from "flagfrog";

const Component = () => {
  return (
    <FlagRenderer
      name="FlagName"
      value={true}
      on={<p>ON Text!!</p>}
      off={<p>OFF Text!!</p>}
    />
  );
};

When you run the remove command, it will be converted to the following:

const Component = () => {
  return <p>ON Text!!</p>;
};
0.1.10

4 months ago

0.1.9

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.6

6 months ago

0.1.4

6 months ago

0.1.5

6 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago