@stryke/unique-id 0.3.43 → 0.3.45

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/convert/src/neutral.cjs +3 -1
  4. package/dist/convert/src/neutral.mjs +5 -1
  5. package/dist/convert/src/parse-type-definition.cjs +1 -1
  6. package/dist/convert/src/parse-type-definition.mjs +3 -1
  7. package/dist/convert/src/string-to-utf8-array.cjs +5 -1
  8. package/dist/convert/src/string-to-utf8-array.mjs +5 -1
  9. package/dist/convert/src/string-to-utf8-array.mjs.map +1 -1
  10. package/dist/convert/src/utf8-array-to-string.cjs +5 -1
  11. package/dist/convert/src/utf8-array-to-string.mjs +5 -1
  12. package/dist/convert/src/utf8-array-to-string.mjs.map +1 -1
  13. package/dist/cuid.cjs +64 -1
  14. package/dist/cuid.mjs +64 -1
  15. package/dist/cuid.mjs.map +1 -1
  16. package/dist/fs/src/list-files.cjs +4 -1
  17. package/dist/fs/src/list-files.mjs +5 -1
  18. package/dist/hash/src/digest.cjs +1 -1
  19. package/dist/hash/src/digest.mjs +3 -1
  20. package/dist/hash/src/hash-files.cjs +2 -1
  21. package/dist/hash/src/hash-files.mjs +4 -1
  22. package/dist/hash/src/murmurhash.cjs +22 -1
  23. package/dist/hash/src/murmurhash.mjs +21 -1
  24. package/dist/hash/src/murmurhash.mjs.map +1 -1
  25. package/dist/hash/src/neutral.cjs +4 -1
  26. package/dist/hash/src/neutral.mjs +6 -1
  27. package/dist/hash/src/xx-hash.cjs +1 -1
  28. package/dist/hash/src/xx-hash.mjs +3 -1
  29. package/dist/index.cjs +18 -1
  30. package/dist/index.mjs +7 -1
  31. package/dist/nanoid-client.cjs +22 -1
  32. package/dist/nanoid-client.mjs +22 -1
  33. package/dist/nanoid-client.mjs.map +1 -1
  34. package/dist/random.cjs +52 -1
  35. package/dist/random.mjs +48 -1
  36. package/dist/random.mjs.map +1 -1
  37. package/dist/snowflake.cjs +100 -1
  38. package/dist/snowflake.mjs +95 -1
  39. package/dist/snowflake.mjs.map +1 -1
  40. package/dist/type-checks/src/index.cjs +3 -1
  41. package/dist/type-checks/src/index.mjs +5 -1
  42. package/dist/type-checks/src/is-buffer.cjs +12 -1
  43. package/dist/type-checks/src/is-buffer.mjs +11 -1
  44. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  45. package/dist/type-checks/src/is-collection.cjs +1 -1
  46. package/dist/type-checks/src/is-collection.mjs +3 -1
  47. package/dist/type-checks/src/type-detect.cjs +15 -1
  48. package/dist/type-checks/src/type-detect.mjs +16 -1
  49. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  50. package/dist/uuid.cjs +45 -1
  51. package/dist/uuid.mjs +44 -1
  52. package/dist/uuid.mjs.map +1 -1
  53. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  # Changelog for Stryke - Unique ID
4
4
 
5
+ ## [0.3.44](https://github.com/storm-software/stryke/releases/tag/unique-id%400.3.44) (01/16/2026)
6
+
7
+ ### Updated Dependencies
8
+
9
+ - Updated **hash** to **v0.12.39**
10
+
11
+ ## [0.3.43](https://github.com/storm-software/stryke/releases/tag/unique-id%400.3.43) (01/16/2026)
12
+
13
+ ### Updated Dependencies
14
+
15
+ - Updated **hash** to **v0.12.38**
16
+
5
17
  ## [0.3.42](https://github.com/storm-software/stryke/releases/tag/unique-id%400.3.42) (01/16/2026)
6
18
 
7
19
  ### Updated Dependencies
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1 +1,3 @@
1
- require(`./parse-type-definition.cjs`),require(`./string-to-utf8-array.cjs`),require(`./utf8-array-to-string.cjs`);
1
+ require('./parse-type-definition.cjs');
2
+ require('./string-to-utf8-array.cjs');
3
+ require('./utf8-array-to-string.cjs');
@@ -1 +1,5 @@
1
- import"./parse-type-definition.mjs";import"./string-to-utf8-array.mjs";import"./utf8-array-to-string.mjs";export{};
1
+ import "./parse-type-definition.mjs";
2
+ import "./string-to-utf8-array.mjs";
3
+ import "./utf8-array-to-string.mjs";
4
+
5
+ export { };
@@ -1 +1 @@
1
- require(`../../type-checks/src/index.cjs`);
1
+ require('../../type-checks/src/index.cjs');
@@ -1 +1,3 @@
1
- import"../../type-checks/src/index.mjs";export{};
1
+ import "../../type-checks/src/index.mjs";
2
+
3
+ export { };
@@ -1 +1,5 @@
1
- const e=new TextEncoder;
1
+
2
+ //#region ../convert/src/string-to-utf8-array.ts
3
+ const encoder = new TextEncoder();
4
+
5
+ //#endregion
@@ -1,2 +1,6 @@
1
- new TextEncoder;export{};
1
+ //#region ../convert/src/string-to-utf8-array.ts
2
+ const encoder = new TextEncoder();
3
+
4
+ //#endregion
5
+ export { };
2
6
  //# sourceMappingURL=string-to-utf8-array.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-to-utf8-array.mjs","names":[],"sources":["../../../../convert/src/string-to-utf8-array.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 encoder = new TextEncoder();\n\n/**\n * Convert a string to a utf-8 array\n *\n * @param input - The string to convert\n * @returns The converted utf-8 array\n */\nexport function stringToUtf8Array(input: string): Uint8Array {\n return encoder.encode(input);\n}\n"],"mappings":"AAkBgB,IAAI"}
1
+ {"version":3,"file":"string-to-utf8-array.mjs","names":[],"sources":["../../../../convert/src/string-to-utf8-array.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 encoder = new TextEncoder();\n\n/**\n * Convert a string to a utf-8 array\n *\n * @param input - The string to convert\n * @returns The converted utf-8 array\n */\nexport function stringToUtf8Array(input: string): Uint8Array {\n return encoder.encode(input);\n}\n"],"mappings":";AAkBA,MAAM,UAAU,IAAI,aAAa"}
@@ -1 +1,5 @@
1
- const e=new TextDecoder;
1
+
2
+ //#region ../convert/src/utf8-array-to-string.ts
3
+ const decoder = new TextDecoder();
4
+
5
+ //#endregion
@@ -1,2 +1,6 @@
1
- new TextDecoder;export{};
1
+ //#region ../convert/src/utf8-array-to-string.ts
2
+ const decoder = new TextDecoder();
3
+
4
+ //#endregion
5
+ export { };
2
6
  //# sourceMappingURL=utf8-array-to-string.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utf8-array-to-string.mjs","names":[],"sources":["../../../../convert/src/utf8-array-to-string.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 decoder = new TextDecoder();\n\n/**\n * Convert a utf-8 array to string\n *\n * @param input - Utf-8 Array\n * @returns The converted string\n */\nexport function utf8ArrayToString(\n input: NodeJS.ArrayBufferView | ArrayBuffer\n): string {\n return decoder.decode(input);\n}\n"],"mappings":"AAkBgB,IAAI"}
1
+ {"version":3,"file":"utf8-array-to-string.mjs","names":[],"sources":["../../../../convert/src/utf8-array-to-string.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 decoder = new TextDecoder();\n\n/**\n * Convert a utf-8 array to string\n *\n * @param input - Utf-8 Array\n * @returns The converted string\n */\nexport function utf8ArrayToString(\n input: NodeJS.ArrayBufferView | ArrayBuffer\n): string {\n return decoder.decode(input);\n}\n"],"mappings":";AAkBA,MAAM,UAAU,IAAI,aAAa"}
package/dist/cuid.cjs CHANGED
@@ -1 +1,64 @@
1
- const e=require(`./hash/src/murmurhash.cjs`);require(`./hash/src/neutral.cjs`);const t=require(`./random.cjs`),n=476782367,r=36,i=Math.floor(Math.random()*476782367)+1;function a(e=4,t=Math.random){let n=``;for(;n.length<e;)n+=Math.floor(t()*36).toString(36);return n}function o(t){let n=(t?.globalObj??typeof globalThis>`u`)&&typeof globalThis>`u`?{}:globalThis,r=Object.keys(n).toString();return e.murmurhash(r.length>0?r+a(36,Math.random):a(36,Math.random)).slice(0,36)}function s(){let n=Date.now().toString(36),r=i.toString(36),s=e.murmurhash(`${n+a(36,Math.random)+r+o()}`);return`${t.randomLetter()+s.slice(1,Math.min(s.length-1,36))}`}exports.cuid=s;
1
+ const require_murmurhash = require('./hash/src/murmurhash.cjs');
2
+ require('./hash/src/neutral.cjs');
3
+ const require_random = require('./random.cjs');
4
+
5
+ //#region src/cuid.ts
6
+ /**
7
+ * ~22k hosts before 50% chance of initial counter collision with a remaining counter range of 9.0e+15 in JavaScript.
8
+ */
9
+ const INITIAL_COUNT_MAX = 476782367;
10
+ /**
11
+ * The length of the CUID fingerprint.
12
+ */
13
+ const CUID_LARGE_LENGTH = 36;
14
+ /**
15
+ * The counter used to help prevent collisions.
16
+ */
17
+ const counter = Math.floor(Math.random() * INITIAL_COUNT_MAX) + 1;
18
+ /**
19
+ * Generate a random letter
20
+ *
21
+ * @param length - The length of the random string to generate
22
+ * @param random - The random number generator
23
+ * @returns A random letter
24
+ */
25
+ function createEntropy(length = 4, random = Math.random) {
26
+ let entropy = "";
27
+ while (entropy.length < length) entropy += Math.floor(random() * CUID_LARGE_LENGTH).toString(CUID_LARGE_LENGTH);
28
+ return entropy;
29
+ }
30
+ /**
31
+ * This is a fingerprint of the host environment. It is used to help prevent collisions when generating ids in a distributed system.
32
+ *
33
+ * @remarks
34
+ * If no global object is available, you can pass in your own, or fall back on a random string.
35
+ *
36
+ * @param options - Options
37
+ * @returns The environment's Fingerprint
38
+ */
39
+ function fingerprint(options) {
40
+ const globalObj = options?.globalObj ?? typeof globalThis === "undefined" ? typeof globalThis === "undefined" ? {} : globalThis : globalThis;
41
+ const globals = Object.keys(globalObj).toString();
42
+ return require_murmurhash.murmurhash(globals.length > 0 ? globals + createEntropy(CUID_LARGE_LENGTH, Math.random) : createEntropy(CUID_LARGE_LENGTH, Math.random)).slice(0, Math.max(0, CUID_LARGE_LENGTH));
43
+ }
44
+ /**
45
+ * Generate a random CUID
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ *
50
+ * // Generate a random CUID
51
+ * const id = cuid();
52
+ * ```
53
+ *
54
+ * @returns A random CUID string
55
+ */
56
+ function cuid() {
57
+ const time = Date.now().toString(CUID_LARGE_LENGTH);
58
+ const count = counter.toString(CUID_LARGE_LENGTH);
59
+ const hashed = require_murmurhash.murmurhash(`${time + createEntropy(CUID_LARGE_LENGTH, Math.random) + count + fingerprint()}`);
60
+ return `${require_random.randomLetter() + hashed.slice(1, Math.min(hashed.length - 1, CUID_LARGE_LENGTH))}`;
61
+ }
62
+
63
+ //#endregion
64
+ exports.cuid = cuid;
package/dist/cuid.mjs CHANGED
@@ -1,2 +1,65 @@
1
- import{murmurhash as e}from"./hash/src/murmurhash.mjs";import"./hash/src/neutral.mjs";import{randomLetter as t}from"./random.mjs";const n=Math.floor(Math.random()*476782367)+1;function r(e=4,t=Math.random){let n=``;for(;n.length<e;)n+=Math.floor(t()*36).toString(36);return n}function i(t){let n=(t?.globalObj??typeof globalThis>`u`)&&typeof globalThis>`u`?{}:globalThis,i=Object.keys(n).toString();return e(i.length>0?i+r(36,Math.random):r(36,Math.random)).slice(0,36)}function a(){let a=Date.now().toString(36),o=n.toString(36),s=e(`${a+r(36,Math.random)+o+i()}`);return`${t()+s.slice(1,Math.min(s.length-1,36))}`}export{a as cuid};
1
+ import { murmurhash } from "./hash/src/murmurhash.mjs";
2
+ import "./hash/src/neutral.mjs";
3
+ import { randomLetter } from "./random.mjs";
4
+
5
+ //#region src/cuid.ts
6
+ /**
7
+ * ~22k hosts before 50% chance of initial counter collision with a remaining counter range of 9.0e+15 in JavaScript.
8
+ */
9
+ const INITIAL_COUNT_MAX = 476782367;
10
+ /**
11
+ * The length of the CUID fingerprint.
12
+ */
13
+ const CUID_LARGE_LENGTH = 36;
14
+ /**
15
+ * The counter used to help prevent collisions.
16
+ */
17
+ const counter = Math.floor(Math.random() * INITIAL_COUNT_MAX) + 1;
18
+ /**
19
+ * Generate a random letter
20
+ *
21
+ * @param length - The length of the random string to generate
22
+ * @param random - The random number generator
23
+ * @returns A random letter
24
+ */
25
+ function createEntropy(length = 4, random = Math.random) {
26
+ let entropy = "";
27
+ while (entropy.length < length) entropy += Math.floor(random() * CUID_LARGE_LENGTH).toString(CUID_LARGE_LENGTH);
28
+ return entropy;
29
+ }
30
+ /**
31
+ * This is a fingerprint of the host environment. It is used to help prevent collisions when generating ids in a distributed system.
32
+ *
33
+ * @remarks
34
+ * If no global object is available, you can pass in your own, or fall back on a random string.
35
+ *
36
+ * @param options - Options
37
+ * @returns The environment's Fingerprint
38
+ */
39
+ function fingerprint(options) {
40
+ const globalObj = options?.globalObj ?? typeof globalThis === "undefined" ? typeof globalThis === "undefined" ? {} : globalThis : globalThis;
41
+ const globals = Object.keys(globalObj).toString();
42
+ return murmurhash(globals.length > 0 ? globals + createEntropy(CUID_LARGE_LENGTH, Math.random) : createEntropy(CUID_LARGE_LENGTH, Math.random)).slice(0, Math.max(0, CUID_LARGE_LENGTH));
43
+ }
44
+ /**
45
+ * Generate a random CUID
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ *
50
+ * // Generate a random CUID
51
+ * const id = cuid();
52
+ * ```
53
+ *
54
+ * @returns A random CUID string
55
+ */
56
+ function cuid() {
57
+ const time = Date.now().toString(CUID_LARGE_LENGTH);
58
+ const count = counter.toString(CUID_LARGE_LENGTH);
59
+ const hashed = murmurhash(`${time + createEntropy(CUID_LARGE_LENGTH, Math.random) + count + fingerprint()}`);
60
+ return `${randomLetter() + hashed.slice(1, Math.min(hashed.length - 1, CUID_LARGE_LENGTH))}`;
61
+ }
62
+
63
+ //#endregion
64
+ export { cuid };
2
65
  //# sourceMappingURL=cuid.mjs.map
package/dist/cuid.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cuid.mjs","names":[],"sources":["../src/cuid.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\nimport { murmurhash } from \"@stryke/hash/neutral\";\nimport { randomLetter } from \"./random\";\n\n/**\n * ~22k hosts before 50% chance of initial counter collision with a remaining counter range of 9.0e+15 in JavaScript.\n */\nconst INITIAL_COUNT_MAX = 476_782_367;\n\n/**\n * The length of the CUID fingerprint.\n */\nconst CUID_LARGE_LENGTH = 36;\n\n/**\n * The sequence of the current running generator.\n *\n * @defaultValue 1\n */\nconst sequence = 1;\n\n/**\n * The counter used to help prevent collisions.\n */\nconst counter = Math.floor(Math.random() * INITIAL_COUNT_MAX) + sequence;\n\n/**\n * Generate a random letter\n *\n * @param length - The length of the random string to generate\n * @param random - The random number generator\n * @returns A random letter\n */\nfunction createEntropy(length = 4, random = Math.random) {\n let entropy = \"\";\n\n while (entropy.length < length) {\n entropy += Math.floor(random() * CUID_LARGE_LENGTH).toString(\n CUID_LARGE_LENGTH\n );\n }\n return entropy;\n}\n\nexport interface FingerprintOptions {\n globalObj?: any;\n}\n\n/**\n * This is a fingerprint of the host environment. It is used to help prevent collisions when generating ids in a distributed system.\n *\n * @remarks\n * If no global object is available, you can pass in your own, or fall back on a random string.\n *\n * @param options - Options\n * @returns The environment's Fingerprint\n */\nfunction fingerprint(options?: FingerprintOptions): string {\n const globalObj =\n (options?.globalObj ?? typeof globalThis === \"undefined\")\n ? typeof globalThis === \"undefined\"\n ? {}\n : globalThis\n : globalThis;\n\n const globals = Object.keys(globalObj).toString();\n const sourceString =\n globals.length > 0\n ? globals + createEntropy(CUID_LARGE_LENGTH, Math.random)\n : createEntropy(CUID_LARGE_LENGTH, Math.random);\n\n return murmurhash(sourceString).slice(0, Math.max(0, CUID_LARGE_LENGTH));\n}\n\n/**\n * Generate a random CUID\n *\n * @example\n * ```typescript\n *\n * // Generate a random CUID\n * const id = cuid();\n * ```\n *\n * @returns A random CUID string\n */\nexport function cuid(): string {\n // If we're lucky, the `.toString(36)` calls may reduce hashing rounds\n // by shortening the input to the hash function a little.\n const time = Date.now().toString(CUID_LARGE_LENGTH);\n const count = counter.toString(CUID_LARGE_LENGTH);\n\n // The salt should be long enough to be globally unique across the full\n // length of the hash. For simplicity, we use the same length as the\n // intended id output.\n const salt = createEntropy(CUID_LARGE_LENGTH, Math.random);\n\n const hashed = murmurhash(`${time + salt + count + fingerprint()}`);\n\n return `${\n randomLetter() +\n hashed.slice(1, Math.min(hashed.length - 1, CUID_LARGE_LENGTH))\n }`;\n}\n"],"mappings":"kIAwBA,MAiBM,EAAU,KAAK,MAAM,KAAK,QAAQ,CAAG,UAAkB,CAL5C,EAcjB,SAAS,EAAc,EAAS,EAAG,EAAS,KAAK,OAAQ,CACvD,IAAI,EAAU,GAEd,KAAO,EAAQ,OAAS,GACtB,GAAW,KAAK,MAAM,GAAQ,CAAG,GAAkB,CAAC,SAClD,GACD,CAEH,OAAO,EAgBT,SAAS,EAAY,EAAsC,CACzD,IAAM,GACH,GAAS,WAAa,OAAO,WAAe,MACzC,OAAO,WAAe,IACpB,EAAE,CACF,WAGF,EAAU,OAAO,KAAK,EAAU,CAAC,UAAU,CAMjD,OAAO,EAJL,EAAQ,OAAS,EACb,EAAU,EAAc,GAAmB,KAAK,OAAO,CACvD,EAAc,GAAmB,KAAK,OAAO,CAEpB,CAAC,MAAM,EAAG,GAA+B,CAe1E,SAAgB,GAAe,CAG7B,IAAM,EAAO,KAAK,KAAK,CAAC,SAAS,GAAkB,CAC7C,EAAQ,EAAQ,SAAS,GAAkB,CAO3C,EAAS,EAAW,GAAG,EAFhB,EAAc,GAAmB,KAAK,OAAO,CAEf,EAAQ,GAAa,GAAG,CAEnE,MAAO,GACL,GAAc,CACd,EAAO,MAAM,EAAG,KAAK,IAAI,EAAO,OAAS,EAAG,GAAkB,CAAC"}
1
+ {"version":3,"file":"cuid.mjs","names":[],"sources":["../src/cuid.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\nimport { murmurhash } from \"@stryke/hash/neutral\";\nimport { randomLetter } from \"./random\";\n\n/**\n * ~22k hosts before 50% chance of initial counter collision with a remaining counter range of 9.0e+15 in JavaScript.\n */\nconst INITIAL_COUNT_MAX = 476_782_367;\n\n/**\n * The length of the CUID fingerprint.\n */\nconst CUID_LARGE_LENGTH = 36;\n\n/**\n * The sequence of the current running generator.\n *\n * @defaultValue 1\n */\nconst sequence = 1;\n\n/**\n * The counter used to help prevent collisions.\n */\nconst counter = Math.floor(Math.random() * INITIAL_COUNT_MAX) + sequence;\n\n/**\n * Generate a random letter\n *\n * @param length - The length of the random string to generate\n * @param random - The random number generator\n * @returns A random letter\n */\nfunction createEntropy(length = 4, random = Math.random) {\n let entropy = \"\";\n\n while (entropy.length < length) {\n entropy += Math.floor(random() * CUID_LARGE_LENGTH).toString(\n CUID_LARGE_LENGTH\n );\n }\n return entropy;\n}\n\nexport interface FingerprintOptions {\n globalObj?: any;\n}\n\n/**\n * This is a fingerprint of the host environment. It is used to help prevent collisions when generating ids in a distributed system.\n *\n * @remarks\n * If no global object is available, you can pass in your own, or fall back on a random string.\n *\n * @param options - Options\n * @returns The environment's Fingerprint\n */\nfunction fingerprint(options?: FingerprintOptions): string {\n const globalObj =\n (options?.globalObj ?? typeof globalThis === \"undefined\")\n ? typeof globalThis === \"undefined\"\n ? {}\n : globalThis\n : globalThis;\n\n const globals = Object.keys(globalObj).toString();\n const sourceString =\n globals.length > 0\n ? globals + createEntropy(CUID_LARGE_LENGTH, Math.random)\n : createEntropy(CUID_LARGE_LENGTH, Math.random);\n\n return murmurhash(sourceString).slice(0, Math.max(0, CUID_LARGE_LENGTH));\n}\n\n/**\n * Generate a random CUID\n *\n * @example\n * ```typescript\n *\n * // Generate a random CUID\n * const id = cuid();\n * ```\n *\n * @returns A random CUID string\n */\nexport function cuid(): string {\n // If we're lucky, the `.toString(36)` calls may reduce hashing rounds\n // by shortening the input to the hash function a little.\n const time = Date.now().toString(CUID_LARGE_LENGTH);\n const count = counter.toString(CUID_LARGE_LENGTH);\n\n // The salt should be long enough to be globally unique across the full\n // length of the hash. For simplicity, we use the same length as the\n // intended id output.\n const salt = createEntropy(CUID_LARGE_LENGTH, Math.random);\n\n const hashed = murmurhash(`${time + salt + count + fingerprint()}`);\n\n return `${\n randomLetter() +\n hashed.slice(1, Math.min(hashed.length - 1, CUID_LARGE_LENGTH))\n }`;\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,oBAAoB;;;;AAK1B,MAAM,oBAAoB;;;;AAY1B,MAAM,UAAU,KAAK,MAAM,KAAK,QAAQ,GAAG,kBAAkB,GAL5C;;;;;;;;AAcjB,SAAS,cAAc,SAAS,GAAG,SAAS,KAAK,QAAQ;CACvD,IAAI,UAAU;AAEd,QAAO,QAAQ,SAAS,OACtB,YAAW,KAAK,MAAM,QAAQ,GAAG,kBAAkB,CAAC,SAClD,kBACD;AAEH,QAAO;;;;;;;;;;;AAgBT,SAAS,YAAY,SAAsC;CACzD,MAAM,YACH,SAAS,aAAa,OAAO,eAAe,cACzC,OAAO,eAAe,cACpB,EAAE,GACF,aACF;CAEN,MAAM,UAAU,OAAO,KAAK,UAAU,CAAC,UAAU;AAMjD,QAAO,WAJL,QAAQ,SAAS,IACb,UAAU,cAAc,mBAAmB,KAAK,OAAO,GACvD,cAAc,mBAAmB,KAAK,OAAO,CAEpB,CAAC,MAAM,GAAG,KAAK,IAAI,GAAG,kBAAkB,CAAC;;;;;;;;;;;;;;AAe1E,SAAgB,OAAe;CAG7B,MAAM,OAAO,KAAK,KAAK,CAAC,SAAS,kBAAkB;CACnD,MAAM,QAAQ,QAAQ,SAAS,kBAAkB;CAOjD,MAAM,SAAS,WAAW,GAAG,OAFhB,cAAc,mBAAmB,KAAK,OAAO,GAEf,QAAQ,aAAa,GAAG;AAEnE,QAAO,GACL,cAAc,GACd,OAAO,MAAM,GAAG,KAAK,IAAI,OAAO,SAAS,GAAG,kBAAkB,CAAC"}
@@ -1 +1,4 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`);require(`../../type-checks/src/index.cjs`),require(`defu`),require(`glob`);
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ require('../../type-checks/src/index.cjs');
3
+ require("defu");
4
+ require("glob");
@@ -1 +1,5 @@
1
- import"../../type-checks/src/index.mjs";import"defu";import"glob";export{};
1
+ import "../../type-checks/src/index.mjs";
2
+ import "defu";
3
+ import "glob";
4
+
5
+ export { };
@@ -1 +1 @@
1
- require(`../../convert/src/neutral.cjs`);
1
+ require('../../convert/src/neutral.cjs');
@@ -1 +1,3 @@
1
- import"../../convert/src/neutral.mjs";export{};
1
+ import "../../convert/src/neutral.mjs";
2
+
3
+ export { };
@@ -1 +1,2 @@
1
- require(`../../fs/src/list-files.cjs`),require(`./murmurhash.cjs`);
1
+ require('../../fs/src/list-files.cjs');
2
+ require('./murmurhash.cjs');
@@ -1 +1,4 @@
1
- import"../../fs/src/list-files.mjs";import"./murmurhash.mjs";export{};
1
+ import "../../fs/src/list-files.mjs";
2
+ import "./murmurhash.mjs";
3
+
4
+ export { };
@@ -1 +1,22 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`ohash`);function n(e,n){let r=(0,t.hash)(e),i=n?.maxLength??32;return r.length>i?r.slice(0,i):r}exports.murmurhash=n;
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ let ohash = require("ohash");
3
+
4
+ //#region ../hash/src/murmurhash.ts
5
+ /**
6
+ * Use a [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash) based algorithm to hash any JS value into a string.
7
+ *
8
+ * @see https://github.com/ohash/ohash
9
+ * @see https://en.wikipedia.org/wiki/MurmurHash
10
+ *
11
+ * @param content - The value to hash
12
+ * @param options - Hashing options
13
+ * @returns A hashed string value
14
+ */
15
+ function murmurhash(content, options) {
16
+ const result = (0, ohash.hash)(content);
17
+ const maxLength = options?.maxLength ?? 32;
18
+ return result.length > maxLength ? result.slice(0, maxLength) : result;
19
+ }
20
+
21
+ //#endregion
22
+ exports.murmurhash = murmurhash;
@@ -1,2 +1,22 @@
1
- import{hash as e}from"ohash";function t(t,n){let r=e(t),i=n?.maxLength??32;return r.length>i?r.slice(0,i):r}export{t as murmurhash};
1
+ import { hash } from "ohash";
2
+
3
+ //#region ../hash/src/murmurhash.ts
4
+ /**
5
+ * Use a [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash) based algorithm to hash any JS value into a string.
6
+ *
7
+ * @see https://github.com/ohash/ohash
8
+ * @see https://en.wikipedia.org/wiki/MurmurHash
9
+ *
10
+ * @param content - The value to hash
11
+ * @param options - Hashing options
12
+ * @returns A hashed string value
13
+ */
14
+ function murmurhash(content, options) {
15
+ const result = hash(content);
16
+ const maxLength = options?.maxLength ?? 32;
17
+ return result.length > maxLength ? result.slice(0, maxLength) : result;
18
+ }
19
+
20
+ //#endregion
21
+ export { murmurhash };
2
22
  //# sourceMappingURL=murmurhash.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"murmurhash.mjs","names":["ohash"],"sources":["../../../../hash/src/murmurhash.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\nimport { hash as ohash } from \"ohash\";\n\nexport interface HashOptions {\n /**\n * The maximum length of the hash\n *\n * @defaultValue 32\n */\n maxLength?: number;\n}\n\n/**\n * Use a [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash) based algorithm to hash any JS value into a string.\n *\n * @see https://github.com/ohash/ohash\n * @see https://en.wikipedia.org/wiki/MurmurHash\n *\n * @param content - The value to hash\n * @param options - Hashing options\n * @returns A hashed string value\n */\nexport function murmurhash(content: any, options?: HashOptions): string {\n const result = ohash(content);\n const maxLength = options?.maxLength ?? 32;\n\n return result.length > maxLength ? result.slice(0, maxLength) : result;\n}\n"],"mappings":"6BAuCA,SAAgB,EAAW,EAAc,EAA+B,CACtE,IAAM,EAASA,EAAM,EAAQ,CACvB,EAAY,GAAS,WAAa,GAExC,OAAO,EAAO,OAAS,EAAY,EAAO,MAAM,EAAG,EAAU,CAAG"}
1
+ {"version":3,"file":"murmurhash.mjs","names":["ohash"],"sources":["../../../../hash/src/murmurhash.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\nimport { hash as ohash } from \"ohash\";\n\nexport interface HashOptions {\n /**\n * The maximum length of the hash\n *\n * @defaultValue 32\n */\n maxLength?: number;\n}\n\n/**\n * Use a [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash) based algorithm to hash any JS value into a string.\n *\n * @see https://github.com/ohash/ohash\n * @see https://en.wikipedia.org/wiki/MurmurHash\n *\n * @param content - The value to hash\n * @param options - Hashing options\n * @returns A hashed string value\n */\nexport function murmurhash(content: any, options?: HashOptions): string {\n const result = ohash(content);\n const maxLength = options?.maxLength ?? 32;\n\n return result.length > maxLength ? result.slice(0, maxLength) : result;\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,SAAgB,WAAW,SAAc,SAA+B;CACtE,MAAM,SAASA,KAAM,QAAQ;CAC7B,MAAM,YAAY,SAAS,aAAa;AAExC,QAAO,OAAO,SAAS,YAAY,OAAO,MAAM,GAAG,UAAU,GAAG"}
@@ -1 +1,4 @@
1
- require(`./digest.cjs`);const e=require(`./murmurhash.cjs`);require(`./hash-files.cjs`),require(`./xx-hash.cjs`);
1
+ require('./digest.cjs');
2
+ const require_murmurhash = require('./murmurhash.cjs');
3
+ require('./hash-files.cjs');
4
+ require('./xx-hash.cjs');
@@ -1 +1,6 @@
1
- import"./digest.mjs";import{murmurhash as e}from"./murmurhash.mjs";import"./hash-files.mjs";import"./xx-hash.mjs";export{};
1
+ import "./digest.mjs";
2
+ import { murmurhash } from "./murmurhash.mjs";
3
+ import "./hash-files.mjs";
4
+ import "./xx-hash.mjs";
5
+
6
+ export { };
@@ -1 +1 @@
1
- require(`js-xxhash`);
1
+ require("js-xxhash");
@@ -1 +1,3 @@
1
- import"js-xxhash";export{};
1
+ import "js-xxhash";
2
+
3
+ export { };
package/dist/index.cjs CHANGED
@@ -1 +1,18 @@
1
- const e=require(`./random.cjs`),t=require(`./cuid.cjs`),n=require(`./nanoid-client.cjs`),r=require(`./snowflake.cjs`),i=require(`./uuid.cjs`);exports.DEFAULT_EPOCH=r.DEFAULT_EPOCH,exports.DEFAULT_SHARD_ID=r.DEFAULT_SHARD_ID,exports.cuid=t.cuid,exports.deconstructSnowflake=r.deconstructSnowflake,exports.getNonCryptoRandomValues=e.getNonCryptoRandomValues,exports.isValidSnowflake=r.isValidSnowflake,exports.nanoid=n.nanoid,exports.randomCharacters=e.randomCharacters,exports.randomInteger=e.randomInteger,exports.randomLetter=e.randomLetter,exports.snowflake=r.snowflake,exports.uuid=i.uuid;
1
+ const require_random = require('./random.cjs');
2
+ const require_cuid = require('./cuid.cjs');
3
+ const require_nanoid_client = require('./nanoid-client.cjs');
4
+ const require_snowflake = require('./snowflake.cjs');
5
+ const require_uuid = require('./uuid.cjs');
6
+
7
+ exports.DEFAULT_EPOCH = require_snowflake.DEFAULT_EPOCH;
8
+ exports.DEFAULT_SHARD_ID = require_snowflake.DEFAULT_SHARD_ID;
9
+ exports.cuid = require_cuid.cuid;
10
+ exports.deconstructSnowflake = require_snowflake.deconstructSnowflake;
11
+ exports.getNonCryptoRandomValues = require_random.getNonCryptoRandomValues;
12
+ exports.isValidSnowflake = require_snowflake.isValidSnowflake;
13
+ exports.nanoid = require_nanoid_client.nanoid;
14
+ exports.randomCharacters = require_random.randomCharacters;
15
+ exports.randomInteger = require_random.randomInteger;
16
+ exports.randomLetter = require_random.randomLetter;
17
+ exports.snowflake = require_snowflake.snowflake;
18
+ exports.uuid = require_uuid.uuid;
package/dist/index.mjs CHANGED
@@ -1 +1,7 @@
1
- import{getNonCryptoRandomValues as e,randomCharacters as t,randomInteger as n,randomLetter as r}from"./random.mjs";import{cuid as i}from"./cuid.mjs";import{nanoid as a}from"./nanoid-client.mjs";import{DEFAULT_EPOCH as o,DEFAULT_SHARD_ID as s,deconstructSnowflake as c,isValidSnowflake as l,snowflake as u}from"./snowflake.mjs";import{uuid as d}from"./uuid.mjs";export{o as DEFAULT_EPOCH,s as DEFAULT_SHARD_ID,i as cuid,c as deconstructSnowflake,e as getNonCryptoRandomValues,l as isValidSnowflake,a as nanoid,t as randomCharacters,n as randomInteger,r as randomLetter,u as snowflake,d as uuid};
1
+ import { getNonCryptoRandomValues, randomCharacters, randomInteger, randomLetter } from "./random.mjs";
2
+ import { cuid } from "./cuid.mjs";
3
+ import { nanoid } from "./nanoid-client.mjs";
4
+ import { DEFAULT_EPOCH, DEFAULT_SHARD_ID, deconstructSnowflake, isValidSnowflake, snowflake } from "./snowflake.mjs";
5
+ import { uuid } from "./uuid.mjs";
6
+
7
+ export { DEFAULT_EPOCH, DEFAULT_SHARD_ID, cuid, deconstructSnowflake, getNonCryptoRandomValues, isValidSnowflake, nanoid, randomCharacters, randomInteger, randomLetter, snowflake, uuid };
@@ -1 +1,22 @@
1
- const e=require(`./random.cjs`);function t(t=21){return e.getNonCryptoRandomValues(new Uint8Array(t)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+=`-`:e+=`_`,e),``)}exports.nanoid=t;
1
+ const require_random = require('./random.cjs');
2
+
3
+ //#region src/nanoid-client.ts
4
+ /**
5
+ * A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.
6
+ *
7
+ * @param size - The size of the string to generate
8
+ * @returns A unique identifier following the nanoid format
9
+ */
10
+ function nanoid(size = 21) {
11
+ return require_random.getNonCryptoRandomValues(new Uint8Array(size)).reduce((id, byte) => {
12
+ byte &= 63;
13
+ if (byte < 36) id += byte.toString(36);
14
+ else if (byte < 62) id += (byte - 26).toString(36).toUpperCase();
15
+ else if (byte > 62) id += "-";
16
+ else id += "_";
17
+ return id;
18
+ }, "");
19
+ }
20
+
21
+ //#endregion
22
+ exports.nanoid = nanoid;
@@ -1,2 +1,23 @@
1
- import{getNonCryptoRandomValues as e}from"./random.mjs";function t(t=21){return e(new Uint8Array(t)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+=`-`:e+=`_`,e),``)}export{t as nanoid};
1
+ import { getNonCryptoRandomValues } from "./random.mjs";
2
+
3
+ //#region src/nanoid-client.ts
4
+ /**
5
+ * A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.
6
+ *
7
+ * @param size - The size of the string to generate
8
+ * @returns A unique identifier following the nanoid format
9
+ */
10
+ function nanoid(size = 21) {
11
+ return getNonCryptoRandomValues(new Uint8Array(size)).reduce((id, byte) => {
12
+ byte &= 63;
13
+ if (byte < 36) id += byte.toString(36);
14
+ else if (byte < 62) id += (byte - 26).toString(36).toUpperCase();
15
+ else if (byte > 62) id += "-";
16
+ else id += "_";
17
+ return id;
18
+ }, "");
19
+ }
20
+
21
+ //#endregion
22
+ export { nanoid };
2
23
  //# sourceMappingURL=nanoid-client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"nanoid-client.mjs","names":[],"sources":["../src/nanoid-client.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\nimport { getNonCryptoRandomValues } from \"./random\";\n\n// This is taken from https://github.com/ai/nanoid/blob/main/index.browser.js We\n// copy this because we want to use `--platform=neutral` which doesn't work with\n// the npm package.\n// Also we changed the random number generator to use Math.random() for compat\n// with React Native.\n\n/**\n * A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.\n *\n * @param size - The size of the string to generate\n * @returns A unique identifier following the nanoid format\n */\nexport function nanoid(size = 21): string {\n // Use our custom getRandomValues function to fill a Uint8Array with random values.\n const randomBytes = getNonCryptoRandomValues(new Uint8Array(size));\n\n return randomBytes.reduce((id, byte) => {\n // It is incorrect to use bytes exceeding the alphabet size.\n // The following mask reduces the random byte in the 0-255 value\n // range to the 0-63 value range. Therefore, adding hacks, such\n // as empty string fallback or magic numbers, is unnecessary because\n // the bitmask trims bytes down to the alphabet size.\n byte &= 63;\n if (byte < 36) {\n // `0-9a-z`\n id += byte.toString(36);\n } else if (byte < 62) {\n // `A-Z`\n id += (byte - 26).toString(36).toUpperCase();\n } else if (byte > 62) {\n id += \"-\";\n } else {\n id += \"_\";\n }\n return id;\n }, \"\");\n}\n"],"mappings":"wDAgCA,SAAgB,EAAO,EAAO,GAAY,CAIxC,OAFoB,EAAyB,IAAI,WAAW,EAAK,CAAC,CAE/C,QAAQ,EAAI,KAM7B,GAAQ,GACJ,EAAO,GAET,GAAM,EAAK,SAAS,GAAG,CACd,EAAO,GAEhB,IAAO,EAAO,IAAI,SAAS,GAAG,CAAC,aAAa,CACnC,EAAO,GAChB,GAAM,IAEN,GAAM,IAED,GACN,GAAG"}
1
+ {"version":3,"file":"nanoid-client.mjs","names":[],"sources":["../src/nanoid-client.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\nimport { getNonCryptoRandomValues } from \"./random\";\n\n// This is taken from https://github.com/ai/nanoid/blob/main/index.browser.js We\n// copy this because we want to use `--platform=neutral` which doesn't work with\n// the npm package.\n// Also we changed the random number generator to use Math.random() for compat\n// with React Native.\n\n/**\n * A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.\n *\n * @param size - The size of the string to generate\n * @returns A unique identifier following the nanoid format\n */\nexport function nanoid(size = 21): string {\n // Use our custom getRandomValues function to fill a Uint8Array with random values.\n const randomBytes = getNonCryptoRandomValues(new Uint8Array(size));\n\n return randomBytes.reduce((id, byte) => {\n // It is incorrect to use bytes exceeding the alphabet size.\n // The following mask reduces the random byte in the 0-255 value\n // range to the 0-63 value range. Therefore, adding hacks, such\n // as empty string fallback or magic numbers, is unnecessary because\n // the bitmask trims bytes down to the alphabet size.\n byte &= 63;\n if (byte < 36) {\n // `0-9a-z`\n id += byte.toString(36);\n } else if (byte < 62) {\n // `A-Z`\n id += (byte - 26).toString(36).toUpperCase();\n } else if (byte > 62) {\n id += \"-\";\n } else {\n id += \"_\";\n }\n return id;\n }, \"\");\n}\n"],"mappings":";;;;;;;;;AAgCA,SAAgB,OAAO,OAAO,IAAY;AAIxC,QAFoB,yBAAyB,IAAI,WAAW,KAAK,CAAC,CAE/C,QAAQ,IAAI,SAAS;AAMtC,UAAQ;AACR,MAAI,OAAO,GAET,OAAM,KAAK,SAAS,GAAG;WACd,OAAO,GAEhB,QAAO,OAAO,IAAI,SAAS,GAAG,CAAC,aAAa;WACnC,OAAO,GAChB,OAAM;MAEN,OAAM;AAER,SAAO;IACN,GAAG"}
package/dist/random.cjs CHANGED
@@ -1 +1,52 @@
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}exports.getNonCryptoRandomValues=r,exports.randomCharacters=i,exports.randomInteger=t,exports.randomLetter=n;
1
+
2
+ //#region src/random.ts
3
+ const alphabet = Array.from({ length: 26 }, (_x, i) => String.fromCodePoint(i + 97));
4
+ /**
5
+ * Generate a random integer
6
+ *
7
+ * @param maximum - The maximum value (inclusive)
8
+ * @param minimum - The minimum value (inclusive)
9
+ * @returns A random integer
10
+ */
11
+ const randomInteger = (maximum, minimum = 0) => Math.floor(Math.random() * (maximum - minimum + 1) + minimum);
12
+ /**
13
+ * Generate a random letter
14
+ *
15
+ * @param random - The random number generator
16
+ * @returns A random letter
17
+ */
18
+ const randomLetter = (random = Math.random) => alphabet[Math.floor(random() * alphabet.length)];
19
+ /**
20
+ * Generate a random string
21
+ *
22
+ * @param array - The array to fill with random values
23
+ * @returns The array filled with random values
24
+ */
25
+ function getNonCryptoRandomValues(array) {
26
+ if (array === null) throw new TypeError("array cannot be null");
27
+ for (let i = 0; i < array.length; i++) array[i] = Math.floor(Math.random() * 256);
28
+ return array;
29
+ }
30
+ /**
31
+ * Generate a series of random characters
32
+ *
33
+ * @param length - The length of the random characters
34
+ * @returns A series of random characters
35
+ */
36
+ function randomCharacters(length) {
37
+ let result = "";
38
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
39
+ const charactersLength = 62;
40
+ let counter = 0;
41
+ while (counter < length) {
42
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
43
+ counter += 1;
44
+ }
45
+ return result;
46
+ }
47
+
48
+ //#endregion
49
+ exports.getNonCryptoRandomValues = getNonCryptoRandomValues;
50
+ exports.randomCharacters = randomCharacters;
51
+ exports.randomInteger = randomInteger;
52
+ exports.randomLetter = randomLetter;
package/dist/random.mjs CHANGED
@@ -1,2 +1,49 @@
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{r as getNonCryptoRandomValues,i as randomCharacters,t as randomInteger,n as randomLetter};
1
+ //#region src/random.ts
2
+ const alphabet = Array.from({ length: 26 }, (_x, i) => String.fromCodePoint(i + 97));
3
+ /**
4
+ * Generate a random integer
5
+ *
6
+ * @param maximum - The maximum value (inclusive)
7
+ * @param minimum - The minimum value (inclusive)
8
+ * @returns A random integer
9
+ */
10
+ const randomInteger = (maximum, minimum = 0) => Math.floor(Math.random() * (maximum - minimum + 1) + minimum);
11
+ /**
12
+ * Generate a random letter
13
+ *
14
+ * @param random - The random number generator
15
+ * @returns A random letter
16
+ */
17
+ const randomLetter = (random = Math.random) => alphabet[Math.floor(random() * alphabet.length)];
18
+ /**
19
+ * Generate a random string
20
+ *
21
+ * @param array - The array to fill with random values
22
+ * @returns The array filled with random values
23
+ */
24
+ function getNonCryptoRandomValues(array) {
25
+ if (array === null) throw new TypeError("array cannot be null");
26
+ for (let i = 0; i < array.length; i++) array[i] = Math.floor(Math.random() * 256);
27
+ return array;
28
+ }
29
+ /**
30
+ * Generate a series of random characters
31
+ *
32
+ * @param length - The length of the random characters
33
+ * @returns A series of random characters
34
+ */
35
+ function randomCharacters(length) {
36
+ let result = "";
37
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
38
+ const charactersLength = 62;
39
+ let counter = 0;
40
+ while (counter < length) {
41
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
42
+ counter += 1;
43
+ }
44
+ return result;
45
+ }
46
+
47
+ //#endregion
48
+ export { getNonCryptoRandomValues, randomCharacters, randomInteger, randomLetter };
2
49
  //# sourceMappingURL=random.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.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"}
1
+ {"version":3,"file":"random.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,WAAW,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,IAAI,MAC/C,OAAO,cAAc,IAAI,GAAG,CAC7B;;;;;;;;AASD,MAAa,iBAAiB,SAAiB,UAAU,MACvD,KAAK,MAAM,KAAK,QAAQ,IAAI,UAAU,UAAU,KAAK,QAAQ;;;;;;;AAQ/D,MAAa,gBAAgB,SAAuB,KAAK,WACvD,SAAS,KAAK,MAAM,QAAQ,GAAG,SAAS,OAAO;;;;;;;AAQjD,SAAgB,yBAAyB,OAAmB;AAC1D,KAAI,UAAU,KACZ,OAAM,IAAI,UAAU,uBAAuB;AAI7C,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,OAAM,KAAK,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AAG5C,QAAO;;;;;;;;AAST,SAAgB,iBAAiB,QAAgB;CAC/C,IAAI,SAAS;CACb,MAAM,aACJ;CACF,MAAM,mBAAmB;CACzB,IAAI,UAAU;AACd,QAAO,UAAU,QAAQ;AACvB,YAAU,WAAW,OAAO,KAAK,MAAM,KAAK,QAAQ,GAAG,iBAAiB,CAAC;AACzE,aAAW;;AAEb,QAAO"}
@@ -1 +1,100 @@
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}}exports.DEFAULT_EPOCH=t,exports.DEFAULT_SHARD_ID=1,exports.deconstructSnowflake=o,exports.isValidSnowflake=s,exports.snowflake=a;
1
+
2
+ //#region src/snowflake.ts
3
+ const DEFAULT_SHARD_ID = 1;
4
+ const DEFAULT_EPOCH = Date.UTC(1970, 0, 1).valueOf();
5
+ /**
6
+ * The sequence of the current running generator.
7
+ *
8
+ * @defaultValue 1
9
+ */
10
+ let sequence = 1;
11
+ /**
12
+ * Transform a snowflake into its 64Bit binary string.
13
+ *
14
+ * @param snowflake - Snowflake to transform
15
+ * @returns A 64Bit binary string
16
+ */
17
+ function ToBinaryString(snowflake$1) {
18
+ const cached64BitZeros = "0000000000000000000000000000000000000000000000000000000000000000";
19
+ const binValue = BigInt(snowflake$1).toString(2);
20
+ return binValue.length < 64 ? cached64BitZeros.slice(0, Math.max(0, 64 - binValue.length)) + binValue : binValue;
21
+ }
22
+ /**
23
+ * Extract bits and their values from a snowflake.
24
+ *
25
+ * @param snowflake - Snowflake to extract from
26
+ * @param start - The starting index to extract bits from
27
+ * @param length - Number of bits to extract before stopping
28
+ * @returns A bigint value of the extracted bits
29
+ */
30
+ function extractBits(snowflake$1, start, length) {
31
+ return Number.parseInt(length ? ToBinaryString(snowflake$1).slice(start, start + length) : ToBinaryString(snowflake$1).slice(Math.max(0, start)), 2);
32
+ }
33
+ /**
34
+ * Generate a snowflake identifier.
35
+ *
36
+ * @remarks
37
+ * Snowflakes are 64-bit unsigned integers that are roughly time-ordered.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ *
42
+ * // Generate a snowflake with the default options
43
+ * const id1 = snowflake();
44
+ *
45
+ * // Generate a snowflake with a custom shard id
46
+ * const id2 = snowflake({ shardId: 2 });
47
+ *
48
+ * // Generate a snowflake with a custom shard id and timestamp
49
+ * const id3 = snowflake({ shardId: 3, timestamp: new Date("2021-01-01") });
50
+ *
51
+ * ```
52
+ *
53
+ * @param options - The options to use when generating the snowflake
54
+ * @returns A snowflake
55
+ */
56
+ function snowflake(options = {}) {
57
+ const { shardId, epoch, timestamp } = options ?? {};
58
+ let result = BigInt(timestamp ? timestamp instanceof Date ? timestamp.valueOf() : new Date(timestamp).valueOf() : Date.now()) - BigInt(epoch ?? DEFAULT_EPOCH) << BigInt(22);
59
+ result |= BigInt((shardId ?? DEFAULT_SHARD_ID) % 1024) << BigInt(12);
60
+ result |= BigInt(sequence++ % 4096);
61
+ return result.toString();
62
+ }
63
+ /**
64
+ * Deconstruct a snowflake to its values using the `epoch`.
65
+ *
66
+ * @param snowflake - Snowflake to deconstruct
67
+ * @returns Either the DeconstructedSnowflake object
68
+ */
69
+ function deconstructSnowflake(snowflake$1) {
70
+ const binary = ToBinaryString(snowflake$1);
71
+ return {
72
+ snowflake: snowflake$1,
73
+ timestamp: extractBits(snowflake$1, 1, 41),
74
+ shard_id: extractBits(snowflake$1, 42, 10),
75
+ sequence: extractBits(snowflake$1, 52),
76
+ binary
77
+ };
78
+ }
79
+ /**
80
+ * Check if a snowflake string Id is valid.
81
+ *
82
+ * @param snowflake - Snowflake to check
83
+ * @returns Whether the snowflake is valid
84
+ */
85
+ function isValidSnowflake(snowflake$1) {
86
+ if (!/^\d{19}$/.test(snowflake$1)) return false;
87
+ try {
88
+ deconstructSnowflake(snowflake$1);
89
+ return true;
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
94
+
95
+ //#endregion
96
+ exports.DEFAULT_EPOCH = DEFAULT_EPOCH;
97
+ exports.DEFAULT_SHARD_ID = DEFAULT_SHARD_ID;
98
+ exports.deconstructSnowflake = deconstructSnowflake;
99
+ exports.isValidSnowflake = isValidSnowflake;
100
+ exports.snowflake = snowflake;
@@ -1,2 +1,96 @@
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{t as DEFAULT_EPOCH,e as DEFAULT_SHARD_ID,o as deconstructSnowflake,s as isValidSnowflake,a as snowflake};
1
+ //#region src/snowflake.ts
2
+ const DEFAULT_SHARD_ID = 1;
3
+ const DEFAULT_EPOCH = Date.UTC(1970, 0, 1).valueOf();
4
+ /**
5
+ * The sequence of the current running generator.
6
+ *
7
+ * @defaultValue 1
8
+ */
9
+ let sequence = 1;
10
+ /**
11
+ * Transform a snowflake into its 64Bit binary string.
12
+ *
13
+ * @param snowflake - Snowflake to transform
14
+ * @returns A 64Bit binary string
15
+ */
16
+ function ToBinaryString(snowflake$1) {
17
+ const cached64BitZeros = "0000000000000000000000000000000000000000000000000000000000000000";
18
+ const binValue = BigInt(snowflake$1).toString(2);
19
+ return binValue.length < 64 ? cached64BitZeros.slice(0, Math.max(0, 64 - binValue.length)) + binValue : binValue;
20
+ }
21
+ /**
22
+ * Extract bits and their values from a snowflake.
23
+ *
24
+ * @param snowflake - Snowflake to extract from
25
+ * @param start - The starting index to extract bits from
26
+ * @param length - Number of bits to extract before stopping
27
+ * @returns A bigint value of the extracted bits
28
+ */
29
+ function extractBits(snowflake$1, start, length) {
30
+ return Number.parseInt(length ? ToBinaryString(snowflake$1).slice(start, start + length) : ToBinaryString(snowflake$1).slice(Math.max(0, start)), 2);
31
+ }
32
+ /**
33
+ * Generate a snowflake identifier.
34
+ *
35
+ * @remarks
36
+ * Snowflakes are 64-bit unsigned integers that are roughly time-ordered.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ *
41
+ * // Generate a snowflake with the default options
42
+ * const id1 = snowflake();
43
+ *
44
+ * // Generate a snowflake with a custom shard id
45
+ * const id2 = snowflake({ shardId: 2 });
46
+ *
47
+ * // Generate a snowflake with a custom shard id and timestamp
48
+ * const id3 = snowflake({ shardId: 3, timestamp: new Date("2021-01-01") });
49
+ *
50
+ * ```
51
+ *
52
+ * @param options - The options to use when generating the snowflake
53
+ * @returns A snowflake
54
+ */
55
+ function snowflake(options = {}) {
56
+ const { shardId, epoch, timestamp } = options ?? {};
57
+ let result = BigInt(timestamp ? timestamp instanceof Date ? timestamp.valueOf() : new Date(timestamp).valueOf() : Date.now()) - BigInt(epoch ?? DEFAULT_EPOCH) << BigInt(22);
58
+ result |= BigInt((shardId ?? DEFAULT_SHARD_ID) % 1024) << BigInt(12);
59
+ result |= BigInt(sequence++ % 4096);
60
+ return result.toString();
61
+ }
62
+ /**
63
+ * Deconstruct a snowflake to its values using the `epoch`.
64
+ *
65
+ * @param snowflake - Snowflake to deconstruct
66
+ * @returns Either the DeconstructedSnowflake object
67
+ */
68
+ function deconstructSnowflake(snowflake$1) {
69
+ const binary = ToBinaryString(snowflake$1);
70
+ return {
71
+ snowflake: snowflake$1,
72
+ timestamp: extractBits(snowflake$1, 1, 41),
73
+ shard_id: extractBits(snowflake$1, 42, 10),
74
+ sequence: extractBits(snowflake$1, 52),
75
+ binary
76
+ };
77
+ }
78
+ /**
79
+ * Check if a snowflake string Id is valid.
80
+ *
81
+ * @param snowflake - Snowflake to check
82
+ * @returns Whether the snowflake is valid
83
+ */
84
+ function isValidSnowflake(snowflake$1) {
85
+ if (!/^\d{19}$/.test(snowflake$1)) return false;
86
+ try {
87
+ deconstructSnowflake(snowflake$1);
88
+ return true;
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+
94
+ //#endregion
95
+ export { DEFAULT_EPOCH, DEFAULT_SHARD_ID, deconstructSnowflake, isValidSnowflake, snowflake };
2
96
  //# sourceMappingURL=snowflake.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"snowflake.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"}
1
+ {"version":3,"file":"snowflake.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,mBAAmB;AAChC,MAAaA,gBAAwB,KAAK,IAAI,MAAM,GAAG,EAAE,CAAC,SAAS;;;;;;AAOnE,IAAI,WAAW;;;;;;;AAQf,SAAS,eAAe,aAAwC;CAC9D,MAAM,mBACJ;CACF,MAAM,WAAW,OAAOC,YAAU,CAAC,SAAS,EAAE;AAE9C,QAAO,SAAS,SAAS,KACrB,iBAAiB,MAAM,GAAG,KAAK,IAAI,GAAG,KAAK,SAAS,OAAO,CAAC,GAAG,WAC/D;;;;;;;;;;AAWN,SAAS,YACP,aACA,OACA,QACQ;AACR,QAAO,OAAO,SACZ,SACI,eAAeA,YAAU,CAAC,MAAM,OAAO,QAAQ,OAAO,GACtD,eAAeA,YAAU,CAAC,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC,EACvD,EACD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,SAAgB,UAAU,UAAqC,EAAE,EAAU;CACzE,MAAM,EAAE,SAAS,OAAO,cAAc,WAAW,EAAE;CAEnD,IAAI,SACD,OACC,YACI,qBAAqB,OACnB,UAAU,SAAS,GACnB,IAAI,KAAK,UAAU,CAAC,SAAS,GAC/B,KAAK,KAAK,CACf,GACC,OAAO,SAAS,cAAc,IAChC,OAAO,GAAG;AAEZ,WAAU,QAAQ,WAAW,oBAAoB,KAAK,IAAI,OAAO,GAAG;AACpE,WAAU,OAAO,aAAa,KAAK;AAEnC,QAAO,OAAO,UAAU;;;;;;;;AAS1B,SAAgB,qBACd,aACwB;CACxB,MAAM,SAAS,eAAeA,YAAU;AAExC,QAAO;EACL;EACA,WAAW,YAAYA,aAAW,GAAG,GAAG;EACxC,UAAU,YAAYA,aAAW,IAAI,GAAG;EACxC,UAAU,YAAYA,aAAW,GAAG;EACpC;EACD;;;;;;;;AASH,SAAgB,iBAAiB,aAA4B;AAC3D,KAAI,CAAC,WAAW,KAAKA,YAAU,CAC7B,QAAO;AAGT,KAAI;AACF,uBAAqBA,YAAU;AAE/B,SAAO;SACD;AACN,SAAO"}
@@ -1 +1,3 @@
1
- const e=require(`./is-buffer.cjs`);require(`./type-detect.cjs`),require(`./is-collection.cjs`);
1
+ const require_is_buffer = require('./is-buffer.cjs');
2
+ require('./type-detect.cjs');
3
+ require('./is-collection.cjs');
@@ -1 +1,5 @@
1
- import{isBufferExists as e}from"./is-buffer.mjs";import"./type-detect.mjs";import"./is-collection.mjs";export{};
1
+ import { isBufferExists } from "./is-buffer.mjs";
2
+ import "./type-detect.mjs";
3
+ import "./is-collection.mjs";
4
+
5
+ export { };
@@ -1 +1,12 @@
1
- const e=typeof Buffer<`u`,t=e?Buffer.isBuffer.bind(Buffer):function(e){return!1};exports.isBufferExists=e;
1
+
2
+ //#region ../type-checks/src/is-buffer.ts
3
+ const isBufferExists = typeof Buffer !== "undefined";
4
+ /**
5
+ * Check if the provided value's type is `Buffer`
6
+ */
7
+ const isBuffer = isBufferExists ? Buffer.isBuffer.bind(Buffer) : function isBuffer$1(value) {
8
+ return false;
9
+ };
10
+
11
+ //#endregion
12
+ exports.isBufferExists = isBufferExists;
@@ -1,2 +1,12 @@
1
- const e=typeof Buffer<`u`;e&&Buffer.isBuffer.bind(Buffer);export{e as isBufferExists};
1
+ //#region ../type-checks/src/is-buffer.ts
2
+ const isBufferExists = typeof Buffer !== "undefined";
3
+ /**
4
+ * Check if the provided value's type is `Buffer`
5
+ */
6
+ const isBuffer = isBufferExists ? Buffer.isBuffer.bind(Buffer) : function isBuffer$1(value) {
7
+ return false;
8
+ };
9
+
10
+ //#endregion
11
+ export { isBufferExists };
2
12
  //# sourceMappingURL=is-buffer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-buffer.mjs","names":["isBuffer: typeof Buffer.isBuffer","isBuffer"],"sources":["../../../../type-checks/src/is-buffer.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\nexport const isBufferExists = typeof Buffer !== \"undefined\";\n\n/**\n * Check if the provided value's type is `Buffer`\n */\nexport const isBuffer: typeof Buffer.isBuffer = isBufferExists\n ? Buffer.isBuffer.bind(Buffer)\n : /**\n * Check if the provided value's type is `Buffer`\n\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `Buffer`\n */\n function isBuffer(\n value: Parameters<typeof Buffer.isBuffer>[0]\n ): value is Buffer {\n return false;\n };\n"],"mappings":"AAkBA,MAAa,EAAiB,OAAO,OAAW,IAKA,GAC5C,OAAO,SAAS,KAAK,OAAO"}
1
+ {"version":3,"file":"is-buffer.mjs","names":["isBuffer: typeof Buffer.isBuffer","isBuffer"],"sources":["../../../../type-checks/src/is-buffer.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\nexport const isBufferExists = typeof Buffer !== \"undefined\";\n\n/**\n * Check if the provided value's type is `Buffer`\n */\nexport const isBuffer: typeof Buffer.isBuffer = isBufferExists\n ? Buffer.isBuffer.bind(Buffer)\n : /**\n * Check if the provided value's type is `Buffer`\n\n * @param value - The value to type check\n * @returns An indicator specifying if the value provided is of type `Buffer`\n */\n function isBuffer(\n value: Parameters<typeof Buffer.isBuffer>[0]\n ): value is Buffer {\n return false;\n };\n"],"mappings":";AAkBA,MAAa,iBAAiB,OAAO,WAAW;;;;AAKhD,MAAaA,WAAmC,iBAC5C,OAAO,SAAS,KAAK,OAAO,GAO5B,SAASC,WACP,OACiB;AACjB,QAAO"}
@@ -1 +1 @@
1
- require(`./type-detect.cjs`);
1
+ require('./type-detect.cjs');
@@ -1 +1,3 @@
1
- import"./type-detect.mjs";export{};
1
+ import "./type-detect.mjs";
2
+
3
+ export { };
@@ -1 +1,15 @@
1
- require(`./is-buffer.cjs`);const e=(e=>(typeof globalThis==`object`||Object.defineProperty(e,`typeDetectGlobalObject`,{get(){return this},configurable:!0}),globalThis))(Object.prototype);
1
+ require('./is-buffer.cjs');
2
+
3
+ //#region ../type-checks/src/type-detect.ts
4
+ const globalObject = ((Obj) => {
5
+ if (typeof globalThis === "object") return globalThis;
6
+ Object.defineProperty(Obj, "typeDetectGlobalObject", {
7
+ get() {
8
+ return this;
9
+ },
10
+ configurable: true
11
+ });
12
+ return globalThis;
13
+ })(Object.prototype);
14
+
15
+ //#endregion
@@ -1,2 +1,17 @@
1
- import"./is-buffer.mjs";(e=>(typeof globalThis==`object`||Object.defineProperty(e,`typeDetectGlobalObject`,{get(){return this},configurable:!0}),globalThis))(Object.prototype);export{};
1
+ import "./is-buffer.mjs";
2
+
3
+ //#region ../type-checks/src/type-detect.ts
4
+ const globalObject = ((Obj) => {
5
+ if (typeof globalThis === "object") return globalThis;
6
+ Object.defineProperty(Obj, "typeDetectGlobalObject", {
7
+ get() {
8
+ return this;
9
+ },
10
+ configurable: true
11
+ });
12
+ return globalThis;
13
+ })(Object.prototype);
14
+
15
+ //#endregion
16
+ export { };
2
17
  //# sourceMappingURL=type-detect.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-detect.mjs","names":[],"sources":["../../../../type-checks/src/type-detect.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\nimport { isBuffer } from \"./is-buffer\";\n\nconst globalObject = (Obj => {\n if (typeof globalThis === \"object\") {\n return globalThis;\n }\n Object.defineProperty(Obj, \"typeDetectGlobalObject\", {\n get() {\n return this;\n },\n configurable: true\n });\n\n // // biome-ignore lint/correctness/noUndeclaredVariables: <explanation>\n // const global = typeDetectGlobalObject;\n\n // // biome-ignore lint/performance/noDelete: <explanation>\n // delete Obj.typeDetectGlobalObject;\n return globalThis;\n})(Object.prototype);\n\nexport function typeDetect(obj: unknown): string {\n // NOTE: isBuffer must execute before type-detect,\n // because type-detect returns 'Uint8Array'.\n if (isBuffer(obj)) {\n return \"Buffer\";\n }\n\n const typeofObj = typeof obj;\n if (typeofObj !== \"object\") {\n return typeofObj;\n }\n\n if (obj === null) {\n return \"null\";\n }\n\n if (obj === globalObject) {\n return \"global\";\n }\n\n if (\n Array.isArray(obj) &&\n (Symbol.toStringTag === undefined || !(Symbol.toStringTag in obj))\n ) {\n return \"Array\";\n }\n\n // https://html.spec.whatwg.org/multipage/browsers.html#location\n if (typeof globalThis === \"object\" && globalThis !== null) {\n if (\n typeof (globalThis as any).location === \"object\" &&\n obj === (globalThis as any).location\n ) {\n return \"Location\";\n }\n\n // https://html.spec.whatwg.org/#document\n if (\n typeof (globalThis as any).document === \"object\" &&\n obj === (globalThis as any).document\n ) {\n return \"Document\";\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray\n if (typeof (globalThis as any).navigator === \"object\") {\n if (\n typeof (globalThis as any).navigator.mimeTypes === \"object\" &&\n obj === (globalThis as any).navigator.mimeTypes\n ) {\n return \"MimeTypeArray\";\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray\n if (\n typeof (globalThis as any).navigator.plugins === \"object\" &&\n obj === (globalThis as any).navigator.plugins\n ) {\n return \"PluginArray\";\n }\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray\n if (\n (typeof (globalThis as any).HTMLElement === \"function\" ||\n typeof (globalThis as any).HTMLElement === \"object\") &&\n obj instanceof (globalThis as any).HTMLElement\n ) {\n if ((obj as any).tagName === \"BLOCKQUOTE\") {\n return \"HTMLQuoteElement\";\n }\n\n // https://html.spec.whatwg.org/#htmltabledatacellelement\n if ((obj as any).tagName === \"TD\") {\n return \"HTMLTableDataCellElement\";\n }\n\n // https://html.spec.whatwg.org/#htmltableheadercellelement\n if ((obj as any).tagName === \"TH\") {\n return \"HTMLTableHeaderCellElement\";\n }\n }\n }\n\n const stringTag =\n Symbol.toStringTag !== undefined && (obj as any)[Symbol.toStringTag];\n if (typeof stringTag === \"string\") {\n return stringTag;\n }\n\n const objPrototype = Object.getPrototypeOf(obj);\n if (objPrototype === RegExp.prototype) {\n return \"RegExp\";\n }\n\n if (objPrototype === Date.prototype) {\n return \"Date\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag\n if (typeof Promise !== \"undefined\" && objPrototype === Promise.prototype) {\n return \"Promise\";\n }\n\n if (typeof Set !== \"undefined\" && objPrototype === Set.prototype) {\n return \"Set\";\n }\n\n if (typeof Map !== \"undefined\" && objPrototype === Map.prototype) {\n return \"Map\";\n }\n\n if (typeof WeakSet !== \"undefined\" && objPrototype === WeakSet.prototype) {\n return \"WeakSet\";\n }\n\n if (typeof WeakMap !== \"undefined\" && objPrototype === WeakMap.prototype) {\n return \"WeakMap\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag\n if (typeof DataView !== \"undefined\" && objPrototype === DataView.prototype) {\n return \"DataView\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag\n if (\n typeof Map !== \"undefined\" &&\n objPrototype === Object.getPrototypeOf(new Map().entries())\n ) {\n return \"Map Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag\n if (\n typeof Set !== \"undefined\" &&\n objPrototype === Object.getPrototypeOf(new Set().entries())\n ) {\n return \"Set Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag\n if (\n typeof Array.prototype[Symbol.iterator] === \"function\" &&\n objPrototype === Object.getPrototypeOf([][Symbol.iterator]())\n ) {\n return \"Array Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag\n if (\n Symbol.iterator !== undefined &&\n typeof String.prototype[Symbol.iterator] === \"function\" &&\n Object.getPrototypeOf(\"\"[Symbol.iterator]()) &&\n objPrototype === Object.getPrototypeOf(\"\"[Symbol.iterator]())\n ) {\n return \"String Iterator\";\n }\n\n if (objPrototype === null) {\n return \"Object\";\n }\n\n return Object.prototype.toString.call(obj).slice(8, -1);\n}\n"],"mappings":"yBAoBsB,IAChB,OAAO,YAAe,UAG1B,OAAO,eAAe,EAAK,yBAA0B,CACnD,KAAM,CACJ,OAAO,MAET,aAAc,GACf,CAAC,CAPO,aAeR,OAAO,UAAU"}
1
+ {"version":3,"file":"type-detect.mjs","names":[],"sources":["../../../../type-checks/src/type-detect.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\nimport { isBuffer } from \"./is-buffer\";\n\nconst globalObject = (Obj => {\n if (typeof globalThis === \"object\") {\n return globalThis;\n }\n Object.defineProperty(Obj, \"typeDetectGlobalObject\", {\n get() {\n return this;\n },\n configurable: true\n });\n\n // // biome-ignore lint/correctness/noUndeclaredVariables: <explanation>\n // const global = typeDetectGlobalObject;\n\n // // biome-ignore lint/performance/noDelete: <explanation>\n // delete Obj.typeDetectGlobalObject;\n return globalThis;\n})(Object.prototype);\n\nexport function typeDetect(obj: unknown): string {\n // NOTE: isBuffer must execute before type-detect,\n // because type-detect returns 'Uint8Array'.\n if (isBuffer(obj)) {\n return \"Buffer\";\n }\n\n const typeofObj = typeof obj;\n if (typeofObj !== \"object\") {\n return typeofObj;\n }\n\n if (obj === null) {\n return \"null\";\n }\n\n if (obj === globalObject) {\n return \"global\";\n }\n\n if (\n Array.isArray(obj) &&\n (Symbol.toStringTag === undefined || !(Symbol.toStringTag in obj))\n ) {\n return \"Array\";\n }\n\n // https://html.spec.whatwg.org/multipage/browsers.html#location\n if (typeof globalThis === \"object\" && globalThis !== null) {\n if (\n typeof (globalThis as any).location === \"object\" &&\n obj === (globalThis as any).location\n ) {\n return \"Location\";\n }\n\n // https://html.spec.whatwg.org/#document\n if (\n typeof (globalThis as any).document === \"object\" &&\n obj === (globalThis as any).document\n ) {\n return \"Document\";\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray\n if (typeof (globalThis as any).navigator === \"object\") {\n if (\n typeof (globalThis as any).navigator.mimeTypes === \"object\" &&\n obj === (globalThis as any).navigator.mimeTypes\n ) {\n return \"MimeTypeArray\";\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray\n if (\n typeof (globalThis as any).navigator.plugins === \"object\" &&\n obj === (globalThis as any).navigator.plugins\n ) {\n return \"PluginArray\";\n }\n }\n\n // https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray\n if (\n (typeof (globalThis as any).HTMLElement === \"function\" ||\n typeof (globalThis as any).HTMLElement === \"object\") &&\n obj instanceof (globalThis as any).HTMLElement\n ) {\n if ((obj as any).tagName === \"BLOCKQUOTE\") {\n return \"HTMLQuoteElement\";\n }\n\n // https://html.spec.whatwg.org/#htmltabledatacellelement\n if ((obj as any).tagName === \"TD\") {\n return \"HTMLTableDataCellElement\";\n }\n\n // https://html.spec.whatwg.org/#htmltableheadercellelement\n if ((obj as any).tagName === \"TH\") {\n return \"HTMLTableHeaderCellElement\";\n }\n }\n }\n\n const stringTag =\n Symbol.toStringTag !== undefined && (obj as any)[Symbol.toStringTag];\n if (typeof stringTag === \"string\") {\n return stringTag;\n }\n\n const objPrototype = Object.getPrototypeOf(obj);\n if (objPrototype === RegExp.prototype) {\n return \"RegExp\";\n }\n\n if (objPrototype === Date.prototype) {\n return \"Date\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag\n if (typeof Promise !== \"undefined\" && objPrototype === Promise.prototype) {\n return \"Promise\";\n }\n\n if (typeof Set !== \"undefined\" && objPrototype === Set.prototype) {\n return \"Set\";\n }\n\n if (typeof Map !== \"undefined\" && objPrototype === Map.prototype) {\n return \"Map\";\n }\n\n if (typeof WeakSet !== \"undefined\" && objPrototype === WeakSet.prototype) {\n return \"WeakSet\";\n }\n\n if (typeof WeakMap !== \"undefined\" && objPrototype === WeakMap.prototype) {\n return \"WeakMap\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag\n if (typeof DataView !== \"undefined\" && objPrototype === DataView.prototype) {\n return \"DataView\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag\n if (\n typeof Map !== \"undefined\" &&\n objPrototype === Object.getPrototypeOf(new Map().entries())\n ) {\n return \"Map Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag\n if (\n typeof Set !== \"undefined\" &&\n objPrototype === Object.getPrototypeOf(new Set().entries())\n ) {\n return \"Set Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag\n if (\n typeof Array.prototype[Symbol.iterator] === \"function\" &&\n objPrototype === Object.getPrototypeOf([][Symbol.iterator]())\n ) {\n return \"Array Iterator\";\n }\n\n // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag\n if (\n Symbol.iterator !== undefined &&\n typeof String.prototype[Symbol.iterator] === \"function\" &&\n Object.getPrototypeOf(\"\"[Symbol.iterator]()) &&\n objPrototype === Object.getPrototypeOf(\"\"[Symbol.iterator]())\n ) {\n return \"String Iterator\";\n }\n\n if (objPrototype === null) {\n return \"Object\";\n }\n\n return Object.prototype.toString.call(obj).slice(8, -1);\n}\n"],"mappings":";;;AAoBA,MAAM,iBAAgB,QAAO;AAC3B,KAAI,OAAO,eAAe,SACxB,QAAO;AAET,QAAO,eAAe,KAAK,0BAA0B;EACnD,MAAM;AACJ,UAAO;;EAET,cAAc;EACf,CAAC;AAOF,QAAO;GACN,OAAO,UAAU"}
package/dist/uuid.cjs CHANGED
@@ -1 +1,45 @@
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}exports.uuid=r;
1
+
2
+ //#region src/uuid.ts
3
+ let index = 256;
4
+ const hex = [];
5
+ let buffer;
6
+ while (index--) hex[index] = (index + 256).toString(16).slice(1);
7
+ /**
8
+ * A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
9
+ *
10
+ * @remarks
11
+ * This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.
12
+ *
13
+ * This implementation was based on https://github.com/lukeed/uuid.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Generate a UUID string
18
+ * const id = uuid();
19
+ * // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
20
+ * ```
21
+ *
22
+ * @returns A UUID unique identifier.
23
+ */
24
+ function uuid() {
25
+ let i = 0;
26
+ let num;
27
+ let out = "";
28
+ if (!buffer || index + 16 > 256) {
29
+ buffer = Array.from({ length: i = 256 });
30
+ while (i--) buffer[i] = Math.trunc(256 * Math.random());
31
+ i = index = 0;
32
+ }
33
+ for (; i < 16; i++) {
34
+ num = buffer[index + i];
35
+ if (i === 6) out += hex[num & 15 | 64];
36
+ else if (i === 8) out += hex[num & 63 | 128];
37
+ else out += hex[num];
38
+ if (i & 1 && i > 1 && i < 11) out += "-";
39
+ }
40
+ index++;
41
+ return out;
42
+ }
43
+
44
+ //#endregion
45
+ exports.uuid = uuid;
package/dist/uuid.mjs CHANGED
@@ -1,2 +1,45 @@
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 uuid};
1
+ //#region src/uuid.ts
2
+ let index = 256;
3
+ const hex = [];
4
+ let buffer;
5
+ while (index--) hex[index] = (index + 256).toString(16).slice(1);
6
+ /**
7
+ * A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
8
+ *
9
+ * @remarks
10
+ * This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.
11
+ *
12
+ * This implementation was based on https://github.com/lukeed/uuid.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Generate a UUID string
17
+ * const id = uuid();
18
+ * // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
19
+ * ```
20
+ *
21
+ * @returns A UUID unique identifier.
22
+ */
23
+ function uuid() {
24
+ let i = 0;
25
+ let num;
26
+ let out = "";
27
+ if (!buffer || index + 16 > 256) {
28
+ buffer = Array.from({ length: i = 256 });
29
+ while (i--) buffer[i] = Math.trunc(256 * Math.random());
30
+ i = index = 0;
31
+ }
32
+ for (; i < 16; i++) {
33
+ num = buffer[index + i];
34
+ if (i === 6) out += hex[num & 15 | 64];
35
+ else if (i === 8) out += hex[num & 63 | 128];
36
+ else out += hex[num];
37
+ if (i & 1 && i > 1 && i < 11) out += "-";
38
+ }
39
+ index++;
40
+ return out;
41
+ }
42
+
43
+ //#endregion
44
+ export { uuid };
2
45
  //# sourceMappingURL=uuid.mjs.map
package/dist/uuid.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.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"}
1
+ {"version":3,"file":"uuid.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,QAAQ;AACZ,MAAM,MAAM,EAAE;AACd,IAAIA;AAEJ,OAAO,QACL,KAAI,UAAU,QAAQ,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE;;;;;;;;;;;;;;;;;;AAoBlD,SAAgB,OAAO;CACrB,IAAI,IAAI;CACR,IAAIC;CACJ,IAAI,MAAM;AAEV,KAAI,CAAC,UAAU,QAAQ,KAAK,KAAK;AAC/B,WAAS,MAAM,KAAK,EAAE,QAAS,IAAI,KAAM,CAAC;AAC1C,SAAO,IACL,QAAO,KAAK,KAAK,MAAM,MAAM,KAAK,QAAQ,CAAC;AAG7C,MAAI,QAAQ;;AAGd,QAAO,IAAI,IAAI,KAAK;AAClB,QAAM,OAAO,QAAQ;AACrB,MAAI,MAAM,EACR,QAAO,IAAK,MAAM,KAAM;WACf,MAAM,EACf,QAAO,IAAK,MAAM,KAAM;MAExB,QAAO,IAAI;AAGb,MAAI,IAAI,KAAK,IAAI,KAAK,IAAI,GACxB,QAAO;;AAIX;AACA,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/unique-id",
3
- "version": "0.3.43",
3
+ "version": "0.3.45",
4
4
  "type": "module",
5
5
  "description": "A package containing various helper functions to generate unique identifier strings",
6
6
  "repository": {
@@ -32,5 +32,5 @@
32
32
  "types": "./dist/index.d.cts",
33
33
  "devDependencies": { "tsdown": "^0.17.2" },
34
34
  "publishConfig": { "access": "public" },
35
- "gitHead": "d7628ea6fec405e8ba9926647a055820bbc4ee87"
35
+ "gitHead": "a31823cb064cdedba8187c7a25956f1863d035c8"
36
36
  }