Created
June 11, 2018 17:31
-
-
Save jwadhwani/5056c45255f23da755000331bce47f73 to your computer and use it in GitHub Desktop.
JavaScript/NodeJS equivalent of PHP's uniqid with a little extra entropy.
This file contains hidden or 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
"use strict"; | |
const crypto = require('crypto'), | |
hash = crypto.createHash('md5'); | |
const uniqid = (prefix = '') => { | |
return `${prefix}${hash.update(Date.now().toString()).digest('hex')}`; | |
}; | |
console.log(uniqid('Example_Prefix-')); //Example_Prefix-d6caf083d4676ec0f2cf2a9a3b2b3020 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment