Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Feature toggling service that enables split testing
import seedrandom from 'seedrandom';
export type featureTypes = {
'killer-feature': number | boolean;
};
@Injectable({
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)) {
seedrandom(this.userId);
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
You can’t perform that action at this time.