tus-js-client-stall-detection
Version:
A pure JavaScript client for the tus resumable upload protocol (fork with stall detection)
20 lines (19 loc) • 739 B
text/typescript
/**
* Generate a UUID v4 based on random numbers. We intentioanlly use the less
* secure Math.random function here since the more secure crypto.getRandomNumbers
* is not available on all platforms.
* This is not a problem for us since we use the UUID only for generating a
* request ID, so we can correlate server logs to client errors.
*
* This function is taken from following site:
* https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
*
* @return {string} The generate UUID
*/
export function uuid(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0
const v = c === 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}