Type duplicates

This commit is contained in:
Adria Navarro 2025-01-13 14:13:20 +01:00
parent b3d18b16cf
commit 8f282d54d2
1 changed files with 5 additions and 5 deletions

View File

@ -10,13 +10,13 @@
* *
* Repl * Repl
*/ */
export const duplicateName = (name, allNames) => { export const duplicateName = (name: string, allNames: string[]) => {
const duplicatePattern = new RegExp(`\\s(\\d+)$`) const duplicatePattern = new RegExp(`\\s(\\d+)$`)
const baseName = name.split(duplicatePattern)[0] const baseName = name.split(duplicatePattern)[0]
const isDuplicate = new RegExp(`${baseName}\\s(\\d+)$`) const isDuplicate = new RegExp(`${baseName}\\s(\\d+)$`)
// get the sequence from matched names // get the sequence from matched names
const sequence = [] const sequence: number[] = []
allNames.filter(n => { allNames.filter(n => {
if (n === baseName) { if (n === baseName) {
return true return true
@ -71,9 +71,9 @@ export const duplicateName = (name, allNames) => {
* flat array of strings * flat array of strings
*/ */
export const getSequentialName = ( export const getSequentialName = (
items, items: string[],
prefix, prefix: string,
{ getName = x => x, numberFirstItem = false } = {} { getName = (x: string) => x, numberFirstItem = false } = {}
) => { ) => {
if (!prefix?.length || !getName) { if (!prefix?.length || !getName) {
return null return null