/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/assets/utils/createStringVariations.ts
56 строк
1 KB
Zyie
chore: documentation overhaul with typedoc (#11423)
19 май 2025, 11:44
Не верифицирован
19 май 2025, 11:44
34926f0
Код
Авторство
О чём код?
function processX(base: string, ids: string[][], depth: number, result: string[], tags: string[]) { const id = ids[depth]; for (let i = 0; i < id.length; i++) { const value = id[i]; if (depth < ids.length - 1) { processX(base.replace(result[depth], value), ids, depth + 1, result, tags); } else { tags.push(base.replace(result[depth], value)); } } } /** * Creates a list of all possible combinations of the given strings. * @example * const out2 = createStringVariations('name is {chicken,wolf,sheep}'); * console.log(out2); // [ 'name is chicken', 'name is wolf', 'name is sheep' ] * @param string - The string to process * @internal */ export function createStringVariations(string: string): string[] { const regex = /\{(.*?)\}/g; const result = string.match(regex); const tags: string[] = []; if (result) { const ids: string[][] = []; result.forEach((vars) => { // first remove the brackets... const split = vars.substring(1, vars.length - 1).split(','); ids.push(split); }); processX(string, ids, 0, result, tags); } else { tags.push(string); } return tags; }