@edgenets/utils 0.3.7 → 0.3.8
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.
@@ -1,7 +1,7 @@
|
|
1
1
|
import crypto from "crypto";
|
2
|
-
export class
|
2
|
+
export class NanoIdUtil {
|
3
3
|
static DEFAULT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
4
|
-
static generate(length, chars =
|
4
|
+
static generate(length, chars = NanoIdUtil.DEFAULT_CHARS) {
|
5
5
|
if (length <= 0) {
|
6
6
|
throw new Error("Length must be greater than 0");
|
7
7
|
}
|
@@ -13,10 +13,10 @@ export class NanoidUtil {
|
|
13
13
|
return result.join("");
|
14
14
|
}
|
15
15
|
static generateDefault(length) {
|
16
|
-
return
|
16
|
+
return NanoIdUtil.generate(length);
|
17
17
|
}
|
18
18
|
static generateCustom(length, customChars) {
|
19
|
-
return
|
19
|
+
return NanoIdUtil.generate(length, customChars);
|
20
20
|
}
|
21
21
|
static generateNumberId(length = 8) {
|
22
22
|
const now = new Date();
|
@@ -25,7 +25,7 @@ export class NanoidUtil {
|
|
25
25
|
const dayPart = dayCount.toString().slice(-4).padStart(4, "0");
|
26
26
|
const minutesOfDay = now.getHours() * 60 + now.getMinutes();
|
27
27
|
const minutePart = minutesOfDay.toString().padStart(4, "0");
|
28
|
-
const randomPart =
|
28
|
+
const randomPart = NanoIdUtil.generate(length, "0123456789");
|
29
29
|
return Number(`${dayPart}${minutePart}${randomPart}`);
|
30
30
|
}
|
31
31
|
}
|