Convert and fix tests
This commit is contained in:
parent
06013929e4
commit
35d5e51898
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue