9 lines
360 B
JavaScript
9 lines
360 B
JavaScript
// Two documents can legitimately carry the same title. The second one gets a
|
|
// numbered id rather than silently overwriting the first one's file.
|
|
export function makeUniqueRecipeId(id, usedIds) {
|
|
const taken = new Set(usedIds)
|
|
if (!taken.has(id)) return id
|
|
let suffix = 2
|
|
while (taken.has(`${id}-${suffix}`)) suffix += 1
|
|
return `${id}-${suffix}`
|
|
}
|