<commit_before>import launchDarklyBrowser from "ldclient-js";
const url = require('url');

export function getLocation() {
  if (window.location) {
    return window.location.toString();
  } else {
    return '';
  }
}

export function ldBrowserInit (key, user) {
  return launchDarklyBrowser.initialize(key, user);
}

export function ldOverrideFlag(flagKey) {
  let override;
  /*
   POST /users?features=send-onboarding-email
   # Overrides the `send-onboarding-email` boolean feature flag, setting it to `true`
   GET /users/101?features=show-user-email,user-nicknames,hide-inactive-users
   # Enables the `show-user-email`, `user-nicknames`, and `hide-inactive-users` feature flags
   POST /users?features.verify-email=false&features.email-frequency=weekly
   # Disables the `verify-email` feature flag and sets the `email-frequency` variation to "weekly"
   */
  const query = url.parse(exports.getLocation(), true).query;
  const queryFlag = query["features." + flagKey];

  if (typeof queryFlag !== "undefined"){
    if (queryFlag === ""){
      override = true;
    } else if (queryFlag === "false"){
      override = false;
    }
  }
  return override;
}

export function getAllFeatureFlags (key, user) {
  const ldClient = ldBrowserInit(key, user);
  return new Promise((resolve, reject) => {
    ldClient.on("ready", () => {
      resolve(ldClient.allFlags());
    });
  });
}<commit_msg>parse query parameter "features" in simple and list forms<commit_after>import launchDarklyBrowser from "ldclient-js";
const url = require('url');

export function getLocation() {
  if (window.location) {
    return window.location.toString();
  } else {
    return '';
  }
}

export function ldBrowserInit (key, user) {
  return launchDarklyBrowser.initialize(key, user);
}

export function ldOverrideFlag(flagKey) {
  let override;
  /*
   POST /users?features=send-onboarding-email
   # Overrides the `send-onboarding-email` boolean feature flag, setting it to `true`
   GET /users/101?features=show-user-email,user-nicknames,hide-inactive-users
   # Enables the `show-user-email`, `user-nicknames`, and `hide-inactive-users` feature flags
   POST /users?features.verify-email=false&features.email-frequency=weekly
   # Disables the `verify-email` feature flag and sets the `email-frequency` variation to "weekly"
   */
  const query = url.parse(exports.getLocation(), true).query;
  const queryFlag = query["features." + flagKey];
  const queryFeatures = query['features'];

  if (typeof queryFlag !== "undefined"){
    if (queryFlag === ""){
      override = true;
    } else if (queryFlag === "false"){
      override = false;
    }
  } else if (queryFeatures) {
    queryFeatures.split(',').forEach((f) => {
      if (f === flagKey){
        override = true;
      }
    })
  }

  return override;
}

export function getAllFeatureFlags (key, user) {
  const ldClient = ldBrowserInit(key, user);
  return new Promise((resolve, reject) => {
    ldClient.on("ready", () => {
      resolve(ldClient.allFlags());
    });
  });
}
{'fraction_non_alphanumeric': 0.14134742404227213, 'fraction_numerical': 0.0019815059445178335, 'mean_word_length': 3.8619582664526484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6309211', 'n_tokens_mistral': 942, 'n_tokens_neox': 917, 'n_words': 228}