Socket
Book a DemoInstallSign in
Socket

feature-toggle-decorator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feature-toggle-decorator

Feature Toggle Decorator

1.0.0
latest
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Feature Toggle Decorator

Travis npm David

A decorator that will only execute the wrapped function if it is given a truthy parameter, and optionally call a fallback method if the feature is not enabled.

Usage

import { isEnabled } from "./is-enabled";

const features = {
  FEATURE_1: true,
  FEATURE_2: false,
  FEATURE_3: false
};

class Example {
  @isEnabled(features.FEATURE_1)
  public test1() {
    // will be called
  }

  @isEnabled(features.FEATURE_2)
  public test2() {
    // will not be called
  }

  @isEnabled(features.FEATURE_3, "fallbackMethod")
  public test3(...args) {
    // will not be called
  }

  public fallbackMethod() {
    // will be called instead of test3
  }

}

Note that any arguments sent to a disabled method with a fallback will be passed on to the fallback.

Limitations

  • The decorator parameters are evaluated at compile time so it is not possible to dynamically toggle features
  • Fallback methods must be specified by string name

Contributing

Issues and PRs are very welcome. To get the project set up run:

git clone git@github.com:solirius/feature-toggle-decorator
npm install --dev
npm test

If you would like to send a pull request please write your contribution in TypeScript and if possible, add a test.

License

This software is licensed under GNU GPLv3.

Keywords

Feature

FAQs

Package last updated on 19 Sep 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.