-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): use unique temp dir per invocation
Fixes #183
- Loading branch information
1 parent
d865434
commit 5fac801
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Cheaply generate a UUID with a low chance of collisions | ||
* https://stackoverflow.com/a/8809472/745158 | ||
*/ | ||
export function uuid(): string { | ||
let epoch: number = new Date().getTime(); | ||
let sessionLength: number = Date.now() * 1000 || 0; | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (character) => { | ||
let randomNumber: number = Math.random() * 16; | ||
if (epoch > 0) { | ||
randomNumber = (epoch + randomNumber) % 16 | 0; | ||
epoch = Math.floor(epoch / 16); | ||
} else { | ||
randomNumber = (sessionLength + randomNumber) % 16 | 0; | ||
sessionLength = Math.floor(sessionLength / 16); | ||
} | ||
return (character == 'x' ? randomNumber : (randomNumber & 0x7) | 0x8).toString(16); | ||
}); | ||
} |