@stryke/unique-id 0.3.20 → 0.3.28
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/CHANGELOG.md +289 -0
- package/README.md +18 -10
- package/dist/cuid-BuvbHUZ8.cjs +1 -0
- package/dist/cuid-CcPQdiR_.mjs +2 -0
- package/dist/cuid-CcPQdiR_.mjs.map +1 -0
- package/dist/cuid-DT9rtBzf.d.mts +20 -0
- package/dist/cuid-DT9rtBzf.d.mts.map +1 -0
- package/dist/cuid-gUcp5l6X.d.cts +20 -0
- package/dist/cuid-gUcp5l6X.d.cts.map +1 -0
- package/dist/cuid.cjs +1 -30
- package/dist/cuid.d.cts +2 -0
- package/dist/cuid.d.mts +2 -0
- package/dist/cuid.mjs +1 -1
- package/dist/index.cjs +1 -60
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +1 -1
- package/dist/nanoid-client-DxgQ8Vt2.cjs +1 -0
- package/dist/nanoid-client-bEHxSBYB.mjs +2 -0
- package/dist/nanoid-client-bEHxSBYB.mjs.map +1 -0
- package/dist/{nanoid-client.d.ts → nanoid-client-mNAgNxsW.d.cts} +5 -1
- package/dist/nanoid-client-mNAgNxsW.d.cts.map +1 -0
- package/dist/nanoid-client-nC1JFvZD.d.mts +11 -0
- package/dist/nanoid-client-nC1JFvZD.d.mts.map +1 -0
- package/dist/nanoid-client.cjs +1 -10
- package/dist/nanoid-client.d.cts +2 -0
- package/dist/nanoid-client.d.mts +2 -0
- package/dist/nanoid-client.mjs +1 -1
- package/dist/{random.d.ts → random-Bd2-oY2n.d.cts} +8 -4
- package/dist/random-Bd2-oY2n.d.cts.map +1 -0
- package/dist/random-C4CrqJsp.cjs +1 -0
- package/dist/random-DTxCCJYh.d.mts +33 -0
- package/dist/random-DTxCCJYh.d.mts.map +1 -0
- package/dist/random-kTN0s0Jy.mjs +2 -0
- package/dist/random-kTN0s0Jy.mjs.map +1 -0
- package/dist/random.cjs +1 -28
- package/dist/random.d.cts +2 -0
- package/dist/random.d.mts +2 -0
- package/dist/random.mjs +1 -1
- package/dist/snowflake-B6ivA7bE.d.mts +102 -0
- package/dist/snowflake-B6ivA7bE.d.mts.map +1 -0
- package/dist/snowflake-BtoDXB99.mjs +2 -0
- package/dist/snowflake-BtoDXB99.mjs.map +1 -0
- package/dist/snowflake-CLDXd54w.cjs +1 -0
- package/dist/snowflake-DQmoRlnq.d.cts +102 -0
- package/dist/snowflake-DQmoRlnq.d.cts.map +1 -0
- package/dist/snowflake.cjs +1 -47
- package/dist/snowflake.d.cts +2 -0
- package/dist/snowflake.d.mts +2 -0
- package/dist/snowflake.mjs +1 -1
- package/dist/uuid-BnD3hGTH.cjs +1 -0
- package/dist/{uuid.d.ts → uuid-ByPTbUGJ.d.mts} +5 -1
- package/dist/uuid-ByPTbUGJ.d.mts.map +1 -0
- package/dist/uuid-DCE9JeUQ.d.cts +22 -0
- package/dist/uuid-DCE9JeUQ.d.cts.map +1 -0
- package/dist/uuid-DSMliG_W.mjs +2 -0
- package/dist/uuid-DSMliG_W.mjs.map +1 -0
- package/dist/uuid.cjs +1 -23
- package/dist/uuid.d.cts +2 -0
- package/dist/uuid.d.mts +2 -0
- package/dist/uuid.mjs +1 -1
- package/package.json +19 -115
- package/dist/cuid.d.ts +0 -16
- package/dist/index.d.ts +0 -13
- package/dist/snowflake.d.ts +0 -98
package/dist/nanoid-client.cjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.nanoid = nanoid;
|
|
7
|
-
var _random = require("./random.cjs");
|
|
8
|
-
function nanoid(o = 21) {
|
|
9
|
-
return (0, _random.getNonCryptoRandomValues)(new Uint8Array(o)).reduce((n, r) => (r &= 63, r < 36 ? n += r.toString(36) : r < 62 ? n += (r - 26).toString(36).toUpperCase() : r > 62 ? n += "-" : n += "_", n), "");
|
|
10
|
-
}
|
|
1
|
+
require(`./random-C4CrqJsp.cjs`);const e=require(`./nanoid-client-DxgQ8Vt2.cjs`);exports.nanoid=e.t;
|
package/dist/nanoid-client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import"./random-kTN0s0Jy.mjs";import{t as e}from"./nanoid-client-bEHxSBYB.mjs";export{e as nanoid};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/random.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Generate a random integer
|
|
3
4
|
*
|
|
@@ -5,25 +6,28 @@
|
|
|
5
6
|
* @param minimum - The minimum value (inclusive)
|
|
6
7
|
* @returns A random integer
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare const randomInteger: (maximum: number, minimum?: number) => number;
|
|
9
10
|
/**
|
|
10
11
|
* Generate a random letter
|
|
11
12
|
*
|
|
12
13
|
* @param random - The random number generator
|
|
13
14
|
* @returns A random letter
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
declare const randomLetter: (random?: () => number) => string | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* Generate a random string
|
|
18
19
|
*
|
|
19
20
|
* @param array - The array to fill with random values
|
|
20
21
|
* @returns The array filled with random values
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
declare function getNonCryptoRandomValues(array: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
23
24
|
/**
|
|
24
25
|
* Generate a series of random characters
|
|
25
26
|
*
|
|
26
27
|
* @param length - The length of the random characters
|
|
27
28
|
* @returns A series of random characters
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
declare function randomCharacters(length: number): string;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { randomLetter as i, randomCharacters as n, randomInteger as r, getNonCryptoRandomValues as t };
|
|
33
|
+
//# sourceMappingURL=random-Bd2-oY2n.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-Bd2-oY2n.d.cts","names":[],"sources":["../src/random.ts"],"sourcesContent":[],"mappings":";;AA6BA;AASA;AASA;;;;AAA0D,cAlB7C,aAkB6C,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAmB1D;;;;;;cA5Ba;;;;;;;iBASG,wBAAA,QAAgC,aAAU,WAAA;;;;;;;iBAmB1C,gBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Array.from({length:26},(e,t)=>String.fromCodePoint(t+97)),t=(e,t=0)=>Math.floor(Math.random()*(e-t+1)+t),n=(t=Math.random)=>e[Math.floor(t()*e.length)];function r(e){if(e===null)throw TypeError(`array cannot be null`);for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return e}function i(e){let t=``,n=0;for(;n<e;)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62)),n+=1;return t}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/random.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a random integer
|
|
4
|
+
*
|
|
5
|
+
* @param maximum - The maximum value (inclusive)
|
|
6
|
+
* @param minimum - The minimum value (inclusive)
|
|
7
|
+
* @returns A random integer
|
|
8
|
+
*/
|
|
9
|
+
declare const randomInteger: (maximum: number, minimum?: number) => number;
|
|
10
|
+
/**
|
|
11
|
+
* Generate a random letter
|
|
12
|
+
*
|
|
13
|
+
* @param random - The random number generator
|
|
14
|
+
* @returns A random letter
|
|
15
|
+
*/
|
|
16
|
+
declare const randomLetter: (random?: () => number) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Generate a random string
|
|
19
|
+
*
|
|
20
|
+
* @param array - The array to fill with random values
|
|
21
|
+
* @returns The array filled with random values
|
|
22
|
+
*/
|
|
23
|
+
declare function getNonCryptoRandomValues(array: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
24
|
+
/**
|
|
25
|
+
* Generate a series of random characters
|
|
26
|
+
*
|
|
27
|
+
* @param length - The length of the random characters
|
|
28
|
+
* @returns A series of random characters
|
|
29
|
+
*/
|
|
30
|
+
declare function randomCharacters(length: number): string;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { randomLetter as i, randomCharacters as n, randomInteger as r, getNonCryptoRandomValues as t };
|
|
33
|
+
//# sourceMappingURL=random-DTxCCJYh.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-DTxCCJYh.d.mts","names":[],"sources":["../src/random.ts"],"sourcesContent":[],"mappings":";;AA6BA;AASA;AASA;;;;AAA0D,cAlB7C,aAkB6C,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAmB1D;;;;;;cA5Ba;;;;;;;iBASG,wBAAA,QAAgC,aAAU,WAAA;;;;;;;iBAmB1C,gBAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=Array.from({length:26},(e,t)=>String.fromCodePoint(t+97)),t=(e,t=0)=>Math.floor(Math.random()*(e-t+1)+t),n=(t=Math.random)=>e[Math.floor(t()*e.length)];function r(e){if(e===null)throw TypeError(`array cannot be null`);for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return e}function i(e){let t=``,n=0;for(;n<e;)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62)),n+=1;return t}export{n as i,i as n,t as r,r as t};
|
|
2
|
+
//# sourceMappingURL=random-kTN0s0Jy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-kTN0s0Jy.mjs","names":[],"sources":["../src/random.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst alphabet = Array.from({ length: 26 }, (_x, i) =>\n String.fromCodePoint(i + 97)\n);\n\n/**\n * Generate a random integer\n *\n * @param maximum - The maximum value (inclusive)\n * @param minimum - The minimum value (inclusive)\n * @returns A random integer\n */\nexport const randomInteger = (maximum: number, minimum = 0) =>\n Math.floor(Math.random() * (maximum - minimum + 1) + minimum);\n\n/**\n * Generate a random letter\n *\n * @param random - The random number generator\n * @returns A random letter\n */\nexport const randomLetter = (random: () => number = Math.random) =>\n alphabet[Math.floor(random() * alphabet.length)];\n\n/**\n * Generate a random string\n *\n * @param array - The array to fill with random values\n * @returns The array filled with random values\n */\nexport function getNonCryptoRandomValues(array: Uint8Array) {\n if (array === null) {\n throw new TypeError(\"array cannot be null\");\n }\n\n // Fill the array with random values\n for (let i = 0; i < array.length; i++) {\n array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)\n }\n\n return array;\n}\n\n/**\n * Generate a series of random characters\n *\n * @param length - The length of the random characters\n * @returns A series of random characters\n */\nexport function randomCharacters(length: number) {\n let result = \"\";\n const characters =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n const charactersLength = characters.length;\n let counter = 0;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n return result;\n}\n"],"mappings":"AAkBA,MAAM,EAAW,MAAM,KAAK,CAAE,OAAQ,GAAI,EAAG,EAAI,IAC/C,OAAO,cAAc,EAAI,GAAG,CAC7B,CASY,GAAiB,EAAiB,EAAU,IACvD,KAAK,MAAM,KAAK,QAAQ,EAAI,EAAU,EAAU,GAAK,EAAQ,CAQlD,GAAgB,EAAuB,KAAK,SACvD,EAAS,KAAK,MAAM,GAAQ,CAAG,EAAS,OAAO,EAQjD,SAAgB,EAAyB,EAAmB,CAC1D,GAAI,IAAU,KACZ,MAAU,UAAU,uBAAuB,CAI7C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,EAAM,GAAK,KAAK,MAAM,KAAK,QAAQ,CAAG,IAAI,CAG5C,OAAO,EAST,SAAgB,EAAiB,EAAgB,CAC/C,IAAI,EAAS,GAIT,EAAU,EACd,KAAO,EAAU,GACf,GAAU,iEAAW,OAAO,KAAK,MAAM,KAAK,QAAQ,CAAG,GAAiB,CAAC,CACzE,GAAW,EAEb,OAAO"}
|
package/dist/random.cjs
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getNonCryptoRandomValues = getNonCryptoRandomValues;
|
|
7
|
-
exports.randomCharacters = randomCharacters;
|
|
8
|
-
exports.randomLetter = exports.randomInteger = void 0;
|
|
9
|
-
const e = Array.from({
|
|
10
|
-
length: 26
|
|
11
|
-
}, (t, r) => String.fromCodePoint(r + 97));
|
|
12
|
-
const randomInteger = (t, r = 0) => Math.floor(Math.random() * (t - r + 1) + r),
|
|
13
|
-
randomLetter = (t = Math.random) => e[Math.floor(t() * e.length)];
|
|
14
|
-
exports.randomLetter = randomLetter;
|
|
15
|
-
exports.randomInteger = randomInteger;
|
|
16
|
-
function getNonCryptoRandomValues(t) {
|
|
17
|
-
if (t === null) throw new TypeError("array cannot be null");
|
|
18
|
-
for (let r = 0; r < t.length; r++) t[r] = Math.floor(Math.random() * 256);
|
|
19
|
-
return t;
|
|
20
|
-
}
|
|
21
|
-
function randomCharacters(t) {
|
|
22
|
-
let r = "";
|
|
23
|
-
const o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
24
|
-
a = o.length;
|
|
25
|
-
let n = 0;
|
|
26
|
-
for (; n < t;) r += o.charAt(Math.floor(Math.random() * a)), n += 1;
|
|
27
|
-
return r;
|
|
28
|
-
}
|
|
1
|
+
const e=require(`./random-C4CrqJsp.cjs`);exports.getNonCryptoRandomValues=e.t,exports.randomCharacters=e.n,exports.randomInteger=e.r,exports.randomLetter=e.i;
|
package/dist/random.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./random-kTN0s0Jy.mjs";export{r as getNonCryptoRandomValues,t as randomCharacters,n as randomInteger,e as randomLetter};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/snowflake.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Options passed to the `generate` function to create a snowflake identifier.
|
|
4
|
+
*/
|
|
5
|
+
interface SnowflakeGeneratorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The id of the shard running this generator.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue 1
|
|
10
|
+
*/
|
|
11
|
+
shardId?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The epoch to use for the snowflake.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This is the time in milliseconds since 1 January 1970 00:00:00 UTC.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())
|
|
19
|
+
*/
|
|
20
|
+
epoch?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The current timestamp to use for the snowflake.
|
|
23
|
+
*
|
|
24
|
+
* @defaultValue Date.now()
|
|
25
|
+
*/
|
|
26
|
+
timestamp?: number | Date;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolvable value types for a valid Snowflake:
|
|
30
|
+
* string
|
|
31
|
+
* number
|
|
32
|
+
* bigint
|
|
33
|
+
*/
|
|
34
|
+
type SnowflakeResolvable = string;
|
|
35
|
+
/**
|
|
36
|
+
* A deconstructed snowflake and the details around it's creation.
|
|
37
|
+
*/
|
|
38
|
+
interface DeconstructedSnowflake {
|
|
39
|
+
/**
|
|
40
|
+
* Snowflake deconstructed from
|
|
41
|
+
*/
|
|
42
|
+
snowflake: SnowflakeResolvable;
|
|
43
|
+
/**
|
|
44
|
+
* The timestamp the snowflake was generated
|
|
45
|
+
*/
|
|
46
|
+
timestamp: number;
|
|
47
|
+
/**
|
|
48
|
+
* The shard_id used when generating
|
|
49
|
+
*/
|
|
50
|
+
shard_id: number;
|
|
51
|
+
/**
|
|
52
|
+
* The increment of this snowflake
|
|
53
|
+
*/
|
|
54
|
+
sequence: number;
|
|
55
|
+
/**
|
|
56
|
+
* The 64Bit snowflake binary string
|
|
57
|
+
*/
|
|
58
|
+
binary: string;
|
|
59
|
+
}
|
|
60
|
+
declare const DEFAULT_SHARD_ID = 1;
|
|
61
|
+
declare const DEFAULT_EPOCH: number;
|
|
62
|
+
/**
|
|
63
|
+
* Generate a snowflake identifier.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Snowflakes are 64-bit unsigned integers that are roughly time-ordered.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
*
|
|
71
|
+
* // Generate a snowflake with the default options
|
|
72
|
+
* const id1 = snowflake();
|
|
73
|
+
*
|
|
74
|
+
* // Generate a snowflake with a custom shard id
|
|
75
|
+
* const id2 = snowflake({ shardId: 2 });
|
|
76
|
+
*
|
|
77
|
+
* // Generate a snowflake with a custom shard id and timestamp
|
|
78
|
+
* const id3 = snowflake({ shardId: 3, timestamp: new Date("2021-01-01") });
|
|
79
|
+
*
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param options - The options to use when generating the snowflake
|
|
83
|
+
* @returns A snowflake
|
|
84
|
+
*/
|
|
85
|
+
declare function snowflake(options?: SnowflakeGeneratorOptions): string;
|
|
86
|
+
/**
|
|
87
|
+
* Deconstruct a snowflake to its values using the `epoch`.
|
|
88
|
+
*
|
|
89
|
+
* @param snowflake - Snowflake to deconstruct
|
|
90
|
+
* @returns Either the DeconstructedSnowflake object
|
|
91
|
+
*/
|
|
92
|
+
declare function deconstructSnowflake(snowflake: SnowflakeResolvable): DeconstructedSnowflake;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a snowflake string Id is valid.
|
|
95
|
+
*
|
|
96
|
+
* @param snowflake - Snowflake to check
|
|
97
|
+
* @returns Whether the snowflake is valid
|
|
98
|
+
*/
|
|
99
|
+
declare function isValidSnowflake(snowflake: string): boolean;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { SnowflakeResolvable as a, snowflake as c, SnowflakeGeneratorOptions as i, DEFAULT_SHARD_ID as n, deconstructSnowflake as o, DeconstructedSnowflake as r, isValidSnowflake as s, DEFAULT_EPOCH as t };
|
|
102
|
+
//# sourceMappingURL=snowflake-B6ivA7bE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake-B6ivA7bE.d.mts","names":[],"sources":["../src/snowflake.ts"],"sourcesContent":[],"mappings":";;AAqBA;AAgCA;AAKiB,UArCA,yBAAA,CAyCJ;EAuBA;AACb;AAqEA;AA0BA;AAoBA;;;;;;;;;;;;;;;;uBA7JuB;;;;;;;;KASX,mBAAA;;;;UAKK,sBAAA;;;;aAIJ;;;;;;;;;;;;;;;;;;cAuBA,gBAAA;cACA;;;;;;;;;;;;;;;;;;;;;;;;iBAqEG,SAAA,WAAmB;;;;;;;iBA0BnB,oBAAA,YACH,sBACV;;;;;;;iBAkBa,gBAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=1,t=Date.UTC(1970,0,1).valueOf();let n=1;function r(e){let t=BigInt(e).toString(2);return t.length<64?`0000000000000000000000000000000000000000000000000000000000000000`.slice(0,Math.max(0,64-t.length))+t:t}function i(e,t,n){return Number.parseInt(n?r(e).slice(t,t+n):r(e).slice(Math.max(0,t)),2)}function a(e={}){let{shardId:r,epoch:i,timestamp:a}=e??{},o=BigInt(a?a instanceof Date?a.valueOf():new Date(a).valueOf():Date.now())-BigInt(i??t)<<BigInt(22);return o|=BigInt((r??1)%1024)<<BigInt(12),o|=BigInt(n++%4096),o.toString()}function o(e){let t=r(e);return{snowflake:e,timestamp:i(e,1,41),shard_id:i(e,42,10),sequence:i(e,52),binary:t}}function s(e){if(!/^\d{19}$/.test(e))return!1;try{return o(e),!0}catch{return!1}}export{a,s as i,e as n,o as r,t};
|
|
2
|
+
//# sourceMappingURL=snowflake-BtoDXB99.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake-BtoDXB99.mjs","names":["DEFAULT_EPOCH: number","snowflake"],"sources":["../src/snowflake.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Options passed to the `generate` function to create a snowflake identifier.\n */\nexport interface SnowflakeGeneratorOptions {\n /**\n * The id of the shard running this generator.\n *\n * @defaultValue 1\n */\n shardId?: number;\n\n /**\n * The epoch to use for the snowflake.\n *\n * @remarks\n * This is the time in milliseconds since 1 January 1970 00:00:00 UTC.\n *\n * @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())\n */\n epoch?: number;\n\n /**\n * The current timestamp to use for the snowflake.\n *\n * @defaultValue Date.now()\n */\n timestamp?: number | Date;\n}\n\n/**\n * Resolvable value types for a valid Snowflake:\n * string\n * number\n * bigint\n */\nexport type SnowflakeResolvable = string;\n\n/**\n * A deconstructed snowflake and the details around it's creation.\n */\nexport interface DeconstructedSnowflake {\n /**\n * Snowflake deconstructed from\n */\n snowflake: SnowflakeResolvable;\n\n /**\n * The timestamp the snowflake was generated\n */\n timestamp: number;\n\n /**\n * The shard_id used when generating\n */\n shard_id: number;\n\n /**\n * The increment of this snowflake\n */\n sequence: number;\n\n /**\n * The 64Bit snowflake binary string\n */\n binary: string;\n}\n\nexport const DEFAULT_SHARD_ID = 1;\nexport const DEFAULT_EPOCH: number = Date.UTC(1970, 0, 1).valueOf();\n\n/**\n * The sequence of the current running generator.\n *\n * @defaultValue 1\n */\nlet sequence = 1;\n\n/**\n * Transform a snowflake into its 64Bit binary string.\n *\n * @param snowflake - Snowflake to transform\n * @returns A 64Bit binary string\n */\nfunction ToBinaryString(snowflake: SnowflakeResolvable): string {\n const cached64BitZeros =\n \"0000000000000000000000000000000000000000000000000000000000000000\";\n const binValue = BigInt(snowflake).toString(2);\n\n return binValue.length < 64\n ? cached64BitZeros.slice(0, Math.max(0, 64 - binValue.length)) + binValue\n : binValue;\n}\n\n/**\n * Extract bits and their values from a snowflake.\n *\n * @param snowflake - Snowflake to extract from\n * @param start - The starting index to extract bits from\n * @param length - Number of bits to extract before stopping\n * @returns A bigint value of the extracted bits\n */\nfunction extractBits(\n snowflake: SnowflakeResolvable,\n start: number,\n length?: number\n): number {\n return Number.parseInt(\n length\n ? ToBinaryString(snowflake).slice(start, start + length)\n : ToBinaryString(snowflake).slice(Math.max(0, start)),\n 2\n );\n}\n\n/**\n * Generate a snowflake identifier.\n *\n * @remarks\n * Snowflakes are 64-bit unsigned integers that are roughly time-ordered.\n *\n * @example\n * ```typescript\n *\n * // Generate a snowflake with the default options\n * const id1 = snowflake();\n *\n * // Generate a snowflake with a custom shard id\n * const id2 = snowflake({ shardId: 2 });\n *\n * // Generate a snowflake with a custom shard id and timestamp\n * const id3 = snowflake({ shardId: 3, timestamp: new Date(\"2021-01-01\") });\n *\n * ```\n *\n * @param options - The options to use when generating the snowflake\n * @returns A snowflake\n */\nexport function snowflake(options: SnowflakeGeneratorOptions = {}): string {\n const { shardId, epoch, timestamp } = options ?? {};\n\n let result =\n (BigInt(\n timestamp\n ? timestamp instanceof Date\n ? timestamp.valueOf()\n : new Date(timestamp).valueOf()\n : Date.now()\n ) -\n BigInt(epoch ?? DEFAULT_EPOCH)) <<\n BigInt(22);\n\n result |= BigInt((shardId ?? DEFAULT_SHARD_ID) % 1024) << BigInt(12);\n result |= BigInt(sequence++ % 4096);\n\n return result.toString();\n}\n\n/**\n * Deconstruct a snowflake to its values using the `epoch`.\n *\n * @param snowflake - Snowflake to deconstruct\n * @returns Either the DeconstructedSnowflake object\n */\nexport function deconstructSnowflake(\n snowflake: SnowflakeResolvable\n): DeconstructedSnowflake {\n const binary = ToBinaryString(snowflake);\n\n return {\n snowflake,\n timestamp: extractBits(snowflake, 1, 41),\n shard_id: extractBits(snowflake, 42, 10),\n sequence: extractBits(snowflake, 52),\n binary\n };\n}\n\n/**\n * Check if a snowflake string Id is valid.\n *\n * @param snowflake - Snowflake to check\n * @returns Whether the snowflake is valid\n */\nexport function isValidSnowflake(snowflake: string): boolean {\n if (!/^\\d{19}$/.test(snowflake)) {\n return false;\n }\n\n try {\n deconstructSnowflake(snowflake);\n\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"AAqFA,MAAa,EAAmB,EACnBA,EAAwB,KAAK,IAAI,KAAM,EAAG,EAAE,CAAC,SAAS,CAOnE,IAAI,EAAW,EAQf,SAAS,EAAe,EAAwC,CAC9D,IAEM,EAAW,OAAOC,EAAU,CAAC,SAAS,EAAE,CAE9C,OAAO,EAAS,OAAS,GACrB,mEAAiB,MAAM,EAAG,KAAK,IAAI,EAAG,GAAK,EAAS,OAAO,CAAC,CAAG,EAC/D,EAWN,SAAS,EACP,EACA,EACA,EACQ,CACR,OAAO,OAAO,SACZ,EACI,EAAeA,EAAU,CAAC,MAAM,EAAO,EAAQ,EAAO,CACtD,EAAeA,EAAU,CAAC,MAAM,KAAK,IAAI,EAAG,EAAM,CAAC,CACvD,EACD,CA0BH,SAAgB,EAAU,EAAqC,EAAE,CAAU,CACzE,GAAM,CAAE,UAAS,QAAO,aAAc,GAAW,EAAE,CAE/C,EACD,OACC,EACI,aAAqB,KACnB,EAAU,SAAS,CACnB,IAAI,KAAK,EAAU,CAAC,SAAS,CAC/B,KAAK,KAAK,CACf,CACC,OAAO,GAAS,EAAc,EAChC,OAAO,GAAG,CAKZ,MAHA,IAAU,QAAQ,GAAW,GAAoB,KAAK,EAAI,OAAO,GAAG,CACpE,GAAU,OAAO,IAAa,KAAK,CAE5B,EAAO,UAAU,CAS1B,SAAgB,EACd,EACwB,CACxB,IAAM,EAAS,EAAeA,EAAU,CAExC,MAAO,CACL,UAAA,EACA,UAAW,EAAYA,EAAW,EAAG,GAAG,CACxC,SAAU,EAAYA,EAAW,GAAI,GAAG,CACxC,SAAU,EAAYA,EAAW,GAAG,CACpC,SACD,CASH,SAAgB,EAAiB,EAA4B,CAC3D,GAAI,CAAC,WAAW,KAAKA,EAAU,CAC7B,MAAO,GAGT,GAAI,CAGF,OAFA,EAAqBA,EAAU,CAExB,QACD,CACN,MAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=1,t=Date.UTC(1970,0,1).valueOf();let n=1;function r(e){let t=BigInt(e).toString(2);return t.length<64?`0000000000000000000000000000000000000000000000000000000000000000`.slice(0,Math.max(0,64-t.length))+t:t}function i(e,t,n){return Number.parseInt(n?r(e).slice(t,t+n):r(e).slice(Math.max(0,t)),2)}function a(e={}){let{shardId:r,epoch:i,timestamp:a}=e??{},o=BigInt(a?a instanceof Date?a.valueOf():new Date(a).valueOf():Date.now())-BigInt(i??t)<<BigInt(22);return o|=BigInt((r??1)%1024)<<BigInt(12),o|=BigInt(n++%4096),o.toString()}function o(e){let t=r(e);return{snowflake:e,timestamp:i(e,1,41),shard_id:i(e,42,10),sequence:i(e,52),binary:t}}function s(e){if(!/^\d{19}$/.test(e))return!1;try{return o(e),!0}catch{return!1}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return 1}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/snowflake.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Options passed to the `generate` function to create a snowflake identifier.
|
|
4
|
+
*/
|
|
5
|
+
interface SnowflakeGeneratorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The id of the shard running this generator.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue 1
|
|
10
|
+
*/
|
|
11
|
+
shardId?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The epoch to use for the snowflake.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This is the time in milliseconds since 1 January 1970 00:00:00 UTC.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())
|
|
19
|
+
*/
|
|
20
|
+
epoch?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The current timestamp to use for the snowflake.
|
|
23
|
+
*
|
|
24
|
+
* @defaultValue Date.now()
|
|
25
|
+
*/
|
|
26
|
+
timestamp?: number | Date;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolvable value types for a valid Snowflake:
|
|
30
|
+
* string
|
|
31
|
+
* number
|
|
32
|
+
* bigint
|
|
33
|
+
*/
|
|
34
|
+
type SnowflakeResolvable = string;
|
|
35
|
+
/**
|
|
36
|
+
* A deconstructed snowflake and the details around it's creation.
|
|
37
|
+
*/
|
|
38
|
+
interface DeconstructedSnowflake {
|
|
39
|
+
/**
|
|
40
|
+
* Snowflake deconstructed from
|
|
41
|
+
*/
|
|
42
|
+
snowflake: SnowflakeResolvable;
|
|
43
|
+
/**
|
|
44
|
+
* The timestamp the snowflake was generated
|
|
45
|
+
*/
|
|
46
|
+
timestamp: number;
|
|
47
|
+
/**
|
|
48
|
+
* The shard_id used when generating
|
|
49
|
+
*/
|
|
50
|
+
shard_id: number;
|
|
51
|
+
/**
|
|
52
|
+
* The increment of this snowflake
|
|
53
|
+
*/
|
|
54
|
+
sequence: number;
|
|
55
|
+
/**
|
|
56
|
+
* The 64Bit snowflake binary string
|
|
57
|
+
*/
|
|
58
|
+
binary: string;
|
|
59
|
+
}
|
|
60
|
+
declare const DEFAULT_SHARD_ID = 1;
|
|
61
|
+
declare const DEFAULT_EPOCH: number;
|
|
62
|
+
/**
|
|
63
|
+
* Generate a snowflake identifier.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Snowflakes are 64-bit unsigned integers that are roughly time-ordered.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
*
|
|
71
|
+
* // Generate a snowflake with the default options
|
|
72
|
+
* const id1 = snowflake();
|
|
73
|
+
*
|
|
74
|
+
* // Generate a snowflake with a custom shard id
|
|
75
|
+
* const id2 = snowflake({ shardId: 2 });
|
|
76
|
+
*
|
|
77
|
+
* // Generate a snowflake with a custom shard id and timestamp
|
|
78
|
+
* const id3 = snowflake({ shardId: 3, timestamp: new Date("2021-01-01") });
|
|
79
|
+
*
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param options - The options to use when generating the snowflake
|
|
83
|
+
* @returns A snowflake
|
|
84
|
+
*/
|
|
85
|
+
declare function snowflake(options?: SnowflakeGeneratorOptions): string;
|
|
86
|
+
/**
|
|
87
|
+
* Deconstruct a snowflake to its values using the `epoch`.
|
|
88
|
+
*
|
|
89
|
+
* @param snowflake - Snowflake to deconstruct
|
|
90
|
+
* @returns Either the DeconstructedSnowflake object
|
|
91
|
+
*/
|
|
92
|
+
declare function deconstructSnowflake(snowflake: SnowflakeResolvable): DeconstructedSnowflake;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a snowflake string Id is valid.
|
|
95
|
+
*
|
|
96
|
+
* @param snowflake - Snowflake to check
|
|
97
|
+
* @returns Whether the snowflake is valid
|
|
98
|
+
*/
|
|
99
|
+
declare function isValidSnowflake(snowflake: string): boolean;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { SnowflakeResolvable as a, snowflake as c, SnowflakeGeneratorOptions as i, DEFAULT_SHARD_ID as n, deconstructSnowflake as o, DeconstructedSnowflake as r, isValidSnowflake as s, DEFAULT_EPOCH as t };
|
|
102
|
+
//# sourceMappingURL=snowflake-DQmoRlnq.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake-DQmoRlnq.d.cts","names":[],"sources":["../src/snowflake.ts"],"sourcesContent":[],"mappings":";;AAqBA;AAgCA;AAKiB,UArCA,yBAAA,CAyCJ;EAuBA;AACb;AAqEA;AA0BA;AAoBA;;;;;;;;;;;;;;;;uBA7JuB;;;;;;;;KASX,mBAAA;;;;UAKK,sBAAA;;;;aAIJ;;;;;;;;;;;;;;;;;;cAuBA,gBAAA;cACA;;;;;;;;;;;;;;;;;;;;;;;;iBAqEG,SAAA,WAAmB;;;;;;;iBA0BnB,oBAAA,YACH,sBACV;;;;;;;iBAkBa,gBAAA"}
|
package/dist/snowflake.cjs
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DEFAULT_SHARD_ID = exports.DEFAULT_EPOCH = void 0;
|
|
7
|
-
exports.deconstructSnowflake = deconstructSnowflake;
|
|
8
|
-
exports.isValidSnowflake = isValidSnowflake;
|
|
9
|
-
exports.snowflake = snowflake;
|
|
10
|
-
const DEFAULT_SHARD_ID = exports.DEFAULT_SHARD_ID = 1,
|
|
11
|
-
DEFAULT_EPOCH = exports.DEFAULT_EPOCH = Date.UTC(1970, 0, 1).valueOf();
|
|
12
|
-
let s = 1;
|
|
13
|
-
function a(e) {
|
|
14
|
-
const t = "0000000000000000000000000000000000000000000000000000000000000000",
|
|
15
|
-
n = BigInt(e).toString(2);
|
|
16
|
-
return n.length < 64 ? t.slice(0, Math.max(0, 64 - n.length)) + n : n;
|
|
17
|
-
}
|
|
18
|
-
function i(e, t, n) {
|
|
19
|
-
return Number.parseInt(n ? a(e).slice(t, t + n) : a(e).slice(Math.max(0, t)), 2);
|
|
20
|
-
}
|
|
21
|
-
function snowflake(e = {}) {
|
|
22
|
-
const {
|
|
23
|
-
shardId: t,
|
|
24
|
-
epoch: n,
|
|
25
|
-
timestamp: r
|
|
26
|
-
} = e ?? {};
|
|
27
|
-
let o = BigInt(r ? r instanceof Date ? r.valueOf() : new Date(r).valueOf() : Date.now()) - BigInt(n ?? DEFAULT_EPOCH) << BigInt(22);
|
|
28
|
-
return o |= BigInt((t ?? 1) % 1024) << BigInt(12), o |= BigInt(s++ % 4096), o.toString();
|
|
29
|
-
}
|
|
30
|
-
function deconstructSnowflake(e) {
|
|
31
|
-
const t = a(e);
|
|
32
|
-
return {
|
|
33
|
-
snowflake: e,
|
|
34
|
-
timestamp: i(e, 1, 41),
|
|
35
|
-
shard_id: i(e, 42, 10),
|
|
36
|
-
sequence: i(e, 52),
|
|
37
|
-
binary: t
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function isValidSnowflake(e) {
|
|
41
|
-
if (!/^\d{19}$/.test(e)) return !1;
|
|
42
|
-
try {
|
|
43
|
-
return deconstructSnowflake(e), !0;
|
|
44
|
-
} catch {
|
|
45
|
-
return !1;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
const e=require(`./snowflake-CLDXd54w.cjs`);exports.DEFAULT_EPOCH=e.t,exports.DEFAULT_SHARD_ID=e.n,exports.deconstructSnowflake=e.r,exports.isValidSnowflake=e.i,exports.snowflake=e.a;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SnowflakeResolvable, c as snowflake, i as SnowflakeGeneratorOptions, n as DEFAULT_SHARD_ID, o as deconstructSnowflake, r as DeconstructedSnowflake, s as isValidSnowflake, t as DEFAULT_EPOCH } from "./snowflake-DQmoRlnq.cjs";
|
|
2
|
+
export { DEFAULT_EPOCH, DEFAULT_SHARD_ID, DeconstructedSnowflake, SnowflakeGeneratorOptions, SnowflakeResolvable, deconstructSnowflake, isValidSnowflake, snowflake };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SnowflakeResolvable, c as snowflake, i as SnowflakeGeneratorOptions, n as DEFAULT_SHARD_ID, o as deconstructSnowflake, r as DeconstructedSnowflake, s as isValidSnowflake, t as DEFAULT_EPOCH } from "./snowflake-B6ivA7bE.mjs";
|
|
2
|
+
export { DEFAULT_EPOCH, DEFAULT_SHARD_ID, DeconstructedSnowflake, SnowflakeGeneratorOptions, SnowflakeResolvable, deconstructSnowflake, isValidSnowflake, snowflake };
|
package/dist/snowflake.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"./snowflake-BtoDXB99.mjs";export{i as DEFAULT_EPOCH,n as DEFAULT_SHARD_ID,r as deconstructSnowflake,t as isValidSnowflake,e as snowflake};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=256;const t=[];let n;for(;e--;)t[e]=(e+256).toString(16).slice(1);function r(){let r=0,i,a=``;if(!n||e+16>256){for(n=Array.from({length:r=256});r--;)n[r]=Math.trunc(256*Math.random());r=e=0}for(;r<16;r++)i=n[e+r],r===6?a+=t[i&15|64]:r===8?a+=t[i&63|128]:a+=t[i],r&1&&r>1&&r<11&&(a+=`-`);return e++,a}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/uuid.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
|
|
3
4
|
*
|
|
@@ -15,4 +16,7 @@
|
|
|
15
16
|
*
|
|
16
17
|
* @returns A UUID unique identifier.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
declare function uuid(): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { uuid as t };
|
|
22
|
+
//# sourceMappingURL=uuid-ByPTbUGJ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-ByPTbUGJ.d.mts","names":[],"sources":["../src/uuid.ts"],"sourcesContent":[],"mappings":";;AA2CA;;;;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/uuid.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.
|
|
7
|
+
*
|
|
8
|
+
* This implementation was based on https://github.com/lukeed/uuid.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Generate a UUID string
|
|
13
|
+
* const id = uuid();
|
|
14
|
+
* // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns A UUID unique identifier.
|
|
18
|
+
*/
|
|
19
|
+
declare function uuid(): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { uuid as t };
|
|
22
|
+
//# sourceMappingURL=uuid-DCE9JeUQ.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-DCE9JeUQ.d.cts","names":[],"sources":["../src/uuid.ts"],"sourcesContent":[],"mappings":";;AA2CA;;;;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=256;const t=[];let n;for(;e--;)t[e]=(e+256).toString(16).slice(1);function r(){let r=0,i,a=``;if(!n||e+16>256){for(n=Array.from({length:r=256});r--;)n[r]=Math.trunc(256*Math.random());r=e=0}for(;r<16;r++)i=n[e+r],r===6?a+=t[i&15|64]:r===8?a+=t[i&63|128]:a+=t[i],r&1&&r>1&&r<11&&(a+=`-`);return e++,a}export{r as t};
|
|
2
|
+
//# sourceMappingURL=uuid-DSMliG_W.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-DSMliG_W.mjs","names":["buffer!: number[]","num!: number"],"sources":["../src/uuid.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nlet index = 256;\nconst hex = [] as string[];\nlet buffer!: number[];\n\nwhile (index--) {\n hex[index] = (index + 256).toString(16).slice(1);\n}\n\n/**\n * A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.\n *\n * @remarks\n * This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.\n *\n * This implementation was based on https://github.com/lukeed/uuid.\n *\n * @example\n * ```typescript\n * // Generate a UUID string\n * const id = uuid();\n * // => \"f47ac10b-58cc-4372-a567-0e02b2c3d479\"\n * ```\n *\n * @returns A UUID unique identifier.\n */\nexport function uuid() {\n let i = 0;\n let num!: number;\n let out = \"\";\n\n if (!buffer || index + 16 > 256) {\n buffer = Array.from({ length: (i = 256) });\n while (i--) {\n buffer[i] = Math.trunc(256 * Math.random());\n }\n // eslint-disable-next-line no-multi-assign\n i = index = 0;\n }\n\n for (; i < 16; i++) {\n num = buffer[index + i]!;\n if (i === 6) {\n out += hex[(num & 15) | 64];\n } else if (i === 8) {\n out += hex[(num & 63) | 128];\n } else {\n out += hex[num];\n }\n\n if (i & 1 && i > 1 && i < 11) {\n out += \"-\";\n }\n }\n\n index++;\n return out;\n}\n"],"mappings":"AAkBA,IAAI,EAAQ,IACZ,MAAM,EAAM,EAAE,CACd,IAAIA,EAEJ,KAAO,KACL,EAAI,IAAU,EAAQ,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,CAoBlD,SAAgB,GAAO,CACrB,IAAI,EAAI,EACJC,EACA,EAAM,GAEV,GAAI,CAAC,GAAU,EAAQ,GAAK,IAAK,CAE/B,IADA,EAAS,MAAM,KAAK,CAAE,OAAS,EAAI,IAAM,CAAC,CACnC,KACL,EAAO,GAAK,KAAK,MAAM,IAAM,KAAK,QAAQ,CAAC,CAG7C,EAAI,EAAQ,EAGd,KAAO,EAAI,GAAI,IACb,EAAM,EAAO,EAAQ,GACjB,IAAM,EACR,GAAO,EAAK,EAAM,GAAM,IACf,IAAM,EACf,GAAO,EAAK,EAAM,GAAM,KAExB,GAAO,EAAI,GAGT,EAAI,GAAK,EAAI,GAAK,EAAI,KACxB,GAAO,KAKX,MADA,KACO"}
|
package/dist/uuid.cjs
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.uuid = uuid;
|
|
7
|
-
let t = 256;
|
|
8
|
-
const n = [];
|
|
9
|
-
let l;
|
|
10
|
-
for (; t--;) n[t] = (t + 256).toString(16).slice(1);
|
|
11
|
-
function uuid() {
|
|
12
|
-
let e = 0,
|
|
13
|
-
i,
|
|
14
|
-
r = "";
|
|
15
|
-
if (!l || t + 16 > 256) {
|
|
16
|
-
for (l = Array.from({
|
|
17
|
-
length: e = 256
|
|
18
|
-
}); e--;) l[e] = Math.trunc(256 * Math.random());
|
|
19
|
-
e = t = 0;
|
|
20
|
-
}
|
|
21
|
-
for (; e < 16; e++) i = l[t + e], e === 6 ? r += n[i & 15 | 64] : e === 8 ? r += n[i & 63 | 128] : r += n[i], e & 1 && e > 1 && e < 11 && (r += "-");
|
|
22
|
-
return t++, r;
|
|
23
|
-
}
|
|
1
|
+
const e=require(`./uuid-BnD3hGTH.cjs`);exports.uuid=e.t;
|
package/dist/uuid.d.cts
ADDED
package/dist/uuid.d.mts
ADDED
package/dist/uuid.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{t as e}from"./uuid-DSMliG_W.mjs";export{e as uuid};
|