From 24d5287bafd20d4fc53b0e05d18559c148f0570c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Wed, 23 Jun 2021 17:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 16 +++++++--------- index.mjs | 16 +++++++--------- package.json | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) 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",