issues-95 get saving and forking to work

This commit is contained in:
Kurt Hutten
2020-11-14 19:44:40 +11:00
parent 7abdd87f03
commit 955f4c9e83
7 changed files with 82 additions and 24 deletions

View File

@@ -14,3 +14,17 @@ export const foreignKeyReplacement = (input) => {
export const enforceAlphaNumeric = (string) =>
string.replace(/([^a-zA-Z\d_:])/g, '-')
export const generateUniqueString = async (
seed,
isUniqueCallback,
count = 0
) => {
const isUnique = !(await isUniqueCallback(seed))
if (isUnique) {
return seed
}
count += 1
const newSeed = count === 1 ? `${seed}_${count}` : seed.slice(0, -1) + count
return generateUniqueString(newSeed, isUniqueCallback, count)
}