{"version":3,"file":"getEnumeration.mjs","names":[],"sources":["../../../src/interpreter/getEnumeration.ts"],"sourcesContent":["import type { EnterFormat, EnumerationContentState } from '../transpiler';\n\n/**\n * Find the matching condition for a quantity.\n *\n * Usage:\n *\n * ```ts\n * const key = findMatchingCondition({\n *  '<=-2.3': 'You have less than -2.3',\n *  '<1': 'You have less than one',\n *  '2': 'You have two',\n *  '>=3': 'You have three or more',\n * }, 2);\n * // '2'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const key = findMatchingCondition({\n *  '<4': 'You have less than four',\n *  '2': 'You have two',\n * }, 2);\n * // '<4'\n * ```\n *\n * If no keys match, the default key is '1'.\n */\nexport const findMatchingCondition = <const Content>(\n  enumerationContent: EnumerationContentState<Content>,\n  quantity: number\n): EnterFormat | undefined => {\n  const numericKeys = Object.keys(enumerationContent);\n\n  for (const key of numericKeys) {\n    const isEqual =\n      (!key.startsWith('>') &&\n        !key.startsWith('<') &&\n        !key.startsWith('=') &&\n        parseFloat(key) === quantity) ||\n      (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);\n    const isSuperior =\n      key.startsWith('>') && quantity > parseFloat(key.slice(1));\n    const isSuperiorOrEqual =\n      key.startsWith('>=') && quantity >= parseFloat(key.slice(2));\n    const isInferior =\n      key.startsWith('<') && quantity < parseFloat(key.slice(1));\n    const isInferiorOrEqual =\n      key.startsWith('<=') && quantity <= parseFloat(key.slice(2));\n\n    if (\n      isEqual ||\n      isSuperior ||\n      isSuperiorOrEqual ||\n      isInferior ||\n      isInferiorOrEqual\n    ) {\n      return key as EnterFormat;\n    }\n  }\n};\n\n/**\n * Picks content from an enumeration map based on a provided quantity.\n *\n * Supported keys in the enumeration map:\n * - Specific numbers: '0', '1', '2'\n * - Comparison operators: '<5', '>=10', '<=2'\n * - Fallback: 'fallback'\n *\n * The first matching key in the object's iteration order will be selected.\n *\n * @param enumerationContent - A map of conditions/quantities to content.\n * @param quantity - The number to match against the conditions.\n * @returns The matching content.\n *\n * @example\n * ```ts\n * const content = getEnumeration({\n *   '0': 'No items',\n *   '1': 'One item',\n *   '>1': 'Many items',\n * }, 5);\n * // 'Many items'\n * ```\n */\nexport const getEnumeration = <const Content>(\n  enumerationContent: EnumerationContentState<Content>,\n  quantity: number\n): Content => {\n  const key =\n    findMatchingCondition<Content>(enumerationContent, quantity) ?? 'fallback';\n\n  // Default or error handling if no keys match\n  return enumerationContent[key] as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,yBACX,oBACA,aAC4B;CAC5B,MAAM,cAAc,OAAO,KAAK,mBAAmB;AAEnD,MAAK,MAAM,OAAO,aAAa;EAC7B,MAAM,UACH,CAAC,IAAI,WAAW,IAAI,IACnB,CAAC,IAAI,WAAW,IAAI,IACpB,CAAC,IAAI,WAAW,IAAI,IACpB,WAAW,IAAI,KAAK,YACrB,IAAI,WAAW,IAAI,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC,KAAK;EACvD,MAAM,aACJ,IAAI,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI,MAAM,EAAE,CAAC;EAC5D,MAAM,oBACJ,IAAI,WAAW,KAAK,IAAI,YAAY,WAAW,IAAI,MAAM,EAAE,CAAC;EAC9D,MAAM,aACJ,IAAI,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI,MAAM,EAAE,CAAC;EAC5D,MAAM,oBACJ,IAAI,WAAW,KAAK,IAAI,YAAY,WAAW,IAAI,MAAM,EAAE,CAAC;AAE9D,MACE,WACA,cACA,qBACA,cACA,kBAEA,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Bb,MAAa,kBACX,oBACA,aACY;AAKZ,QAAO,mBAHL,sBAA+B,oBAAoB,SAAS,IAAI"}