diff --git a/index.js b/index.js index 7fa142b..1fc51ce 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,8 @@ const fs = require('fs') const Helper = require('./lib/helper.js') -var __stamp__ = '' +const PID = process.pid +const PPID = process.ppid var __inc__ = 1024 /** @@ -75,17 +76,14 @@ Helper.uuid = function(pipe = '-') { var now = (~~(Date.now() / 1000)).toString(16) var inc - if (__stamp__ === now) { - __inc__++ - } else { - __stamp__ = now + __inc__++ + if (__inc__ > 65535) { __inc__ = 1024 } - inc = __inc__.toString(16).padStart(4, '0') - return ( - __stamp__ + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8) - ) + inc = (__inc__ + PID + PPID).toString(16).padStart(4, '0') + + return now + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8) } /** diff --git a/index.mjs b/index.mjs index e593580..3072c02 100644 --- a/index.mjs +++ b/index.mjs @@ -7,7 +7,8 @@ import fs from 'fs' import Helper from './lib/helper.mjs' -var __stamp__ = '' +const PID = process.pid +const PPID = process.ppid var __inc__ = 1024 /** @@ -75,17 +76,14 @@ export function uuid(pipe = '-') { var now = (~~(Date.now() / 1000)).toString(16) var inc - if (__stamp__ === now) { - __inc__++ - } else { - __stamp__ = now + __inc__++ + if (__inc__ > 65535) { __inc__ = 1024 } - inc = __inc__.toString(16).padStart(4, '0') - return ( - __stamp__ + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8) - ) + inc = (__inc__ + PID + PPID).toString(16).padStart(4, '0') + + return now + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8) } /** diff --git a/package.json b/package.json index 1141a86..89c9d12 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypto.js", - "version": "2.0.2", + "version": "2.0.3", "description": "原生crypto加密模块的二次封装,简化常用加密函数的使用", "keywords": [ "md5",