ice.fo.utils
Version:
22 lines (20 loc) • 605 B
JavaScript
/**
* Generate a random ID for use. Note: Only use this for temporary data or display. It should not be used for API and the algorithm may be changed any time.
*/
export function randomId () {
return randomObjectId()
}
/**
* Return a random objectId format
*
* @example
* randomObjectId(); // return 62a971ae250deead422f3f3e
*
* @returns string
*/
export function randomObjectId () {
const timestamp = (new Date().getTime() / 1000 | 0).toString(16)
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function () {
return (Math.random() * 16 | 0).toString(16)
}).toLowerCase()
}