优化uuid
parent
c21a72a9a2
commit
24d5287baf
14
index.js
14
index.js
|
@ -7,7 +7,8 @@
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const Helper = require('./lib/helper.js')
|
const Helper = require('./lib/helper.js')
|
||||||
|
|
||||||
var __stamp__ = ''
|
const PID = process.pid
|
||||||
|
const PPID = process.ppid
|
||||||
var __inc__ = 1024
|
var __inc__ = 1024
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,17 +76,14 @@ Helper.uuid = function(pipe = '-') {
|
||||||
var now = (~~(Date.now() / 1000)).toString(16)
|
var now = (~~(Date.now() / 1000)).toString(16)
|
||||||
var inc
|
var inc
|
||||||
|
|
||||||
if (__stamp__ === now) {
|
|
||||||
__inc__++
|
__inc__++
|
||||||
} else {
|
if (__inc__ > 65535) {
|
||||||
__stamp__ = now
|
|
||||||
__inc__ = 1024
|
__inc__ = 1024
|
||||||
}
|
}
|
||||||
inc = __inc__.toString(16).padStart(4, '0')
|
|
||||||
|
|
||||||
return (
|
inc = (__inc__ + PID + PPID).toString(16).padStart(4, '0')
|
||||||
__stamp__ + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8)
|
|
||||||
)
|
return now + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
14
index.mjs
14
index.mjs
|
@ -7,7 +7,8 @@
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import Helper from './lib/helper.mjs'
|
import Helper from './lib/helper.mjs'
|
||||||
|
|
||||||
var __stamp__ = ''
|
const PID = process.pid
|
||||||
|
const PPID = process.ppid
|
||||||
var __inc__ = 1024
|
var __inc__ = 1024
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,17 +76,14 @@ export function uuid(pipe = '-') {
|
||||||
var now = (~~(Date.now() / 1000)).toString(16)
|
var now = (~~(Date.now() / 1000)).toString(16)
|
||||||
var inc
|
var inc
|
||||||
|
|
||||||
if (__stamp__ === now) {
|
|
||||||
__inc__++
|
__inc__++
|
||||||
} else {
|
if (__inc__ > 65535) {
|
||||||
__stamp__ = now
|
|
||||||
__inc__ = 1024
|
__inc__ = 1024
|
||||||
}
|
}
|
||||||
inc = __inc__.toString(16).padStart(4, '0')
|
|
||||||
|
|
||||||
return (
|
inc = (__inc__ + PID + PPID).toString(16).padStart(4, '0')
|
||||||
__stamp__ + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8)
|
|
||||||
)
|
return now + pipe + inc + pipe + rand.slice(0, 4) + pipe + rand.slice(-8)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "crypto.js",
|
"name": "crypto.js",
|
||||||
"version": "2.0.2",
|
"version": "2.0.3",
|
||||||
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"md5",
|
"md5",
|
||||||
|
|
Loading…
Reference in New Issue