@live-change/uid 0.1.2 → 0.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -3
- package/package.json +2 -3
package/index.js
CHANGED
|
@@ -69,7 +69,7 @@ function hashCode(str) {
|
|
|
69
69
|
return Math.abs(hash)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function uidGenerator(fingerprint = randomString(4), numberLength = 0) {
|
|
72
|
+
function uidGenerator(fingerprint = randomString(4), numberLength = 0, borders = '{}') {
|
|
73
73
|
let lastMillisecond = Date.now(), lastId = 0
|
|
74
74
|
function next() {
|
|
75
75
|
const date = new Date()
|
|
@@ -80,7 +80,8 @@ function uidGenerator(fingerprint = randomString(4), numberLength = 0) {
|
|
|
80
80
|
lastId = 0
|
|
81
81
|
lastMillisecond = now
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
const idPart = encodeNumber(lastId).padStart(numberLength, '0')
|
|
84
|
+
return borders[0] + encodeDate(date) + '.' + idPart + '@' + fingerprint + borders[1]
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
return next
|
|
@@ -102,7 +103,7 @@ function verifyUidSource(uid, source) {
|
|
|
102
103
|
|
|
103
104
|
module.exports = {
|
|
104
105
|
encodeDate,
|
|
105
|
-
|
|
106
|
+
decodeDate,
|
|
106
107
|
encodeNumber,
|
|
107
108
|
hashCode,
|
|
108
109
|
randomString,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/uid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.19",
|
|
4
4
|
"description": "Simple unique id generator with timestamp and source",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,6 +20,5 @@
|
|
|
20
20
|
"url": "https://github.com/live-change/uid/issues"
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/uid",
|
|
23
|
-
"
|
|
24
|
-
"dependencies": {}
|
|
23
|
+
"gitHead": "2c25ed68487762fe4ca36208b708ac7aa7506852"
|
|
25
24
|
}
|