@forge/bridge
5.14.0-next.45.14.0-next.5
out/featureFlags/evaluator.js+
out/featureFlags/evaluator.jsNew file+53
Index: package/out/featureFlags/evaluator.js
===================================================================
--- package/out/featureFlags/evaluator.js
+++ package/out/featureFlags/evaluator.js
@@ -0,0 +1,53 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Evaluator = void 0;
+class Evaluator {
+ constructor(results) {
+ this.results = results;
+ }
+ checkFlag(flagName, defaultValue) {
+ if (!this.results || !this.results.feature_flags) {
+ return defaultValue;
+ }
+ const featureFlags = this.results.feature_flags;
+ let hashedValue = '';
+ try {
+ hashedValue = this.getHashedValue(flagName);
+ }
+ catch (err) {
+ console.error('Unexpected error occurred while evaluating flag ', err);
+ return defaultValue;
+ }
+ if (!hashedValue) {
+ return defaultValue;
+ }
+ const evaluatedFlag = featureFlags[hashedValue];
+ if (evaluatedFlag) {
+ if (evaluatedFlag.disabled) {
+ return false;
+ }
+ return evaluatedFlag.value;
+ }
+ return defaultValue;
+ }
+ shutDown() {
+ this.results = undefined;
+ }
+ getHashedValue(flagName) {
+ if (typeof flagName !== 'string') {
+ return '';
+ }
+ const input = flagName.trim();
+ if (input.length === 0) {
+ return '';
+ }
+ let hash = 5381;
+ for (let i = 0; i < input.length; i += 1) {
+ const charCode = input.charCodeAt(i);
+ hash = (hash << 5) + hash + charCode;
+ hash |= 0;
+ }
+ return (hash >>> 0).toString();
+ }
+}
+exports.Evaluator = Evaluator;