Skip to content

Instantly share code, notes, and snippets.

@hardboiled
Created August 16, 2021 09:56
Show Gist options
  • Save hardboiled/aef8f260c191fbb3a5f6b25b71838b19 to your computer and use it in GitHub Desktop.
Save hardboiled/aef8f260c191fbb3a5f6b25b71838b19 to your computer and use it in GitHub Desktop.
/**
* 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