{"version":3,"file":"matchOption.mjs","names":[],"sources":["../../src/tools/matchOption.ts"],"sourcesContent":["import { getType } from '@openobserve/js-core/util'\nimport { display } from './display'\n\nexport type MatchOption = string | RegExp | ((value: string) => boolean)\n\nexport function isMatchOption(item: unknown): item is MatchOption {\n  const itemType = getType(item)\n  return itemType === 'string' || itemType === 'function' || item instanceof RegExp\n}\n\n/**\n * Returns true if value can be matched by at least one of the provided MatchOptions.\n * When comparing strings, setting useStartsWith to true will compare the value with the start of\n * the option, instead of requiring an exact match.\n */\nexport function matchList(list: MatchOption[], value: string, useStartsWith = false): boolean {\n  return list.some((item) => {\n    try {\n      if (typeof item === 'function') {\n        return item(value)\n      } else if (item instanceof RegExp) {\n        // Prevent stateful matching\n        item.lastIndex = 0\n        return item.test(value)\n      } else if (typeof item === 'string') {\n        return useStartsWith ? value.startsWith(item) : item === value\n      }\n    } catch (e) {\n      display.error(e)\n    }\n    return false\n  })\n}\n"],"mappings":";;;AAKA,SAAgB,cAAc,MAAoC;CAChE,MAAM,WAAW,QAAQ,IAAI;CAC7B,OAAO,aAAa,YAAY,aAAa,cAAc,gBAAgB;AAC7E;;;;;;AAOA,SAAgB,UAAU,MAAqB,OAAe,gBAAgB,OAAgB;CAC5F,OAAO,KAAK,MAAM,SAAS;EACzB,IAAI;GACF,IAAI,OAAO,SAAS,YAClB,OAAO,KAAK,KAAK;QACZ,IAAI,gBAAgB,QAAQ;IAEjC,KAAK,YAAY;IACjB,OAAO,KAAK,KAAK,KAAK;GACxB,OAAO,IAAI,OAAO,SAAS,UACzB,OAAO,gBAAgB,MAAM,WAAW,IAAI,IAAI,SAAS;EAE7D,SAAS,GAAG;GACV,QAAQ,MAAM,CAAC;EACjB;EACA,OAAO;CACT,CAAC;AACH"}