多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
794 B

export const generateUniqueName = async () => {
const { adjectives, animals, starWars, uniqueNamesGenerator } = await import('unique-names-generator')
return uniqueNamesGenerator({
dictionaries: [[starWars], [adjectives, animals]][Math.floor(Math.random() * 2)],
})
.toLowerCase()
.replace(/[ -]/g, '_')
}
export const generateUniqueTitle = <T extends Record<string, any> = Record<string, any>>(
title: string,
arr: T[],
predicate: keyof T,
) => {
let c = 1
while (arr.some((item) => item[predicate].includes(`${title}-${c}` as keyof T))) {
c++
}
return `${title}-${c}`
}
export const generateRandomNumber = () => {
const typedArray = new Uint8Array(10)
const randomValues = window.crypto.getRandomValues(typedArray)
return randomValues.join('')
}