Created
August 16, 2021 09:56
-
-
Save hardboiled/aef8f260c191fbb3a5f6b25b71838b19 to your computer and use it in GitHub Desktop.
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
/** | |
* Convenience method for creating not rigorously random uuids to help with testing staging and development APIs | |
* Definition based off this answer: https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid#answer-105074 | |
*/ | |
function createFakeUuid () { | |
return 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx'.split('').map(x => { | |
const chars = '0123456789abcdef'; | |
const seed = Math.random(); | |
switch (x) { | |
case 'M': | |
return chars[Math.round(seed * 5 + 1)]; | |
case 'N': | |
return chars[Math.round(seed * 2 + 8)]; | |
case '-': | |
return x; | |
default: | |
return chars[Math.round(seed * 16)]; | |
} | |
}).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment