Skip to content

Instantly share code, notes, and snippets.

@jwadhwani
Created June 11, 2018 17:31
Show Gist options
  • Save jwadhwani/5056c45255f23da755000331bce47f73 to your computer and use it in GitHub Desktop.
Save jwadhwani/5056c45255f23da755000331bce47f73 to your computer and use it in GitHub Desktop.
JavaScript/NodeJS equivalent of PHP's uniqid with a little extra entropy.
"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