Skip to content

Instantly share code, notes, and snippets.

Last active August 26, 2018 10:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lydemann/2b54f431a3a1f1614519fceaaeb3a628 to your computer and use it in GitHub Desktop.
Feature toggling service that enables split testing
import seedrandom from 'seedrandom';
export type featureTypes = {
'killer-feature': number | boolean;
providedIn: 'root'
export class FeatureToggleService {
public features: featureTypes;
public userId: string = 'some-user-id';
constructor() {}
public isFeatureEnabled(feautureName: keyof featureTypes): boolean {
const featureValue = this.features[feautureName];
if (Number.isInteger(featureValue as number)) {
const isEnabled = Math.floor(Math.random() * 100) <= featureValue;
return isEnabled;
} else {
return featureValue as boolean;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment