Tofu/scripts/import-recipes/recipes/makeUniqueRecipeId.js
2026-09-18 01:41:02 +02:00

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}`
}