UNPKG

vuestic-ui

Version:
1 lines 1.51 kB
{"version":3,"file":"regex.mjs","sources":["../../../../../../src/services/icon/utils/regex.ts"],"sourcesContent":["export const isMatchRegex = (str: string, regex: RegExp) => {\n return regex.test(str)\n}\n\n/**\n * Return values from regex groups\n * @example\n * ```\n * \"fa-phone-o\", /fa-(.*)-(.*)/ -> [\"phone\", \"o\"]\n * \"any string\", /(.*)/ -> [\"any string\"]\n * \"global regex test\", /global (regex) (test)/g -> [['regex', 'test']]\n * ```\n */\nexport const regexGroupsValues = (str: string, regex: RegExp | string): string[] | string[][] => {\n if (typeof regex !== 'string' && regex.global) {\n // Global regex can return multiple matches array. So we need to map this all matches and remove non group values.\n return [...str.matchAll(regex)].map(g => g.slice(1))\n }\n\n const match = str.match(regex) || []\n if (!match) { return [] }\n /**\n * If there is groups in result - we need to slice first match\n * ```\n * \"test\".match(/(s)/)\n * > Array [ \"s\", \"s\" ]\n * ```\n */\n if (match.length > 1) { return match.slice(1) }\n\n return match\n}\n"],"names":[],"mappings":"AAAa,MAAA,eAAe,CAAC,KAAa,UAAkB;AACnD,SAAA,MAAM,KAAK,GAAG;AACvB;AAWa,MAAA,oBAAoB,CAAC,KAAa,UAAkD;AAC/F,MAAI,OAAO,UAAU,YAAY,MAAM,QAAQ;AAE7C,WAAO,CAAC,GAAG,IAAI,SAAS,KAAK,CAAC,EAAE,IAAI,CAAK,MAAA,EAAE,MAAM,CAAC,CAAC;AAAA,EACrD;AAEA,QAAM,QAAQ,IAAI,MAAM,KAAK,KAAK,CAAA;AAClC,MAAI,CAAC,OAAO;AAAE,WAAO;EAAG;AAQpB,MAAA,MAAM,SAAS,GAAG;AAAS,WAAA,MAAM,MAAM,CAAC;AAAA,EAAE;AAEvC,SAAA;AACT;"}