Convert and fix tests

This commit is contained in:
Adria Navarro 2025-01-14 11:35:43 +01:00
parent 06013929e4
commit 35d5e51898
2 changed files with 7 additions and 7 deletions

View File

@ -70,18 +70,18 @@ export const duplicateName = (name: string, allNames: string[]) => {
* @param getName optional function to extract the name for an item, if not a * @param getName optional function to extract the name for an item, if not a
* flat array of strings * flat array of strings
*/ */
export const getSequentialName = <T extends string | object>( export const getSequentialName = <T extends any>(
items: T[], items: T[] | null,
prefix: string, prefix: string | null,
{ {
getName, getName,
numberFirstItem, numberFirstItem,
}: { }: {
getName: (item: T) => string getName?: (item: T) => string
numberFirstItem?: boolean numberFirstItem?: boolean
} } = {}
) => { ) => {
if (!prefix?.length || !getName) { if (!prefix?.length) {
return null return null
} }
const trimmedPrefix = prefix.trim() const trimmedPrefix = prefix.trim()
@ -91,7 +91,7 @@ export const getSequentialName = <T extends string | object>(
} }
let max = 0 let max = 0
items.forEach(item => { items.forEach(item => {
const name = getName(item) const name = getName?.(item) ?? item
if (typeof name !== "string" || !name.startsWith(trimmedPrefix)) { if (typeof name !== "string" || !name.startsWith(trimmedPrefix)) {
return return
} }