uuidv1
Version:
‘uuidv1’ simply generates UUID v1 (with timestamp). Works in both Node.js and the browser. Lightweight. No dependencies.
25 lines (20 loc) • 714 B
JavaScript
/* ISC (c) 2018+ Jackens * https://github.com/jackens/uuidv1 */
(function (K, W) {
function P (str, length) {
return ('0000000000000000' + str).slice(-length)
}
function R () {
return P((~~(Math.random() * 0x1000)).toString(16), 3)
}
function $ () {
var now = new Date()
var time = P((10000 * (+new Date(now.getTime() - now.getTimezoneOffset() * 60000) + 12219292800000)).toString(16), 16)
return time.slice(8, 16) + '-' + time.slice(4, 8) + '-1' + time.slice(1, 4) + '-8' + R() + '-' + R() + R() + R() + R()
}
try {
(W = window).require = function (I) { return W[K][I] };
(W[K] = W[K] || {}).uuidv1 = $
} catch (_) {
module.exports = $
}
})('module.exports')