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M,GAC7B,OAAoB,IAAhB,EAAK,QAAkC,IAAlB,EAAO,SAKb,IAAhB,EAAK,QAAgB,EAAK,SAAS,MAAe,EAAO,SAAS,EAEvE,CAKA,SAAS,MACP,OAAO,qBAAqB,MAC9B,CAQA,SAAS,qBAAqB,GAC5B,MAAO,CAAC,CAAC,EAAU,GACrB,CAQA,SAAS,KAAK,EAAG,GACf,OAAO,EAAE,GAAK,EAAE,EAClB","file":"/npm/franc-all@7.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/franc-all@7.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// This file is generated by `build.js`\n/**\n * @typedef {import('trigram-utils').TrigramTuple} TrigramTuple\n *\n * @typedef Options\n * @property {Array<string>} [only]\n *   Languages to allow.\n * @property {Array<string>} [ignore]\n *   Languages to ignore.\n * @property {number} [minLength=10]\n *   Minimum length to accept.\n */\n\n/* Load `trigram-utils`. */\nimport {asTuples} from 'trigram-utils'\n\n/* Load `expressions` (regular expressions matching\n * scripts). */\nimport {expressions} from './expressions.js'\n\n/* Load `data` (trigram information per language,\n * per script). */\nimport {data} from './data.js'\n\n/* Maximum sample length. */\nconst MAX_LENGTH = 2048\n\n/* Minimum sample length. */\nconst MIN_LENGTH = 10\n\n/* The maximum distance to add when a given trigram does\n * not exist in a trigram dictionary. */\nconst MAX_DIFFERENCE = 300\n\nconst own = {}.hasOwnProperty\n\n/* Construct trigram dictionaries. */\n\n/** @type {string} */\nlet script\n\n/** @type {Record<string, Record<string, Record<string, number>>>} */\nconst numericData = {}\n\nfor (script in data) {\n  if (own.call(data, script)) {\n    const languages = data[script]\n    /** @type {string} */\n    let name\n\n    numericData[script] = {}\n\n    for (name in languages) {\n      if (own.call(languages, name)) {\n        const model = languages[name].split('|')\n        /** @type {Record<string, number>} */\n        const trigrams = {}\n        let weight = model.length\n\n        while (weight--) {\n          trigrams[model[weight]] = weight\n        }\n\n        numericData[script][name] = trigrams\n      }\n    }\n  }\n}\n\n/**\n * Get the most probable language for the given value.\n *\n * @param {string} [value]\n *   The value to test.\n * @param {Options} [options]\n *   Configuration.\n * @return {string}\n *  The most probable language.\n */\nexport function franc(value, options) {\n  return francAll(value, options)[0][0]\n}\n\n/**\n * Get a list of probable languages the given value is\n * written in.\n *\n * @param {string} [value]\n *   The value to test.\n * @param {Options} [options]\n *   Configuration.\n * @return {Array<TrigramTuple>}\n *   An array containing language—distance tuples.\n */\nexport function francAll(value, options = {}) {\n  /** @type {Array<string>} */\n  // @ts-expect-error: `whitelist` is from long ago.\n  const only = [...(options.whitelist || []), ...(options.only || [])]\n  /** @type {Array<string>} */\n  // @ts-expect-error: `blacklist` is from long ago.\n  const ignore = [...(options.blacklist || []), ...(options.ignore || [])]\n  const minLength =\n    options.minLength !== null && options.minLength !== undefined\n      ? options.minLength\n      : MIN_LENGTH\n\n  if (!value || value.length < minLength) {\n    return und()\n  }\n\n  value = value.slice(0, MAX_LENGTH)\n\n  /* Get the script which characters occur the most\n   * in `value`. */\n  const script = getTopScript(value, expressions)\n\n  /* One languages exists for the most-used script. */\n  if (!script[0] || !(script[0] in numericData)) {\n    /* If no matches occured, such as a digit only string,\n     * or because the language is ignored, exit with `und`. */\n    if (!script[0] || script[1] === 0 || !allow(script[0], only, ignore)) {\n      return und()\n    }\n\n    return singleLanguageTuples(script[0])\n  }\n\n  /* Get all distances for a given script, and\n   * normalize the distance values. */\n  return normalize(\n    value,\n    getDistances(asTuples(value), numericData[script[0]], only, ignore)\n  )\n}\n\n/**\n * Normalize the difference for each tuple in\n * `distances`.\n *\n * @param {string} value\n *   Value to normalize.\n * @param {Array<TrigramTuple>} distances\n *   List of distances.\n * @return {Array<TrigramTuple>}\n *   Normalized distances.\n */\nfunction normalize(value, distances) {\n  const min = distances[0][1]\n  const max = value.length * MAX_DIFFERENCE - min\n  let index = -1\n\n  while (++index < distances.length) {\n    distances[index][1] = 1 - (distances[index][1] - min) / max || 0\n  }\n\n  return distances\n}\n\n/**\n * From `scripts`, get the most occurring expression for\n * `value`.\n *\n * @param {string} value\n *   Value to check.\n * @param {Record<string, RegExp>} scripts\n *   Top-Scripts.\n * @return {[string|undefined, number]}\n *   Top script and its occurrence percentage.\n */\nfunction getTopScript(value, scripts) {\n  let topCount = -1\n  /** @type {string|undefined} */\n  let topScript\n  /** @type {string} */\n  let script\n\n  for (script in scripts) {\n    if (own.call(scripts, script)) {\n      const count = getOccurrence(value, scripts[script])\n\n      if (count > topCount) {\n        topCount = count\n        topScript = script\n      }\n    }\n  }\n\n  return [topScript, topCount]\n}\n\n/**\n * Get the occurrence ratio of `expression` for `value`.\n *\n * @param {string} value\n *   Value to check.\n * @param {RegExp} expression\n *   Code-point expression.\n * @return {number}\n *   Float between 0 and 1.\n */\nfunction getOccurrence(value, expression) {\n  const count = value.match(expression)\n\n  return (count ? count.length : 0) / value.length || 0\n}\n\n/**\n * Get the distance between an array of trigram—count\n * tuples, and multiple trigram dictionaries.\n *\n * @param {Array<TrigramTuple>} trigrams\n *   An array containing trigram—count tuples.\n * @param {Record<string, Record<string, number>>} languages\n *   Multiple trigrams to test against.\n * @param {Array<string>} only\n *   Allowed languages; if non-empty, only included languages are kept.\n * @param {Array<string>} ignore\n *   Disallowed languages; included languages are ignored.\n * @return {Array<TrigramTuple>} An array\n *   containing language—distance tuples.\n */\nfunction getDistances(trigrams, languages, only, ignore) {\n  languages = filterLanguages(languages, only, ignore)\n\n  /** @type {Array<TrigramTuple>} */\n  const distances = []\n  /** @type {string} */\n  let language\n\n  if (languages) {\n    for (language in languages) {\n      if (own.call(languages, language)) {\n        distances.push([language, getDistance(trigrams, languages[language])])\n      }\n    }\n  }\n\n  return distances.length === 0 ? und() : distances.sort(sort)\n}\n\n/**\n * Get the distance between an array of trigram—count\n * tuples, and a language dictionary.\n *\n * @param {Array<TrigramTuple>} trigrams\n *   An array containing trigram—count tuples.\n * @param {Record<string, number>} model\n *   Object containing weighted trigrams.\n * @return {number}\n *   The distance between the two.\n */\nfunction getDistance(trigrams, model) {\n  let distance = 0\n  let index = -1\n\n  while (++index < trigrams.length) {\n    const trigram = trigrams[index]\n    let difference = MAX_DIFFERENCE\n\n    if (trigram[0] in model) {\n      difference = trigram[1] - model[trigram[0]] - 1\n\n      if (difference < 0) {\n        difference = -difference\n      }\n    }\n\n    distance += difference\n  }\n\n  return distance\n}\n\n/**\n * Filter `languages` by removing languages in\n * `ignore`, or including languages in `only`.\n *\n * @param {Record<string, Record<string, number>>} languages\n *   Languages to filter\n * @param {Array<string>} only\n *   Allowed languages; if non-empty, only included languages are kept.\n * @param {Array<string>} ignore\n *   Disallowed languages; included languages are ignored.\n * @return {Record<string, Record<string, number>>}\n *   Filtered array of languages.\n */\nfunction filterLanguages(languages, only, ignore) {\n  if (only.length === 0 && ignore.length === 0) {\n    return languages\n  }\n\n  /** @type {Record<string, Record<string, number>>} */\n  const filteredLanguages = {}\n  /** @type {string} */\n  let language\n\n  for (language in languages) {\n    if (allow(language, only, ignore)) {\n      filteredLanguages[language] = languages[language]\n    }\n  }\n\n  return filteredLanguages\n}\n\n/**\n * Check if `language` can match according to settings.\n *\n * @param {string} language\n *   Languages to filter\n * @param {Array<string>} only\n *   Allowed languages; if non-empty, only included languages are kept.\n * @param {Array<string>} ignore\n *   Disallowed languages; included languages are ignored.\n * @return {boolean}\n *   Whether `language` can match\n */\nfunction allow(language, only, ignore) {\n  if (only.length === 0 && ignore.length === 0) {\n    return true\n  }\n\n  return (\n    (only.length === 0 || only.includes(language)) && !ignore.includes(language)\n  )\n}\n\n/**\n * Create a single `und` tuple.\n */\nfunction und() {\n  return singleLanguageTuples('und')\n}\n\n/**\n * Create a single tuple as a list of tuples from a given language code.\n *\n * @param {string} language\n * @returns {Array<TrigramTuple>}\n */\nfunction singleLanguageTuples(language) {\n  return [[language, 1]]\n}\n\n/**\n * Deep regular sort on the number at `1` in both objects.\n *\n * @param {TrigramTuple} a\n * @param {TrigramTuple} b\n */\nfunction sort(a, b) {\n  return a[1] - b[1]\n}\n"]}