@stryke/unique-id 0.3.31 → 0.3.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/convert/src/neutral.cjs +1 -0
- package/dist/convert/src/neutral.mjs +1 -0
- package/dist/convert/src/parse-type-definition.cjs +1 -0
- package/dist/convert/src/parse-type-definition.mjs +1 -0
- package/dist/convert/src/string-to-utf8-array.cjs +1 -0
- package/dist/convert/src/string-to-utf8-array.mjs +2 -0
- package/dist/convert/src/string-to-utf8-array.mjs.map +1 -0
- package/dist/convert/src/utf8-array-to-string.cjs +1 -0
- package/dist/convert/src/utf8-array-to-string.mjs +2 -0
- package/dist/convert/src/utf8-array-to-string.mjs.map +1 -0
- package/dist/cuid.cjs +1 -1
- package/dist/cuid.d.cts +20 -2
- package/dist/cuid.d.cts.map +1 -0
- package/dist/cuid.d.mts +20 -2
- package/dist/cuid.d.mts.map +1 -0
- package/dist/cuid.mjs +2 -1
- package/dist/cuid.mjs.map +1 -0
- package/dist/fs/src/list-files.cjs +1 -0
- package/dist/fs/src/list-files.mjs +1 -0
- package/dist/hash/src/digest.cjs +1 -0
- package/dist/hash/src/digest.mjs +1 -0
- package/dist/hash/src/hash-files.cjs +1 -0
- package/dist/hash/src/hash-files.mjs +1 -0
- package/dist/hash/src/murmurhash.cjs +1 -0
- package/dist/hash/src/murmurhash.mjs +2 -0
- package/dist/hash/src/murmurhash.mjs.map +1 -0
- package/dist/hash/src/neutral.cjs +1 -0
- package/dist/hash/src/neutral.mjs +1 -0
- package/dist/hash/src/xx-hash.cjs +1 -0
- package/dist/hash/src/xx-hash.mjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -1
- package/dist/nanoid-client.cjs +1 -1
- package/dist/nanoid-client.d.cts +11 -2
- package/dist/nanoid-client.d.cts.map +1 -0
- package/dist/nanoid-client.d.mts +11 -2
- package/dist/nanoid-client.d.mts.map +1 -0
- package/dist/nanoid-client.mjs +2 -1
- package/dist/nanoid-client.mjs.map +1 -0
- package/dist/random.cjs +1 -1
- package/dist/random.d.cts +33 -2
- package/dist/random.d.cts.map +1 -0
- package/dist/random.d.mts +33 -2
- package/dist/random.d.mts.map +1 -0
- package/dist/random.mjs +2 -1
- package/dist/random.mjs.map +1 -0
- package/dist/snowflake.cjs +1 -1
- package/dist/snowflake.d.cts +102 -2
- package/dist/snowflake.d.cts.map +1 -0
- package/dist/snowflake.d.mts +102 -2
- package/dist/snowflake.d.mts.map +1 -0
- package/dist/snowflake.mjs +2 -1
- package/dist/snowflake.mjs.map +1 -0
- package/dist/type-checks/src/index.cjs +1 -0
- package/dist/type-checks/src/index.mjs +1 -0
- package/dist/type-checks/src/is-buffer.cjs +1 -0
- package/dist/type-checks/src/is-buffer.mjs +2 -0
- package/dist/type-checks/src/is-buffer.mjs.map +1 -0
- package/dist/type-checks/src/is-collection.cjs +1 -0
- package/dist/type-checks/src/is-collection.mjs +1 -0
- package/dist/type-checks/src/type-detect.cjs +1 -0
- package/dist/type-checks/src/type-detect.mjs +2 -0
- package/dist/type-checks/src/type-detect.mjs.map +1 -0
- package/dist/uuid.cjs +1 -1
- package/dist/uuid.d.cts +22 -2
- package/dist/uuid.d.cts.map +1 -0
- package/dist/uuid.d.mts +22 -2
- package/dist/uuid.d.mts.map +1 -0
- package/dist/uuid.mjs +2 -1
- package/dist/uuid.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/cuid-BuvbHUZ8.cjs +0 -1
- package/dist/cuid-CcPQdiR_.mjs +0 -2
- package/dist/cuid-CcPQdiR_.mjs.map +0 -1
- package/dist/cuid-DT9rtBzf.d.mts +0 -20
- package/dist/cuid-DT9rtBzf.d.mts.map +0 -1
- package/dist/cuid-gUcp5l6X.d.cts +0 -20
- package/dist/cuid-gUcp5l6X.d.cts.map +0 -1
- package/dist/nanoid-client-DxgQ8Vt2.cjs +0 -1
- package/dist/nanoid-client-bEHxSBYB.mjs +0 -2
- package/dist/nanoid-client-bEHxSBYB.mjs.map +0 -1
- package/dist/nanoid-client-mNAgNxsW.d.cts +0 -11
- package/dist/nanoid-client-mNAgNxsW.d.cts.map +0 -1
- package/dist/nanoid-client-nC1JFvZD.d.mts +0 -11
- package/dist/nanoid-client-nC1JFvZD.d.mts.map +0 -1
- package/dist/random-Bd2-oY2n.d.cts +0 -33
- package/dist/random-Bd2-oY2n.d.cts.map +0 -1
- package/dist/random-C4CrqJsp.cjs +0 -1
- package/dist/random-DTxCCJYh.d.mts +0 -33
- package/dist/random-DTxCCJYh.d.mts.map +0 -1
- package/dist/random-kTN0s0Jy.mjs +0 -2
- package/dist/random-kTN0s0Jy.mjs.map +0 -1
- package/dist/snowflake-B6ivA7bE.d.mts +0 -102
- package/dist/snowflake-B6ivA7bE.d.mts.map +0 -1
- package/dist/snowflake-BtoDXB99.mjs +0 -2
- package/dist/snowflake-BtoDXB99.mjs.map +0 -1
- package/dist/snowflake-CLDXd54w.cjs +0 -1
- package/dist/snowflake-DQmoRlnq.d.cts +0 -102
- package/dist/snowflake-DQmoRlnq.d.cts.map +0 -1
- package/dist/uuid-BnD3hGTH.cjs +0 -1
- package/dist/uuid-ByPTbUGJ.d.mts +0 -22
- package/dist/uuid-ByPTbUGJ.d.mts.map +0 -1
- package/dist/uuid-DCE9JeUQ.d.cts +0 -22
- package/dist/uuid-DCE9JeUQ.d.cts.map +0 -1
- package/dist/uuid-DSMliG_W.mjs +0 -2
- package/dist/uuid-DSMliG_W.mjs.map +0 -1
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./is-buffer.cjs`);require(`./type-detect.cjs`),require(`./is-collection.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isBufferExists as e}from"./is-buffer.mjs";import"./type-detect.mjs";import"./is-collection.mjs";export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=typeof Buffer<`u`,t=e?Buffer.isBuffer.bind(Buffer):function(e){return!1};exports.isBufferExists=e;
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./type-detect.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./type-detect.mjs";export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./is-buffer.cjs`);const e=(e=>(typeof globalThis==`object`||Object.defineProperty(e,`typeDetectGlobalObject`,{get(){return this},configurable:!0}),globalThis))(Object.prototype);
|
|
@@ -0,0 +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"}
|
package/dist/uuid.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=
|
|
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;
|
package/dist/uuid.d.cts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/uuid.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.
|
|
7
|
+
*
|
|
8
|
+
* This implementation was based on https://github.com/lukeed/uuid.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Generate a UUID string
|
|
13
|
+
* const id = uuid();
|
|
14
|
+
* // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns A UUID unique identifier.
|
|
18
|
+
*/
|
|
19
|
+
declare function uuid(): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { uuid };
|
|
22
|
+
//# sourceMappingURL=uuid.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.cts","names":[],"sources":["../src/uuid.ts"],"sourcesContent":[],"mappings":";;AA2CA;;;;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
package/dist/uuid.d.mts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/uuid.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility function that returns a [UUID (Universally Unique Identifier)](https://www.cockroachlabs.com/blog/what-is-a-uuid/) string.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function generates a random UUID (Universally Unique Identifier) using a cryptographically secure pseudo-random number generator.
|
|
7
|
+
*
|
|
8
|
+
* This implementation was based on https://github.com/lukeed/uuid.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Generate a UUID string
|
|
13
|
+
* const id = uuid();
|
|
14
|
+
* // => "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns A UUID unique identifier.
|
|
18
|
+
*/
|
|
19
|
+
declare function uuid(): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { uuid };
|
|
22
|
+
//# sourceMappingURL=uuid.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.mts","names":[],"sources":["../src/uuid.ts"],"sourcesContent":[],"mappings":";;AA2CA;;;;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
package/dist/uuid.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
let e=256;const t=[];let n;for(;e--;)t[e]=(e+256).toString(16).slice(1);function r(){let r=0,i,a=``;if(!n||e+16>256){for(n=Array.from({length:r=256});r--;)n[r]=Math.trunc(256*Math.random());r=e=0}for(;r<16;r++)i=n[e+r],r===6?a+=t[i&15|64]:r===8?a+=t[i&63|128]:a+=t[i],r&1&&r>1&&r<11&&(a+=`-`);return e++,a}export{r as uuid};
|
|
2
|
+
//# sourceMappingURL=uuid.mjs.map
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/unique-id",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing various helper functions to generate unique identifier strings",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"./*": "./*"
|
|
31
31
|
},
|
|
32
32
|
"types": "./dist/index.d.cts",
|
|
33
|
-
"devDependencies": { "tsdown": "^0.17.
|
|
33
|
+
"devDependencies": { "tsdown": "^0.17.2" },
|
|
34
34
|
"publishConfig": { "access": "public" },
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8f2e484743eb3ce54929e99096ca2ea188b4730e"
|
|
36
36
|
}
|
package/dist/cuid-BuvbHUZ8.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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));const c=require(`./random-C4CrqJsp.cjs`);require(`defu`),require(`glob`);let l=require(`ohash`);require(`js-xxhash`);const u=typeof Buffer<`u`,d=u?Buffer.isBuffer.bind(Buffer):function(e){return!1},f=(e=>(typeof globalThis==`object`||Object.defineProperty(e,`typeDetectGlobalObject`,{get(){return this},configurable:!0}),globalThis))(Object.prototype),p=new TextEncoder,m=new TextDecoder;function h(e,t){let n=(0,l.hash)(e),r=t?.maxLength??32;return n.length>r?n.slice(0,r):n}const g=476782367,_=36,v=Math.floor(Math.random()*476782367)+1;function y(e=4,t=Math.random){let n=``;for(;n.length<e;)n+=Math.floor(t()*36).toString(36);return n}function b(e){let t=(e?.globalObj??typeof globalThis>`u`)&&typeof globalThis>`u`?{}:globalThis,n=Object.keys(t).toString();return h(n.length>0?n+y(36,Math.random):y(36,Math.random)).slice(0,36)}function x(){let e=Date.now().toString(36),t=v.toString(36),n=h(`${e+y(36,Math.random)+t+b()}`);return`${c.i()+n.slice(1,Math.min(n.length-1,36))}`}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return x}});
|
package/dist/cuid-CcPQdiR_.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./random-kTN0s0Jy.mjs";import"defu";import"glob";import{hash as t}from"ohash";import"js-xxhash";typeof Buffer<`u`&&Buffer.isBuffer.bind(Buffer),(e=>(typeof globalThis==`object`||Object.defineProperty(e,`typeDetectGlobalObject`,{get(){return this},configurable:!0}),globalThis))(Object.prototype),new TextEncoder,new TextDecoder;function n(e,n){let r=t(e),i=n?.maxLength??32;return r.length>i?r.slice(0,i):r}const r=Math.floor(Math.random()*476782367)+1;function i(e=4,t=Math.random){let n=``;for(;n.length<e;)n+=Math.floor(t()*36).toString(36);return n}function a(e){let t=(e?.globalObj??typeof globalThis>`u`)&&typeof globalThis>`u`?{}:globalThis,r=Object.keys(t).toString();return n(r.length>0?r+i(36,Math.random):i(36,Math.random)).slice(0,36)}function o(){let t=Date.now().toString(36),o=r.toString(36),s=n(`${t+i(36,Math.random)+o+a()}`);return`${e()+s.slice(1,Math.min(s.length-1,36))}`}export{o as t};
|
|
2
|
-
//# sourceMappingURL=cuid-CcPQdiR_.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cuid-CcPQdiR_.mjs","names":["isBuffer: typeof Buffer.isBuffer","isBuffer","ohash"],"sources":["../../type-checks/src/is-buffer.ts","../../type-checks/src/type-detect.ts","../../convert/src/string-to-utf8-array.ts","../../convert/src/utf8-array-to-string.ts","../../hash/src/murmurhash.ts","../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\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","/* -------------------------------------------------------------------\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","/* -------------------------------------------------------------------\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","/* -------------------------------------------------------------------\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","/* -------------------------------------------------------------------\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","/* -------------------------------------------------------------------\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":"mHAkB8B,OAAO,OAAW,KAM5C,OAAO,SAAS,KAAK,OAAO,ECJV,IAChB,OAAO,YAAe,UAG1B,OAAO,eAAe,EAAK,yBAA0B,CACnD,KAAM,CACJ,OAAO,MAET,aAAc,GACf,CAAC,CAPO,aAeR,OAAO,UAAU,CCnBJ,IAAI,YCAJ,IAAI,YCqBpB,SAAgB,EAAW,EAAc,EAA+B,CACtE,IAAM,EAASE,EAAM,EAAQ,CACvB,EAAY,GAAS,WAAa,GAExC,OAAO,EAAO,OAAS,EAAY,EAAO,MAAM,EAAG,EAAU,CAAG,ECnBlE,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"}
|
package/dist/cuid-DT9rtBzf.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/cuid.d.ts
|
|
2
|
-
interface FingerprintOptions {
|
|
3
|
-
globalObj?: any;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Generate a random CUID
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
*
|
|
11
|
-
* // Generate a random CUID
|
|
12
|
-
* const id = cuid();
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @returns A random CUID string
|
|
16
|
-
*/
|
|
17
|
-
declare function cuid(): string;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { cuid as n, FingerprintOptions as t };
|
|
20
|
-
//# sourceMappingURL=cuid-DT9rtBzf.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cuid-DT9rtBzf.d.mts","names":[],"sources":["../src/cuid.ts"],"sourcesContent":[],"mappings":";UA6DiB,kBAAA;EAAA,SAAA,CAAA,EAAA,GAAA;AA0CjB;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
package/dist/cuid-gUcp5l6X.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/cuid.d.ts
|
|
2
|
-
interface FingerprintOptions {
|
|
3
|
-
globalObj?: any;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Generate a random CUID
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
*
|
|
11
|
-
* // Generate a random CUID
|
|
12
|
-
* const id = cuid();
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @returns A random CUID string
|
|
16
|
-
*/
|
|
17
|
-
declare function cuid(): string;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { cuid as n, FingerprintOptions as t };
|
|
20
|
-
//# sourceMappingURL=cuid-gUcp5l6X.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cuid-gUcp5l6X.d.cts","names":[],"sources":["../src/cuid.ts"],"sourcesContent":[],"mappings":";UA6DiB,kBAAA;EAAA,SAAA,CAAA,EAAA,GAAA;AA0CjB;;;;;;;;;;;;;iBAAgB,IAAA,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./random-C4CrqJsp.cjs`);function t(t=21){return e.t(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),``)}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nanoid-client-bEHxSBYB.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":"0CAgCA,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,11 +0,0 @@
|
|
|
1
|
-
//#region src/nanoid-client.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
4
|
-
*
|
|
5
|
-
* @param size - The size of the string to generate
|
|
6
|
-
* @returns A unique identifier following the nanoid format
|
|
7
|
-
*/
|
|
8
|
-
declare function nanoid(size?: number): string;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { nanoid as t };
|
|
11
|
-
//# sourceMappingURL=nanoid-client-mNAgNxsW.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nanoid-client-mNAgNxsW.d.cts","names":[],"sources":["../src/nanoid-client.ts"],"sourcesContent":[],"mappings":";;AAgCA;;;;;iBAAgB,MAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/nanoid-client.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* A wrapper around the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
4
|
-
*
|
|
5
|
-
* @param size - The size of the string to generate
|
|
6
|
-
* @returns A unique identifier following the nanoid format
|
|
7
|
-
*/
|
|
8
|
-
declare function nanoid(size?: number): string;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { nanoid as t };
|
|
11
|
-
//# sourceMappingURL=nanoid-client-nC1JFvZD.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nanoid-client-nC1JFvZD.d.mts","names":[],"sources":["../src/nanoid-client.ts"],"sourcesContent":[],"mappings":";;AAgCA;;;;;iBAAgB,MAAA"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region src/random.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Generate a random integer
|
|
4
|
-
*
|
|
5
|
-
* @param maximum - The maximum value (inclusive)
|
|
6
|
-
* @param minimum - The minimum value (inclusive)
|
|
7
|
-
* @returns A random integer
|
|
8
|
-
*/
|
|
9
|
-
declare const randomInteger: (maximum: number, minimum?: number) => number;
|
|
10
|
-
/**
|
|
11
|
-
* Generate a random letter
|
|
12
|
-
*
|
|
13
|
-
* @param random - The random number generator
|
|
14
|
-
* @returns A random letter
|
|
15
|
-
*/
|
|
16
|
-
declare const randomLetter: (random?: () => number) => string | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Generate a random string
|
|
19
|
-
*
|
|
20
|
-
* @param array - The array to fill with random values
|
|
21
|
-
* @returns The array filled with random values
|
|
22
|
-
*/
|
|
23
|
-
declare function getNonCryptoRandomValues(array: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
24
|
-
/**
|
|
25
|
-
* Generate a series of random characters
|
|
26
|
-
*
|
|
27
|
-
* @param length - The length of the random characters
|
|
28
|
-
* @returns A series of random characters
|
|
29
|
-
*/
|
|
30
|
-
declare function randomCharacters(length: number): string;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { randomLetter as i, randomCharacters as n, randomInteger as r, getNonCryptoRandomValues as t };
|
|
33
|
-
//# sourceMappingURL=random-Bd2-oY2n.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"random-Bd2-oY2n.d.cts","names":[],"sources":["../src/random.ts"],"sourcesContent":[],"mappings":";;AA6BA;AASA;AASA;;;;AAA0D,cAlB7C,aAkB6C,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAmB1D;;;;;;cA5Ba;;;;;;;iBASG,wBAAA,QAAgC,aAAU,WAAA;;;;;;;iBAmB1C,gBAAA"}
|
package/dist/random-C4CrqJsp.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=Array.from({length:26},(e,t)=>String.fromCodePoint(t+97)),t=(e,t=0)=>Math.floor(Math.random()*(e-t+1)+t),n=(t=Math.random)=>e[Math.floor(t()*e.length)];function r(e){if(e===null)throw TypeError(`array cannot be null`);for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return e}function i(e){let t=``,n=0;for(;n<e;)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62)),n+=1;return t}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region src/random.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Generate a random integer
|
|
4
|
-
*
|
|
5
|
-
* @param maximum - The maximum value (inclusive)
|
|
6
|
-
* @param minimum - The minimum value (inclusive)
|
|
7
|
-
* @returns A random integer
|
|
8
|
-
*/
|
|
9
|
-
declare const randomInteger: (maximum: number, minimum?: number) => number;
|
|
10
|
-
/**
|
|
11
|
-
* Generate a random letter
|
|
12
|
-
*
|
|
13
|
-
* @param random - The random number generator
|
|
14
|
-
* @returns A random letter
|
|
15
|
-
*/
|
|
16
|
-
declare const randomLetter: (random?: () => number) => string | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Generate a random string
|
|
19
|
-
*
|
|
20
|
-
* @param array - The array to fill with random values
|
|
21
|
-
* @returns The array filled with random values
|
|
22
|
-
*/
|
|
23
|
-
declare function getNonCryptoRandomValues(array: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
24
|
-
/**
|
|
25
|
-
* Generate a series of random characters
|
|
26
|
-
*
|
|
27
|
-
* @param length - The length of the random characters
|
|
28
|
-
* @returns A series of random characters
|
|
29
|
-
*/
|
|
30
|
-
declare function randomCharacters(length: number): string;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { randomLetter as i, randomCharacters as n, randomInteger as r, getNonCryptoRandomValues as t };
|
|
33
|
-
//# sourceMappingURL=random-DTxCCJYh.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"random-DTxCCJYh.d.mts","names":[],"sources":["../src/random.ts"],"sourcesContent":[],"mappings":";;AA6BA;AASA;AASA;;;;AAA0D,cAlB7C,aAkB6C,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAmB1D;;;;;;cA5Ba;;;;;;;iBASG,wBAAA,QAAgC,aAAU,WAAA;;;;;;;iBAmB1C,gBAAA"}
|
package/dist/random-kTN0s0Jy.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=Array.from({length:26},(e,t)=>String.fromCodePoint(t+97)),t=(e,t=0)=>Math.floor(Math.random()*(e-t+1)+t),n=(t=Math.random)=>e[Math.floor(t()*e.length)];function r(e){if(e===null)throw TypeError(`array cannot be null`);for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return e}function i(e){let t=``,n=0;for(;n<e;)t+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62)),n+=1;return t}export{n as i,i as n,t as r,r as t};
|
|
2
|
-
//# sourceMappingURL=random-kTN0s0Jy.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"random-kTN0s0Jy.mjs","names":[],"sources":["../src/random.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst alphabet = Array.from({ length: 26 }, (_x, i) =>\n String.fromCodePoint(i + 97)\n);\n\n/**\n * Generate a random integer\n *\n * @param maximum - The maximum value (inclusive)\n * @param minimum - The minimum value (inclusive)\n * @returns A random integer\n */\nexport const randomInteger = (maximum: number, minimum = 0) =>\n Math.floor(Math.random() * (maximum - minimum + 1) + minimum);\n\n/**\n * Generate a random letter\n *\n * @param random - The random number generator\n * @returns A random letter\n */\nexport const randomLetter = (random: () => number = Math.random) =>\n alphabet[Math.floor(random() * alphabet.length)];\n\n/**\n * Generate a random string\n *\n * @param array - The array to fill with random values\n * @returns The array filled with random values\n */\nexport function getNonCryptoRandomValues(array: Uint8Array) {\n if (array === null) {\n throw new TypeError(\"array cannot be null\");\n }\n\n // Fill the array with random values\n for (let i = 0; i < array.length; i++) {\n array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)\n }\n\n return array;\n}\n\n/**\n * Generate a series of random characters\n *\n * @param length - The length of the random characters\n * @returns A series of random characters\n */\nexport function randomCharacters(length: number) {\n let result = \"\";\n const characters =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n const charactersLength = characters.length;\n let counter = 0;\n while (counter < length) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n counter += 1;\n }\n return result;\n}\n"],"mappings":"AAkBA,MAAM,EAAW,MAAM,KAAK,CAAE,OAAQ,GAAI,EAAG,EAAI,IAC/C,OAAO,cAAc,EAAI,GAAG,CAC7B,CASY,GAAiB,EAAiB,EAAU,IACvD,KAAK,MAAM,KAAK,QAAQ,EAAI,EAAU,EAAU,GAAK,EAAQ,CAQlD,GAAgB,EAAuB,KAAK,SACvD,EAAS,KAAK,MAAM,GAAQ,CAAG,EAAS,OAAO,EAQjD,SAAgB,EAAyB,EAAmB,CAC1D,GAAI,IAAU,KACZ,MAAU,UAAU,uBAAuB,CAI7C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,EAAM,GAAK,KAAK,MAAM,KAAK,QAAQ,CAAG,IAAI,CAG5C,OAAO,EAST,SAAgB,EAAiB,EAAgB,CAC/C,IAAI,EAAS,GAIT,EAAU,EACd,KAAO,EAAU,GACf,GAAU,iEAAW,OAAO,KAAK,MAAM,KAAK,QAAQ,CAAG,GAAiB,CAAC,CACzE,GAAW,EAEb,OAAO"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//#region src/snowflake.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Options passed to the `generate` function to create a snowflake identifier.
|
|
4
|
-
*/
|
|
5
|
-
interface SnowflakeGeneratorOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The id of the shard running this generator.
|
|
8
|
-
*
|
|
9
|
-
* @defaultValue 1
|
|
10
|
-
*/
|
|
11
|
-
shardId?: number;
|
|
12
|
-
/**
|
|
13
|
-
* The epoch to use for the snowflake.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* This is the time in milliseconds since 1 January 1970 00:00:00 UTC.
|
|
17
|
-
*
|
|
18
|
-
* @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())
|
|
19
|
-
*/
|
|
20
|
-
epoch?: number;
|
|
21
|
-
/**
|
|
22
|
-
* The current timestamp to use for the snowflake.
|
|
23
|
-
*
|
|
24
|
-
* @defaultValue Date.now()
|
|
25
|
-
*/
|
|
26
|
-
timestamp?: number | Date;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Resolvable value types for a valid Snowflake:
|
|
30
|
-
* string
|
|
31
|
-
* number
|
|
32
|
-
* bigint
|
|
33
|
-
*/
|
|
34
|
-
type SnowflakeResolvable = string;
|
|
35
|
-
/**
|
|
36
|
-
* A deconstructed snowflake and the details around it's creation.
|
|
37
|
-
*/
|
|
38
|
-
interface DeconstructedSnowflake {
|
|
39
|
-
/**
|
|
40
|
-
* Snowflake deconstructed from
|
|
41
|
-
*/
|
|
42
|
-
snowflake: SnowflakeResolvable;
|
|
43
|
-
/**
|
|
44
|
-
* The timestamp the snowflake was generated
|
|
45
|
-
*/
|
|
46
|
-
timestamp: number;
|
|
47
|
-
/**
|
|
48
|
-
* The shard_id used when generating
|
|
49
|
-
*/
|
|
50
|
-
shard_id: number;
|
|
51
|
-
/**
|
|
52
|
-
* The increment of this snowflake
|
|
53
|
-
*/
|
|
54
|
-
sequence: number;
|
|
55
|
-
/**
|
|
56
|
-
* The 64Bit snowflake binary string
|
|
57
|
-
*/
|
|
58
|
-
binary: string;
|
|
59
|
-
}
|
|
60
|
-
declare const DEFAULT_SHARD_ID = 1;
|
|
61
|
-
declare const DEFAULT_EPOCH: number;
|
|
62
|
-
/**
|
|
63
|
-
* Generate a snowflake identifier.
|
|
64
|
-
*
|
|
65
|
-
* @remarks
|
|
66
|
-
* Snowflakes are 64-bit unsigned integers that are roughly time-ordered.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
*
|
|
71
|
-
* // Generate a snowflake with the default options
|
|
72
|
-
* const id1 = snowflake();
|
|
73
|
-
*
|
|
74
|
-
* // Generate a snowflake with a custom shard id
|
|
75
|
-
* const id2 = snowflake({ shardId: 2 });
|
|
76
|
-
*
|
|
77
|
-
* // Generate a snowflake with a custom shard id and timestamp
|
|
78
|
-
* const id3 = snowflake({ shardId: 3, timestamp: new Date("2021-01-01") });
|
|
79
|
-
*
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @param options - The options to use when generating the snowflake
|
|
83
|
-
* @returns A snowflake
|
|
84
|
-
*/
|
|
85
|
-
declare function snowflake(options?: SnowflakeGeneratorOptions): string;
|
|
86
|
-
/**
|
|
87
|
-
* Deconstruct a snowflake to its values using the `epoch`.
|
|
88
|
-
*
|
|
89
|
-
* @param snowflake - Snowflake to deconstruct
|
|
90
|
-
* @returns Either the DeconstructedSnowflake object
|
|
91
|
-
*/
|
|
92
|
-
declare function deconstructSnowflake(snowflake: SnowflakeResolvable): DeconstructedSnowflake;
|
|
93
|
-
/**
|
|
94
|
-
* Check if a snowflake string Id is valid.
|
|
95
|
-
*
|
|
96
|
-
* @param snowflake - Snowflake to check
|
|
97
|
-
* @returns Whether the snowflake is valid
|
|
98
|
-
*/
|
|
99
|
-
declare function isValidSnowflake(snowflake: string): boolean;
|
|
100
|
-
//#endregion
|
|
101
|
-
export { SnowflakeResolvable as a, snowflake as c, SnowflakeGeneratorOptions as i, DEFAULT_SHARD_ID as n, deconstructSnowflake as o, DeconstructedSnowflake as r, isValidSnowflake as s, DEFAULT_EPOCH as t };
|
|
102
|
-
//# sourceMappingURL=snowflake-B6ivA7bE.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snowflake-B6ivA7bE.d.mts","names":[],"sources":["../src/snowflake.ts"],"sourcesContent":[],"mappings":";;AAqBA;AAgCA;AAKiB,UArCA,yBAAA,CAyCJ;EAuBA;AACb;AAqEA;AA0BA;AAoBA;;;;;;;;;;;;;;;;uBA7JuB;;;;;;;;KASX,mBAAA;;;;UAKK,sBAAA;;;;aAIJ;;;;;;;;;;;;;;;;;;cAuBA,gBAAA;cACA;;;;;;;;;;;;;;;;;;;;;;;;iBAqEG,SAAA,WAAmB;;;;;;;iBA0BnB,oBAAA,YACH,sBACV;;;;;;;iBAkBa,gBAAA"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=1,t=Date.UTC(1970,0,1).valueOf();let n=1;function r(e){let t=BigInt(e).toString(2);return t.length<64?`0000000000000000000000000000000000000000000000000000000000000000`.slice(0,Math.max(0,64-t.length))+t:t}function i(e,t,n){return Number.parseInt(n?r(e).slice(t,t+n):r(e).slice(Math.max(0,t)),2)}function a(e={}){let{shardId:r,epoch:i,timestamp:a}=e??{},o=BigInt(a?a instanceof Date?a.valueOf():new Date(a).valueOf():Date.now())-BigInt(i??t)<<BigInt(22);return o|=BigInt((r??1)%1024)<<BigInt(12),o|=BigInt(n++%4096),o.toString()}function o(e){let t=r(e);return{snowflake:e,timestamp:i(e,1,41),shard_id:i(e,42,10),sequence:i(e,52),binary:t}}function s(e){if(!/^\d{19}$/.test(e))return!1;try{return o(e),!0}catch{return!1}}export{a,s as i,e as n,o as r,t};
|
|
2
|
-
//# sourceMappingURL=snowflake-BtoDXB99.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snowflake-BtoDXB99.mjs","names":["DEFAULT_EPOCH: number","snowflake"],"sources":["../src/snowflake.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Options passed to the `generate` function to create a snowflake identifier.\n */\nexport interface SnowflakeGeneratorOptions {\n /**\n * The id of the shard running this generator.\n *\n * @defaultValue 1\n */\n shardId?: number;\n\n /**\n * The epoch to use for the snowflake.\n *\n * @remarks\n * This is the time in milliseconds since 1 January 1970 00:00:00 UTC.\n *\n * @defaultValue 1420070400000 (Date.UTC(1970, 0, 1).valueOf())\n */\n epoch?: number;\n\n /**\n * The current timestamp to use for the snowflake.\n *\n * @defaultValue Date.now()\n */\n timestamp?: number | Date;\n}\n\n/**\n * Resolvable value types for a valid Snowflake:\n * string\n * number\n * bigint\n */\nexport type SnowflakeResolvable = string;\n\n/**\n * A deconstructed snowflake and the details around it's creation.\n */\nexport interface DeconstructedSnowflake {\n /**\n * Snowflake deconstructed from\n */\n snowflake: SnowflakeResolvable;\n\n /**\n * The timestamp the snowflake was generated\n */\n timestamp: number;\n\n /**\n * The shard_id used when generating\n */\n shard_id: number;\n\n /**\n * The increment of this snowflake\n */\n sequence: number;\n\n /**\n * The 64Bit snowflake binary string\n */\n binary: string;\n}\n\nexport const DEFAULT_SHARD_ID = 1;\nexport const DEFAULT_EPOCH: number = Date.UTC(1970, 0, 1).valueOf();\n\n/**\n * The sequence of the current running generator.\n *\n * @defaultValue 1\n */\nlet sequence = 1;\n\n/**\n * Transform a snowflake into its 64Bit binary string.\n *\n * @param snowflake - Snowflake to transform\n * @returns A 64Bit binary string\n */\nfunction ToBinaryString(snowflake: SnowflakeResolvable): string {\n const cached64BitZeros =\n \"0000000000000000000000000000000000000000000000000000000000000000\";\n const binValue = BigInt(snowflake).toString(2);\n\n return binValue.length < 64\n ? cached64BitZeros.slice(0, Math.max(0, 64 - binValue.length)) + binValue\n : binValue;\n}\n\n/**\n * Extract bits and their values from a snowflake.\n *\n * @param snowflake - Snowflake to extract from\n * @param start - The starting index to extract bits from\n * @param length - Number of bits to extract before stopping\n * @returns A bigint value of the extracted bits\n */\nfunction extractBits(\n snowflake: SnowflakeResolvable,\n start: number,\n length?: number\n): number {\n return Number.parseInt(\n length\n ? ToBinaryString(snowflake).slice(start, start + length)\n : ToBinaryString(snowflake).slice(Math.max(0, start)),\n 2\n );\n}\n\n/**\n * Generate a snowflake identifier.\n *\n * @remarks\n * Snowflakes are 64-bit unsigned integers that are roughly time-ordered.\n *\n * @example\n * ```typescript\n *\n * // Generate a snowflake with the default options\n * const id1 = snowflake();\n *\n * // Generate a snowflake with a custom shard id\n * const id2 = snowflake({ shardId: 2 });\n *\n * // Generate a snowflake with a custom shard id and timestamp\n * const id3 = snowflake({ shardId: 3, timestamp: new Date(\"2021-01-01\") });\n *\n * ```\n *\n * @param options - The options to use when generating the snowflake\n * @returns A snowflake\n */\nexport function snowflake(options: SnowflakeGeneratorOptions = {}): string {\n const { shardId, epoch, timestamp } = options ?? {};\n\n let result =\n (BigInt(\n timestamp\n ? timestamp instanceof Date\n ? timestamp.valueOf()\n : new Date(timestamp).valueOf()\n : Date.now()\n ) -\n BigInt(epoch ?? DEFAULT_EPOCH)) <<\n BigInt(22);\n\n result |= BigInt((shardId ?? DEFAULT_SHARD_ID) % 1024) << BigInt(12);\n result |= BigInt(sequence++ % 4096);\n\n return result.toString();\n}\n\n/**\n * Deconstruct a snowflake to its values using the `epoch`.\n *\n * @param snowflake - Snowflake to deconstruct\n * @returns Either the DeconstructedSnowflake object\n */\nexport function deconstructSnowflake(\n snowflake: SnowflakeResolvable\n): DeconstructedSnowflake {\n const binary = ToBinaryString(snowflake);\n\n return {\n snowflake,\n timestamp: extractBits(snowflake, 1, 41),\n shard_id: extractBits(snowflake, 42, 10),\n sequence: extractBits(snowflake, 52),\n binary\n };\n}\n\n/**\n * Check if a snowflake string Id is valid.\n *\n * @param snowflake - Snowflake to check\n * @returns Whether the snowflake is valid\n */\nexport function isValidSnowflake(snowflake: string): boolean {\n if (!/^\\d{19}$/.test(snowflake)) {\n return false;\n }\n\n try {\n deconstructSnowflake(snowflake);\n\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"AAqFA,MAAa,EAAmB,EACnBA,EAAwB,KAAK,IAAI,KAAM,EAAG,EAAE,CAAC,SAAS,CAOnE,IAAI,EAAW,EAQf,SAAS,EAAe,EAAwC,CAC9D,IAEM,EAAW,OAAOC,EAAU,CAAC,SAAS,EAAE,CAE9C,OAAO,EAAS,OAAS,GACrB,mEAAiB,MAAM,EAAG,KAAK,IAAI,EAAG,GAAK,EAAS,OAAO,CAAC,CAAG,EAC/D,EAWN,SAAS,EACP,EACA,EACA,EACQ,CACR,OAAO,OAAO,SACZ,EACI,EAAeA,EAAU,CAAC,MAAM,EAAO,EAAQ,EAAO,CACtD,EAAeA,EAAU,CAAC,MAAM,KAAK,IAAI,EAAG,EAAM,CAAC,CACvD,EACD,CA0BH,SAAgB,EAAU,EAAqC,EAAE,CAAU,CACzE,GAAM,CAAE,UAAS,QAAO,aAAc,GAAW,EAAE,CAE/C,EACD,OACC,EACI,aAAqB,KACnB,EAAU,SAAS,CACnB,IAAI,KAAK,EAAU,CAAC,SAAS,CAC/B,KAAK,KAAK,CACf,CACC,OAAO,GAAS,EAAc,EAChC,OAAO,GAAG,CAKZ,MAHA,IAAU,QAAQ,GAAW,GAAoB,KAAK,EAAI,OAAO,GAAG,CACpE,GAAU,OAAO,IAAa,KAAK,CAE5B,EAAO,UAAU,CAS1B,SAAgB,EACd,EACwB,CACxB,IAAM,EAAS,EAAeA,EAAU,CAExC,MAAO,CACL,UAAA,EACA,UAAW,EAAYA,EAAW,EAAG,GAAG,CACxC,SAAU,EAAYA,EAAW,GAAI,GAAG,CACxC,SAAU,EAAYA,EAAW,GAAG,CACpC,SACD,CASH,SAAgB,EAAiB,EAA4B,CAC3D,GAAI,CAAC,WAAW,KAAKA,EAAU,CAC7B,MAAO,GAGT,GAAI,CAGF,OAFA,EAAqBA,EAAU,CAExB,QACD,CACN,MAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=1,t=Date.UTC(1970,0,1).valueOf();let n=1;function r(e){let t=BigInt(e).toString(2);return t.length<64?`0000000000000000000000000000000000000000000000000000000000000000`.slice(0,Math.max(0,64-t.length))+t:t}function i(e,t,n){return Number.parseInt(n?r(e).slice(t,t+n):r(e).slice(Math.max(0,t)),2)}function a(e={}){let{shardId:r,epoch:i,timestamp:a}=e??{},o=BigInt(a?a instanceof Date?a.valueOf():new Date(a).valueOf():Date.now())-BigInt(i??t)<<BigInt(22);return o|=BigInt((r??1)%1024)<<BigInt(12),o|=BigInt(n++%4096),o.toString()}function o(e){let t=r(e);return{snowflake:e,timestamp:i(e,1,41),shard_id:i(e,42,10),sequence:i(e,52),binary:t}}function s(e){if(!/^\d{19}$/.test(e))return!1;try{return o(e),!0}catch{return!1}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return 1}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|