/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/editor/src/lib/utils/getIncrementedName.ts
22 строки
530 B
Steve Ruiz
refactor(editor): clean up editor utility files (#7940)
15 фев 2026, 12:14
Не верифицирован
15 фев 2026, 12:14
1f0521a
Код
Авторство
О чём код?
/** * Get an incremented name (e.g. New page (2)) from a name (e.g. New page), based on an array of * existing names. * * @param name - The name to increment. * @param others - The array of existing names. * @public */ export function getIncrementedName(name: string, others: string[]) { let result = name const set = new Set(others) while (set.has(result)) { result = /^.*(\d+)$/.exec(result)?.[1] ? result.replace(/(\d+)$/, (m) => { return (+m + 1).toString() }) : `${result} 1` } return result }