Comparing version 0.6.1 to 0.6.2
20
index.js
@@ -50,2 +50,13 @@ // standard Node.js crypto library | ||
// calculate an 8-digit prefix for the timestamp 't' | ||
// that is base62 encoded and sorts in reverse time order | ||
// but with milliseconds | ||
const prefixReverseMs = function (t) { | ||
// get time stamp for now | ||
const timestamp = maxTS - tsms(t) | ||
// turn timestamp into 8-digit, base-62 encoded string | ||
return base62Encode(timestamp).padStart(8, '0') | ||
} | ||
const rand = function (n) { | ||
@@ -80,2 +91,7 @@ if (!n) { | ||
// generate a kuuid (reverse mode) | ||
const idmsr = function (t) { | ||
return prefixReverseMs(t) + rand() | ||
} | ||
// generate short id | ||
@@ -97,6 +113,8 @@ const ids = function (t) { | ||
idms, | ||
idmsr, | ||
rand, | ||
prefix, | ||
prefixms, | ||
prefixReverse | ||
prefixReverse, | ||
prefixReverseMs | ||
} |
{ | ||
"name": "kuuid", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "K-sortable UUID - roughly time-sortable unique id generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,5 +83,11 @@ # kuuid | ||
kuuid.idms() | ||
// 0RW2yGC21miE8r3oeOun2pGeIp0EoQNu | ||
// 0T6vppV82RX4Nx1ZzGqB0Exjjs4fkuhh | ||
``` | ||
```js | ||
// 'now' reverse | ||
kuuid.idmsr() | ||
// zWt4A9Wz3TxK0h4MRkec06xADk3kIemn | ||
``` | ||
## Short ids | ||
@@ -128,2 +134,8 @@ | ||
or for a millisecond-precision reversed version: | ||
```js | ||
kuuid.prefixReverseMs() | ||
``` | ||
## How does it work? | ||
@@ -130,0 +142,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23211
203
159