@anizoptera/uuid-slug 0.3.0 → 0.5.0

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 (202) hide show
  1. package/LICENSE +54 -31
  2. package/README.md +373 -324
  3. package/dist/alphabet.d.ts +5 -17
  4. package/dist/alphabet.d.ts.map +1 -1
  5. package/dist/alphabet.js +146 -112
  6. package/dist/alphabet.js.map +1 -1
  7. package/dist/base64url-name.d.ts +7 -0
  8. package/dist/base64url-name.d.ts.map +1 -0
  9. package/dist/base64url-name.js +8 -0
  10. package/dist/base64url-name.js.map +1 -0
  11. package/dist/errors.d.ts +50 -9
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +145 -63
  14. package/dist/errors.js.map +1 -1
  15. package/dist/feistel.js +29 -95
  16. package/dist/feistel.js.map +1 -1
  17. package/dist/generation-options.js +20 -0
  18. package/dist/generation-options.js.map +1 -0
  19. package/dist/index.d.ts +22 -10
  20. package/dist/index.js +21 -9
  21. package/dist/instant.js +83 -0
  22. package/dist/instant.js.map +1 -0
  23. package/dist/mask-handle.d.ts +16 -0
  24. package/dist/mask-handle.d.ts.map +1 -0
  25. package/dist/mask-handle.js +60 -0
  26. package/dist/mask-handle.js.map +1 -0
  27. package/dist/mask.d.ts +27 -0
  28. package/dist/mask.d.ts.map +1 -0
  29. package/dist/mask.js +151 -95
  30. package/dist/mask.js.map +1 -1
  31. package/dist/masking-codec-protocol.js +23 -0
  32. package/dist/masking-codec-protocol.js.map +1 -0
  33. package/dist/masking-codec-types.d.ts +245 -0
  34. package/dist/masking-codec-types.d.ts.map +1 -0
  35. package/dist/masking-codec.d.ts +19 -0
  36. package/dist/masking-codec.d.ts.map +1 -0
  37. package/dist/masking-codec.js +391 -0
  38. package/dist/masking-codec.js.map +1 -0
  39. package/dist/migration.js +114 -51
  40. package/dist/migration.js.map +1 -1
  41. package/dist/node/runtime.js +39 -0
  42. package/dist/node/runtime.js.map +1 -0
  43. package/dist/payload.d.ts +7 -0
  44. package/dist/payload.d.ts.map +1 -0
  45. package/dist/payload.js +118 -0
  46. package/dist/payload.js.map +1 -0
  47. package/dist/runtime/pool.js +21 -46
  48. package/dist/runtime/pool.js.map +1 -1
  49. package/dist/runtime/portable.js +27 -0
  50. package/dist/runtime/portable.js.map +1 -0
  51. package/dist/sentinel.js +10 -0
  52. package/dist/sentinel.js.map +1 -0
  53. package/dist/siphash.js +20 -99
  54. package/dist/siphash.js.map +1 -1
  55. package/dist/slug.d.ts +169 -0
  56. package/dist/slug.d.ts.map +1 -0
  57. package/dist/slug.js +268 -0
  58. package/dist/slug.js.map +1 -0
  59. package/dist/timestamp.d.ts +19 -0
  60. package/dist/timestamp.d.ts.map +1 -0
  61. package/dist/timestamp.js +44 -0
  62. package/dist/timestamp.js.map +1 -0
  63. package/dist/types.d.ts +480 -200
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js +8 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/uuid-value-protocol.js +46 -0
  68. package/dist/uuid-value-protocol.js.map +1 -0
  69. package/dist/uuid-value.d.ts +17 -0
  70. package/dist/uuid-value.d.ts.map +1 -0
  71. package/dist/uuid-value.js +127 -0
  72. package/dist/uuid-value.js.map +1 -0
  73. package/dist/uuid.d.ts +51 -64
  74. package/dist/uuid.d.ts.map +1 -1
  75. package/dist/uuid.js +203 -199
  76. package/dist/uuid.js.map +1 -1
  77. package/dist/v4-slug.d.ts +16 -0
  78. package/dist/v4-slug.d.ts.map +1 -0
  79. package/dist/v4-slug.js +16 -0
  80. package/dist/v4-slug.js.map +1 -0
  81. package/dist/v4.d.ts +42 -0
  82. package/dist/v4.d.ts.map +1 -0
  83. package/dist/v4.js +85 -0
  84. package/dist/v4.js.map +1 -0
  85. package/dist/v7-bounds.d.ts +36 -0
  86. package/dist/v7-bounds.d.ts.map +1 -0
  87. package/dist/v7-bounds.js +49 -0
  88. package/dist/v7-bounds.js.map +1 -0
  89. package/dist/v7-generator-input.js +75 -0
  90. package/dist/v7-generator-input.js.map +1 -0
  91. package/dist/v7-generator.d.ts +43 -0
  92. package/dist/v7-generator.d.ts.map +1 -0
  93. package/dist/v7-generator.js +105 -0
  94. package/dist/v7-generator.js.map +1 -0
  95. package/dist/v7-keyless.d.ts +46 -0
  96. package/dist/v7-keyless.d.ts.map +1 -0
  97. package/dist/v7-keyless.js +106 -0
  98. package/dist/v7-keyless.js.map +1 -0
  99. package/dist/v7-payload.js +54 -0
  100. package/dist/v7-payload.js.map +1 -0
  101. package/dist/v7-slug.d.ts +46 -0
  102. package/dist/v7-slug.d.ts.map +1 -0
  103. package/dist/v7-slug.js +127 -0
  104. package/dist/v7-slug.js.map +1 -0
  105. package/dist/v7-timestamp.js +9 -0
  106. package/dist/v7-timestamp.js.map +1 -0
  107. package/dist/v7-value-options.js +28 -0
  108. package/dist/v7-value-options.js.map +1 -0
  109. package/dist/v7-value.d.ts +23 -0
  110. package/dist/v7-value.d.ts.map +1 -0
  111. package/dist/v7-value.js +31 -0
  112. package/dist/v7-value.js.map +1 -0
  113. package/dist/v7.js +127 -171
  114. package/dist/v7.js.map +1 -1
  115. package/package.json +15 -8
  116. package/src/alphabet.ts +456 -27
  117. package/src/base64url-name.ts +5 -0
  118. package/src/errors.ts +373 -37
  119. package/src/feistel.ts +69 -56
  120. package/src/generation-options.ts +48 -0
  121. package/src/index.ts +134 -80
  122. package/src/instant.ts +196 -0
  123. package/src/keyless.ts +7 -134
  124. package/src/mask-handle.ts +141 -0
  125. package/src/mask.ts +354 -129
  126. package/src/masking-codec-protocol.ts +29 -0
  127. package/src/masking-codec-types.ts +380 -0
  128. package/src/masking-codec.ts +923 -0
  129. package/src/migration.ts +195 -42
  130. package/src/payload.ts +321 -0
  131. package/src/runtime/bun.ts +30 -49
  132. package/src/runtime/node.ts +43 -24
  133. package/src/runtime/pool.ts +49 -21
  134. package/src/runtime/portable.ts +68 -0
  135. package/src/runtime/types.ts +23 -35
  136. package/src/sentinel.ts +13 -0
  137. package/src/siphash.ts +5 -4
  138. package/src/slug.ts +884 -0
  139. package/src/timestamp.ts +122 -0
  140. package/src/types.ts +759 -205
  141. package/src/uuid-value-protocol.ts +77 -0
  142. package/src/uuid-value.ts +341 -0
  143. package/src/uuid.ts +514 -234
  144. package/src/v4-slug.ts +27 -0
  145. package/src/v4.ts +234 -0
  146. package/src/v7-bounds.ts +171 -0
  147. package/src/v7-generator-input.ts +169 -0
  148. package/src/v7-generator.ts +245 -0
  149. package/src/v7-keyless.ts +354 -0
  150. package/src/v7-payload.ts +121 -0
  151. package/src/v7-slug.ts +293 -0
  152. package/src/v7-timestamp.ts +21 -0
  153. package/src/v7-value-options.ts +62 -0
  154. package/src/v7-value.ts +54 -0
  155. package/src/v7.ts +377 -200
  156. package/dist/base64url.d.ts +0 -20
  157. package/dist/base64url.d.ts.map +0 -1
  158. package/dist/base64url.js +0 -33
  159. package/dist/base64url.js.map +0 -1
  160. package/dist/codec.d.ts +0 -17
  161. package/dist/codec.d.ts.map +0 -1
  162. package/dist/codec.js +0 -192
  163. package/dist/codec.js.map +0 -1
  164. package/dist/keyless.d.ts +0 -31
  165. package/dist/keyless.d.ts.map +0 -1
  166. package/dist/keyless.js +0 -93
  167. package/dist/keyless.js.map +0 -1
  168. package/dist/legacy-mask.js +0 -55
  169. package/dist/legacy-mask.js.map +0 -1
  170. package/dist/node/alphabet.js +0 -130
  171. package/dist/node/base64url.js +0 -31
  172. package/dist/node/codec.js +0 -190
  173. package/dist/node/errors.js +0 -78
  174. package/dist/node/feistel.js +0 -103
  175. package/dist/node/index.js +0 -10
  176. package/dist/node/keyless.js +0 -91
  177. package/dist/node/legacy-mask.js +0 -53
  178. package/dist/node/mask.js +0 -106
  179. package/dist/node/migration.js +0 -64
  180. package/dist/node/runtime/node.js +0 -33
  181. package/dist/node/runtime/pool.js +0 -53
  182. package/dist/node/schema.js +0 -214
  183. package/dist/node/siphash.js +0 -106
  184. package/dist/node/uuid.js +0 -226
  185. package/dist/node/v7.js +0 -185
  186. package/dist/node/yield.js +0 -20
  187. package/dist/runtime/web.js +0 -39
  188. package/dist/runtime/web.js.map +0 -1
  189. package/dist/schema.d.ts +0 -20
  190. package/dist/schema.d.ts.map +0 -1
  191. package/dist/schema.js +0 -216
  192. package/dist/schema.js.map +0 -1
  193. package/dist/v7.d.ts +0 -12
  194. package/dist/v7.d.ts.map +0 -1
  195. package/dist/yield.js +0 -22
  196. package/dist/yield.js.map +0 -1
  197. package/src/base64url.ts +0 -41
  198. package/src/codec.ts +0 -320
  199. package/src/legacy-mask.ts +0 -25
  200. package/src/runtime/web.ts +0 -48
  201. package/src/schema.ts +0 -300
  202. package/src/yield.ts +0 -22
package/dist/siphash.js CHANGED
@@ -1,105 +1,26 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- // @anizoptera/uuid-slug 0.3.0 | https://github.com/Anizoptera/uuid-slug#readme
3
- //#region src/siphash.ts
4
- /**
5
- * HalfSipHash-2-4 with 64-bit output — the 32-bit-word member of the SipHash family (Aumasson and
6
- * Bernstein), transcribed from the reference implementation. It is a KEYED pseudorandom function:
7
- * without the key its output on a chosen input is not computable, which is exactly what `mix32` — a
8
- * fixed, public, unkeyed bijection — could never be, and the reason it replaced it.
9
- *
10
- * One primitive serves both callers that need one: the Feistel round function (`feistel.ts`) and the
11
- * key derivation (`schema.ts`). Neither justifies its own.
12
- *
13
- * Chosen over full SipHash-2-4 because that is defined over 64-bit words, which JavaScript has only
14
- * as `BigInt` or as hand-emulated 32-bit pairs — the first far too slow for a hot path, the second a
15
- * re-implementation whose errors nothing would catch. HalfSipHash is 32-bit BY SPECIFICATION, so
16
- * this is a transcription, and `test/siphash.test.ts` holds it to all 64 published vectors. That
17
- * external check is the whole reason a standard primitive beat anything tuned here: nothing in this
18
- * repository can grade a mixing function (see `feistel.ts` — every instrument here passes a
19
- * two-round network), so agreement with a specification somebody else wrote is the only evidence
20
- * available that can actually fail.
21
- *
22
- * Its key is 64 bits. `schema.ts` runs two independently keyed instances and XORs them, the standard
23
- * cascade for widening a PRF's key; see there.
24
- */
25
- /** Message-absorption rounds per block — the `2` of HalfSipHash-**2**-4. */
26
- const C_ROUNDS = 2;
27
- /** Finalisation rounds per output word — the `4` of HalfSipHash-2-**4**. */
28
- const D_ROUNDS = 4;
29
- /**
30
- * HalfSipHash-2-4 over a message supplied as 32-bit LITTLE-ENDIAN words, writing the two output
31
- * words into `out`.
32
- *
33
- * Words rather than bytes because both callers already hold words, and the specification absorbs the
34
- * message in 32-bit little-endian blocks regardless — so this is the same function with the byte
35
- * reassembly left to whoever actually has bytes. Taking a `Uint8Array` would make the hot path pack
36
- * bytes it had just unpacked.
37
- *
38
- * `byteLength` is the message length the specification hashes and stamps into the final block.
39
- * `words` must therefore hold `ceil(byteLength / 4)` entries, with any trailing 1-3 bytes packed
40
- * little-endian into the low bytes of the last one. Internal cooperative callers may pass a
41
- * positive block limit and resume the returned continuation with exactly the same inputs.
42
- */
43
- function halfSipHash(key0, key1, words, byteLength, out, continuation, blockLimit = Infinity) {
44
- let v0 = key0 | 0;
45
- let v1 = key1 ^ 238 | 0;
46
- let v2 = key0 ^ 1819895653 | 0;
47
- let v3 = key1 ^ 1952801890 | 0;
48
- if (continuation) ({v0, v1, v2, v3} = continuation);
49
- const fullWords = byteLength >>> 2;
50
- const spare = byteLength & 3;
51
- const tail = spare === 0 ? 0 : words[fullWords] & (1 << spare * 8) - 1;
52
- const lengthBlock = byteLength << 24 | tail | 0;
53
- const start = continuation?.block ?? 0;
54
- const end = blockLimit === Infinity ? fullWords : Math.min(fullWords, start + blockLimit - 1);
55
- for (let block = start; block <= end; block += 1) {
56
- const m = block === fullWords ? lengthBlock : words[block];
57
- v3 ^= m;
58
- for (let round = 0; round < C_ROUNDS; round += 1) {
59
- v0 = v0 + v1 | 0;
60
- v1 = v1 << 5 | v1 >>> 27;
61
- v1 ^= v0;
62
- v0 = v0 << 16 | v0 >>> 16;
63
- v2 = v2 + v3 | 0;
64
- v3 = v3 << 8 | v3 >>> 24;
65
- v3 ^= v2;
66
- v0 = v0 + v3 | 0;
67
- v3 = v3 << 7 | v3 >>> 25;
68
- v3 ^= v0;
69
- v2 = v2 + v1 | 0;
70
- v1 = v1 << 13 | v1 >>> 19;
71
- v1 ^= v2;
72
- v2 = v2 << 16 | v2 >>> 16;
73
- }
74
- v0 ^= m;
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ function halfSipHash(e, t, n, r, i, a, o = Infinity) {
4
+ let s = e | 0, c = t ^ 238, l = e ^ 1819895653, u = t ^ 1952801890;
5
+ a && ({v0: s, v1: c, v2: l, v3: u} = a);
6
+ let d = r >>> 2, f = r & 3, p = f === 0 ? 0 : n[d] & (1 << f * 8) - 1, m = r << 24 | p, h = a?.block ?? 0, g = o === Infinity ? d : Math.min(d, h + o - 1);
7
+ for (let e = h; e <= g; e += 1) {
8
+ let t = e === d ? m : n[e];
9
+ u ^= t;
10
+ for (let e = 0; e < 2; e += 1) s = s + c | 0, c = c << 5 | c >>> 27, c ^= s, s = s << 16 | s >>> 16, l = l + u | 0, u = u << 8 | u >>> 24, u ^= l, s = s + u | 0, u = u << 7 | u >>> 25, u ^= s, l = l + c | 0, c = c << 13 | c >>> 19, c ^= l, l = l << 16 | l >>> 16;
11
+ s ^= t;
75
12
  }
76
- if (end < fullWords) return {
77
- block: end + 1,
78
- v0,
79
- v1,
80
- v2,
81
- v3
13
+ if (g < d) return {
14
+ block: g + 1,
15
+ v0: s,
16
+ v1: c,
17
+ v2: l,
18
+ v3: u
82
19
  };
83
- v2 ^= 238;
84
- for (let half = 0; half < 2; half += 1) {
85
- for (let round = 0; round < D_ROUNDS; round += 1) {
86
- v0 = v0 + v1 | 0;
87
- v1 = v1 << 5 | v1 >>> 27;
88
- v1 ^= v0;
89
- v0 = v0 << 16 | v0 >>> 16;
90
- v2 = v2 + v3 | 0;
91
- v3 = v3 << 8 | v3 >>> 24;
92
- v3 ^= v2;
93
- v0 = v0 + v3 | 0;
94
- v3 = v3 << 7 | v3 >>> 25;
95
- v3 ^= v0;
96
- v2 = v2 + v1 | 0;
97
- v1 = v1 << 13 | v1 >>> 19;
98
- v1 ^= v2;
99
- v2 = v2 << 16 | v2 >>> 16;
100
- }
101
- out[half] = v1 ^ v3;
102
- v1 ^= 221;
20
+ l ^= 238;
21
+ for (let e = 0; e < 2; e += 1) {
22
+ for (let e = 0; e < 4; e += 1) s = s + c | 0, c = c << 5 | c >>> 27, c ^= s, s = s << 16 | s >>> 16, l = l + u | 0, u = u << 8 | u >>> 24, u ^= l, s = s + u | 0, u = u << 7 | u >>> 25, u ^= s, l = l + c | 0, c = c << 13 | c >>> 19, c ^= l, l = l << 16 | l >>> 16;
23
+ i[e] = c ^ u, c ^= 221;
103
24
  }
104
25
  }
105
26
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"siphash.js","names":[],"sources":["../src/siphash.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * HalfSipHash-2-4 with 64-bit output — the 32-bit-word member of the SipHash family (Aumasson and\n * Bernstein), transcribed from the reference implementation. It is a KEYED pseudorandom function:\n * without the key its output on a chosen input is not computable, which is exactly what `mix32` — a\n * fixed, public, unkeyed bijection — could never be, and the reason it replaced it.\n *\n * One primitive serves both callers that need one: the Feistel round function (`feistel.ts`) and the\n * key derivation (`schema.ts`). Neither justifies its own.\n *\n * Chosen over full SipHash-2-4 because that is defined over 64-bit words, which JavaScript has only\n * as `BigInt` or as hand-emulated 32-bit pairs — the first far too slow for a hot path, the second a\n * re-implementation whose errors nothing would catch. HalfSipHash is 32-bit BY SPECIFICATION, so\n * this is a transcription, and `test/siphash.test.ts` holds it to all 64 published vectors. That\n * external check is the whole reason a standard primitive beat anything tuned here: nothing in this\n * repository can grade a mixing function (see `feistel.ts` — every instrument here passes a\n * two-round network), so agreement with a specification somebody else wrote is the only evidence\n * available that can actually fail.\n *\n * Its key is 64 bits. `schema.ts` runs two independently keyed instances and XORs them, the standard\n * cascade for widening a PRF's key; see there.\n */\n\n/** Message-absorption rounds per block — the `2` of HalfSipHash-**2**-4. */\nconst C_ROUNDS = 2;\n/** Finalisation rounds per output word — the `4` of HalfSipHash-2-**4**. */\nconst D_ROUNDS = 4;\n\n/** Private continuation: resume only with the same message, keys, byte length and output. */\nexport interface HashContinuation {\n readonly block: number;\n readonly v0: number;\n readonly v1: number;\n readonly v2: number;\n readonly v3: number;\n}\n\n/**\n * HalfSipHash-2-4 over a message supplied as 32-bit LITTLE-ENDIAN words, writing the two output\n * words into `out`.\n *\n * Words rather than bytes because both callers already hold words, and the specification absorbs the\n * message in 32-bit little-endian blocks regardless — so this is the same function with the byte\n * reassembly left to whoever actually has bytes. Taking a `Uint8Array` would make the hot path pack\n * bytes it had just unpacked.\n *\n * `byteLength` is the message length the specification hashes and stamps into the final block.\n * `words` must therefore hold `ceil(byteLength / 4)` entries, with any trailing 1-3 bytes packed\n * little-endian into the low bytes of the last one. Internal cooperative callers may pass a\n * positive block limit and resume the returned continuation with exactly the same inputs.\n */\nexport function halfSipHash(\n key0: number,\n key1: number,\n words: Int32Array,\n byteLength: number,\n out: Int32Array,\n continuation?: HashContinuation,\n blockLimit = Infinity,\n): HashContinuation | undefined {\n let v0 = key0 | 0;\n let v1 = (key1 ^ 0xee) | 0;\n let v2 = (key0 ^ 0x6c796765) | 0;\n let v3 = (key1 ^ 0x74656462) | 0;\n if (continuation) ({ v0, v1, v2, v3 } = continuation);\n\n // The length-stamped final block is absorbed exactly like a message block, so it rides the same\n // loop rather than a second copy of it. Seeds may end mid-word; mask blocks use whole words.\n // The reference vectors exercise every tail length, including an empty message.\n const fullWords = byteLength >>> 2;\n const spare = byteLength & 3;\n const tail = spare === 0 ? 0 : (words[fullWords] as number) & ((1 << (spare * 8)) - 1);\n const lengthBlock = (byteLength << 24) | tail | 0;\n const start = continuation?.block ?? 0;\n const end = blockLimit === Infinity ? fullWords : Math.min(fullWords, start + blockLimit - 1);\n for (let block = start; block <= end; block += 1) {\n const m = block === fullWords ? lengthBlock : (words[block] as number);\n v3 ^= m;\n for (let round = 0; round < C_ROUNDS; round += 1) {\n v0 = (v0 + v1) | 0;\n v1 = (v1 << 5) | (v1 >>> 27);\n v1 ^= v0;\n v0 = (v0 << 16) | (v0 >>> 16);\n v2 = (v2 + v3) | 0;\n v3 = (v3 << 8) | (v3 >>> 24);\n v3 ^= v2;\n v0 = (v0 + v3) | 0;\n v3 = (v3 << 7) | (v3 >>> 25);\n v3 ^= v0;\n v2 = (v2 + v1) | 0;\n v1 = (v1 << 13) | (v1 >>> 19);\n v1 ^= v2;\n v2 = (v2 << 16) | (v2 >>> 16);\n }\n v0 ^= m;\n }\n\n // No output is published until absorption and finalisation are complete. The synchronous\n // hot path has an unlimited block budget and never allocates a continuation.\n if (end < fullWords) return { block: end + 1, v0, v1, v2, v3 };\n\n // Two squeezes, and the `0xdd` between them is what makes the second output word something other\n // than a rerun of the first.\n v2 ^= 0xee;\n for (let half = 0; half < 2; half += 1) {\n for (let round = 0; round < D_ROUNDS; round += 1) {\n v0 = (v0 + v1) | 0;\n v1 = (v1 << 5) | (v1 >>> 27);\n v1 ^= v0;\n v0 = (v0 << 16) | (v0 >>> 16);\n v2 = (v2 + v3) | 0;\n v3 = (v3 << 8) | (v3 >>> 24);\n v3 ^= v2;\n v0 = (v0 + v3) | 0;\n v3 = (v3 << 7) | (v3 >>> 25);\n v3 ^= v0;\n v2 = (v2 + v1) | 0;\n v1 = (v1 << 13) | (v1 >>> 19);\n v1 ^= v2;\n v2 = (v2 << 16) | (v2 >>> 16);\n }\n out[half] = v1 ^ v3;\n v1 ^= 0xdd;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,WAAW;;AAEjB,MAAM,WAAW;;;;;;;;;;;;;;;AAyBjB,SAAgB,YACd,MACA,MACA,OACA,YACA,KACA,cACA,aAAa,UACiB;CAC9B,IAAI,KAAK,OAAO;CAChB,IAAI,KAAM,OAAO,MAAQ;CACzB,I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O;GACzB,MAAM;GACN,KAAM,KAAK,KAAM;GACjB,KAAM,MAAM,IAAM,OAAO;GACzB,MAAM;GACN,KAAM,KAAK,KAAM;GACjB,KAAM,MAAM,KAAO,OAAO;GAC1B,MAAM;GACN,KAAM,MAAM,KAAO,OAAO;EAC5B;EACA,IAAI,QAAQ,KAAK;EACjB,MAAM;CACR;AAEF"}
1
+ {"version":3,"file":"siphash.js","names":["v0","key0","v1","key1","v2","v3","continuation","fullWords","byteLength","spare","tail","words","lengthBlock","start","end","blockLimit","block","m","round","half"],"sources":["../src/siphash.ts"],"mappings":";;AAqDA,SAAgB,YACd,GACA,GACA,GACA,GACA,GACA,GACA,IAAa,UACiB;CAC9B,IAAIA,IAAKC,IAAO,GACZC,IAAMC,IAAO,KACbC,IAAMH,IAAO,YACbI,IAAMF,IAAO;CACjB,AAAIG,MAAe,+BAAqBA;CAKxC,IAAMC,IAAYC,MAAe,GAC3BC,IAAQD,IAAa,GACrBE,IAAOD,MAAU,IAAI,IAAKE,EAAMJ,MAA0B,KAAME,IAAQ,KAAM,GAC9EG,IAAeJ,KAAc,KAAME,GACnCG,IAAQP,GAAc,SAAS,GAC/BQ,IAAMC,MAAe,WAAWR,IAAY,KAAK,IAAIA,GAAWM,IAAQE,IAAa,CAAC;CAC5F,KAAK,IAAIC,IAAQH,GAAOG,KAASF,GAAK,KAAS,GAAG;EAChD,IAAMG,IAAID,MAAUT,IAAYK,IAAeD,EAAMK;EACrD,KAAMC;EACN,KAAK,IAAIC,IAAQ,GAAGA,IAAQ,GAAU,KAAS,GAc7C,AAbA,IAAMlB,IAAKE,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAMF,GACN,IAAMA,KAAM,KAAOA,MAAO,IAC1B,IAAMI,IAAKC,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAMD,GACN,IAAMJ,IAAKK,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAML,GACN,IAAMI,IAAKF,IAAM,GACjB,IAAMA,KAAM,KAAOA,MAAO,IAC1B,KAAME,GACN,IAAMA,KAAM,KAAOA,MAAO;EAE5B,KAAMa;CACR;CAIA,IAAIH,IAAMP,GAAW,OAAO;EAAE,OAAOO,IAAM;EAAG;EAAI;EAAI;EAAI;CAAG;CAI7D,KAAM;CACN,KAAK,IAAIK,IAAO,GAAGA,IAAO,GAAG,KAAQ,GAAG;EACtC,KAAK,IAAID,IAAQ,GAAGA,IAAQ,GAAU,KAAS,GAc7C,AAbA,IAAMlB,IAAKE,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAMF,GACN,IAAMA,KAAM,KAAOA,MAAO,IAC1B,IAAMI,IAAKC,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAMD,GACN,IAAMJ,IAAKK,IAAM,GACjB,IAAMA,KAAM,IAAMA,MAAO,IACzB,KAAML,GACN,IAAMI,IAAKF,IAAM,GACjB,IAAMA,KAAM,KAAOA,MAAO,IAC1B,KAAME,GACN,IAAMA,KAAM,KAAOA,MAAO;EAG5B,AADA,EAAIe,KAAQjB,IAAKG,GACjB,KAAM;CACR;AAEF"}
package/dist/slug.d.ts ADDED
@@ -0,0 +1,169 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { UuidSlugError, UuidSlugErrorCode, isUuidSlugError } from "./errors.js";
4
+ import { BASE64URL_NAME } from "./base64url-name.js";
5
+ import { BASE32HEX_NAME } from "./alphabet.js";
6
+ import { KeylessUuidInput, PlainUuidSlug, PlainUuidSlugInput, PlainUuidSlugResult, PlainUuidV4Slug, PlainUuidV7Slug, PlainUuidV7SlugInput, PreserveUuidVersion, UUID_TEXT_LOWERCASE, UuidByteInput, UuidBytes, UuidBytesResult, UuidInput, UuidOutput, UuidStringFor, UuidStringInput, UuidStringResult, UuidTextCase, UuidTextCaseArguments, UuidV4Bytes, UuidV4StringFor, UuidV7Bytes, UuidV7BytesInput, UuidV7Payload, UuidV7PayloadLayout, UuidV7StringFor, UuidV7TimestampInput, UuidV7TimestampWindow, UuidVersion } from "./types.js";
7
+ //#region src/slug.d.ts
8
+ /**
9
+ * Select plain-slug output: 22-character base64url, or 26-character lowercase base32hex.
10
+ * Base64url is shorter. Base32hex UUIDv7 slugs sort by timestamp as plain strings and are safe on
11
+ * case-insensitive filesystems. Decoders infer the alphabet from length. JavaScript also accepts
12
+ * genuine `String` objects where an alphabet is selected.
13
+ */
14
+ export type SlugAlphabet = typeof BASE64URL_NAME | typeof BASE32HEX_NAME;
15
+ /**
16
+ * Encode a standalone 16-byte UUID as a plain slug, using base64url by default. An `ArrayBuffer`
17
+ * uses its whole contents; a `DataView` uses its declared range. Invalid input or alphabet returns
18
+ * `UuidSlugError`. A preceding `UuidSlugError` is returned unchanged.
19
+ *
20
+ * @param bytes - One exact 16-byte UUID source.
21
+ * @param alphabet - Output spelling. Omit for the shorter 22-character base64url form.
22
+ */
23
+ export declare function uuidBytesToPlainSlug(bytes: UuidByteInput | UuidSlugError, alphabet?: SlugAlphabet): PlainUuidSlug | UuidSlugError;
24
+ /**
25
+ * Encode 16 bytes within a larger array as a plain slug. A preceding `UuidSlugError` is returned
26
+ * unchanged.
27
+ *
28
+ * @param bytes - Array containing at least one complete 16-byte UUID.
29
+ * @param byteOffset - Zero-based index where the UUID starts.
30
+ * @param alphabet - Output spelling. Omit for the shorter 22-character base64url form.
31
+ */
32
+ export declare function uuidBytesToPlainSlug(bytes: Uint8Array | UuidSlugError, byteOffset: number, alphabet?: SlugAlphabet): PlainUuidSlug | UuidSlugError;
33
+ /**
34
+ * Decode a canonical plain slug into a new plain 16-byte `Uint8Array`. Its length selects
35
+ * base64url or base32hex. Known UUID and masked values are rejected by TypeScript; invalid input
36
+ * returns `UuidSlugError`. A preceding `UuidSlugError` is returned unchanged.
37
+ *
38
+ * @param plainUuidSlug - Canonical 22-character base64url or 26-character base32hex plain UUID slug.
39
+ * JavaScript also accepts a genuine `String` object.
40
+ */
41
+ export declare function plainSlugToUuidBytes<Input extends string | UuidSlugError>(plainUuidSlug: PlainUuidSlugInput<Input>): PreserveUuidVersion<Input, UuidBytes, UuidV4Bytes, UuidV7Bytes> | UuidSlugError;
42
+ /**
43
+ * Decode a canonical plain slug into caller-owned storage after validating the full input. A
44
+ * preceding `UuidSlugError` is returned unchanged without writing.
45
+ *
46
+ * @param plainUuidSlug - Canonical 22-character base64url or 26-character base32hex plain UUID slug.
47
+ * JavaScript also accepts a genuine `String` object.
48
+ * @param output - Caller-owned array that receives the 16 UUID bytes.
49
+ * @param outputOffset - Zero-based index where writing starts. Omit to start at index 0. Bytes
50
+ * outside the written range stay unchanged.
51
+ */
52
+ export declare function plainSlugToUuidBytes<Input extends string | UuidSlugError, Output extends Uint8Array>(plainUuidSlug: PlainUuidSlugInput<Input>, output: Output, outputOffset?: number): UuidOutput<Output> | UuidSlugError;
53
+ /**
54
+ * Encode accepted mixed-case UUID text as a reversible plain slug, using base64url by default.
55
+ * A known UUID version is preserved in the result type. TypeScript rejects known slug
56
+ * values; invalid text or alphabet returns `UuidSlugError`. A preceding `UuidSlugError` is returned
57
+ * unchanged.
58
+ *
59
+ * @param uuid - UUID text in an accepted spelling. JavaScript also accepts a genuine `String` object.
60
+ * @param alphabet - Output spelling. Omit for the shorter 22-character base64url form.
61
+ */
62
+ export declare function uuidStringToPlainSlug<Input extends string | UuidSlugError>(uuid: UuidStringInput<Input>, alphabet?: SlugAlphabet): PreserveUuidVersion<Input, PlainUuidSlug, PlainUuidV4Slug, PlainUuidV7Slug> | UuidSlugError;
63
+ /**
64
+ * Decode a plain slug to hyphenated UUID text; its length selects base64url or base32hex.
65
+ * Base32hex input accepts uppercase or lowercase. Base64url remains case-sensitive.
66
+ * A known UUID version is preserved in the result type. TypeScript rejects known UUID and masked
67
+ * values; invalid input returns `UuidSlugError`. A preceding `UuidSlugError` is returned unchanged.
68
+ *
69
+ * @param plainUuidSlug - Canonical 22-character base64url or 26-character base32hex plain UUID slug.
70
+ * @param textCase - Built-in output spelling. Omit for lowercase.
71
+ */
72
+ export declare function plainSlugToUuidString<Input extends string | UuidSlugError, Case extends UuidTextCase = typeof UUID_TEXT_LOWERCASE>(plainUuidSlug: PlainUuidSlugInput<Input>, ...textCase: UuidTextCaseArguments<Case>): PreserveUuidVersion<Input, UuidStringFor<Case>, UuidV4StringFor<Case>, UuidV7StringFor<Case>> | UuidSlugError;
73
+ /**
74
+ * Return the four-bit UUID version field from UUID text, exact bytes, or a plain slug after full
75
+ * input validation. This reports the stored field, including zero for nil and 15 for max; it does
76
+ * not prove that the UUID has the RFC variant or that the version is assigned.
77
+ *
78
+ * @param uuid - Any unmasked UUID representation supported by the package.
79
+ */
80
+ export declare function extractUuidVersion<Input extends UuidInput>(uuid: KeylessUuidInput<Input>): UuidVersion | UuidSlugError;
81
+ /**
82
+ * Convert UUID text, bytes, or a plain UUID slug to new or caller-owned UUID bytes.
83
+ * Only `Uint8Array` input accepts a non-zero offset; `0` means the same as omitting it.
84
+ *
85
+ * @param byteOffset - Zero-based index where the UUID starts. Omit for a standalone UUID.
86
+ */
87
+ export declare function uuidToBytes<Input extends UuidInput>(uuid: KeylessUuidInput<Input>): UuidBytesResult<Input>;
88
+ export declare function uuidToBytes<Input extends UuidInput, Output extends Uint8Array>(uuid: KeylessUuidInput<Input>, output: Output, outputOffset?: number): UuidOutput<Output> | UuidSlugError;
89
+ export declare function uuidToBytes(uuid: Uint8Array, byteOffset: number): UuidBytesResult<Uint8Array>;
90
+ export declare function uuidToBytes<Output extends Uint8Array>(uuid: Uint8Array, byteOffset: number, output: Output, outputOffset?: number): UuidOutput<Output> | UuidSlugError;
91
+ /**
92
+ * Convert UUID text, bytes, or a plain UUID slug to normalized UUID text.
93
+ * Only `Uint8Array` input accepts a non-zero offset; `0` means the same as omitting it.
94
+ *
95
+ * @param byteOffset - Zero-based index where the UUID starts. Omit for a standalone UUID.
96
+ */
97
+ export declare function uuidToString<Input extends UuidInput, Case extends UuidTextCase = typeof UUID_TEXT_LOWERCASE>(uuid: KeylessUuidInput<Input>, ...textCase: UuidTextCaseArguments<Case>): UuidStringResult<Input, Case>;
98
+ export declare function uuidToString<Case extends UuidTextCase = typeof UUID_TEXT_LOWERCASE>(uuid: Uint8Array, byteOffset: number, ...textCase: UuidTextCaseArguments<Case>): UuidStringResult<Uint8Array, Case>;
99
+ /**
100
+ * Convert UUID text, bytes, or a plain UUID slug to a plain slug.
101
+ * Only `Uint8Array` input accepts a non-zero offset; `0` means the same as omitting it.
102
+ *
103
+ * @param byteOffset - Zero-based index where the UUID starts. Omit for a standalone UUID.
104
+ */
105
+ export declare function uuidToPlainSlug<Input extends UuidInput>(uuid: KeylessUuidInput<Input>, alphabet?: SlugAlphabet): PlainUuidSlugResult<Input>;
106
+ export declare function uuidToPlainSlug(uuid: Uint8Array, byteOffset: number, alphabet?: SlugAlphabet): PlainUuidSlugResult<Uint8Array>;
107
+ /** Check a canonical 22-character base64url or 26-character lowercase base32hex plain slug. */
108
+ export declare function isPlainUuidSlug(value: unknown): value is PlainUuidSlug;
109
+ /** Check a canonical plain slug whose payload is an RFC-variant UUIDv4. */
110
+ export declare function isPlainUuidV4Slug(value: unknown): value is PlainUuidV4Slug;
111
+ /** Check a canonical plain slug whose payload is an RFC-variant UUIDv7. */
112
+ export declare function isPlainUuidV7Slug(value: unknown): value is PlainUuidV7Slug;
113
+ /**
114
+ * Return the 48-bit Unix millisecond encoded by accepted UUIDv7 text, a plain UUIDv7 slug, or
115
+ * UUIDv7 bytes. Compact and canonical text and both plain slug alphabets avoid a byte allocation.
116
+ * Use `codec.extractMaskedUuidV7UnixMs` for masked or sentinel slugs. Other UUID versions and malformed
117
+ * values return `UuidSlugError`. A preceding `UuidSlugError` is returned unchanged.
118
+ *
119
+ * @param value - UUIDv7 text in an accepted spelling, or a plain UUIDv7 slug in either alphabet.
120
+ */
121
+ export declare function extractUuidV7UnixMs<Input extends string | UuidSlugError>(value: UuidV7TimestampInput<Input>): number | UuidSlugError;
122
+ /**
123
+ * Return the 48-bit Unix millisecond encoded by UUIDv7 bytes. An `ArrayBuffer` uses its whole
124
+ * contents; a `DataView` uses its declared range. Only `Uint8Array` input accepts a non-zero
125
+ * offset; `0` means the same as omitting it.
126
+ *
127
+ * @param value - One supported UUIDv7 byte source.
128
+ * @param byteOffset - Zero-based index where the UUID starts. Omit for a standalone UUID.
129
+ */
130
+ export declare function extractUuidV7UnixMs<Input extends UuidByteInput | UuidSlugError>(value: UuidV7BytesInput<Input>, byteOffset?: number): number | UuidSlugError;
131
+ /** Read Unix milliseconds from supported text/byte unions; a preceding error passes through unchanged. */
132
+ export declare function extractUuidV7UnixMs<Input extends string | UuidByteInput | UuidSlugError>(value: UuidV7TimestampInput<Input>): number | UuidSlugError;
133
+ /**
134
+ * Decode the UUIDv7 payload under a layout supplied by the caller. The UUID does not identify its
135
+ * generator or payload layout, so this operation never guesses. Fraction bits follow RFC 9562
136
+ * Method 3; counter bits immediately follow them as in Method 1. All other bits remain uninterpreted.
137
+ *
138
+ * @param value - UUIDv7 text in an accepted spelling, or a plain UUIDv7 slug in either alphabet.
139
+ * @param layout - Known leading fraction and fixed-counter widths.
140
+ * @returns The millisecond timestamp, declared fields, and every undeclared low payload bit; or a
141
+ * `UuidSlugError` for an invalid UUID, byte range, or layout.
142
+ * @remarks A fraction value `n` in `b` bits identifies the half-open interval
143
+ * `[unixMs + n / 2**b, unixMs + (n + 1) / 2**b)` milliseconds, not an exact instant.
144
+ */
145
+ export declare function extractUuidV7Payload<Input extends string | UuidSlugError>(value: UuidV7TimestampInput<Input>, layout: UuidV7PayloadLayout): UuidV7Payload | UuidSlugError;
146
+ /**
147
+ * Decode a UUIDv7 byte source under the same caller-supplied payload layout. Only `Uint8Array`
148
+ * input accepts a non-zero offset; `0` means the same as omitting it.
149
+ *
150
+ * @param byteOffset - Zero-based index where the UUID starts. Omit for a standalone UUID.
151
+ */
152
+ export declare function extractUuidV7Payload<Input extends UuidByteInput | UuidSlugError>(value: UuidV7BytesInput<Input>, layout: UuidV7PayloadLayout, byteOffset?: number): UuidV7Payload | UuidSlugError;
153
+ /** Interpret supported text/byte unions under the supplied layout; a preceding error passes through unchanged. */
154
+ export declare function extractUuidV7Payload<Input extends string | UuidByteInput | UuidSlugError>(value: UuidV7TimestampInput<Input>, layout: UuidV7PayloadLayout): UuidV7Payload | UuidSlugError;
155
+ /**
156
+ * Return a canonical plain UUIDv7 slug when its timestamp is inside the inclusive symmetric window.
157
+ * Base32hex output is lowercase; case-sensitive base64url is unchanged.
158
+ * Return `timestamp_outside_window` when it is not. Use a codec method for masked or sentinel
159
+ * input. TypeScript rejects known UUID text, masked slugs, and UUIDv4 slugs. A preceding
160
+ * `UuidSlugError` is returned unchanged.
161
+ *
162
+ * @param slug - Plain UUIDv7 slug to validate and normalize. JavaScript also accepts a
163
+ * genuine `String` object.
164
+ * @param window - Inclusive maximum distance from an explicit or current reference time.
165
+ */
166
+ export declare function validatePlainUuidV7SlugUnixMs<Input extends string | UuidSlugError>(slug: PlainUuidV7SlugInput<Input>, window: UuidV7TimestampWindow): (Input extends PlainUuidSlug ? Input & PlainUuidV7Slug : PlainUuidV7Slug) | UuidSlugError;
167
+ //#endregion
168
+ export { UuidSlugError };
169
+ //# sourceMappingURL=slug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.d.ts","names":[],"sources":["../src/slug.ts"],"mappings":";;;;;;;;;;;;;YAgKY,sBAAsB,wBAAwB;;;;;;;;;wBAoD1C,qBACd,OAAO,gBAAgB,eACvB,WAAW,eACV,gBAAgB;;;;;;;;;wBASH,qBACd,OAAO,aAAa,eACpB,oBACA,WAAW,eACV,gBAAgB;;;;;;;;;wBA+CH,qBAAqB,uBAAuB,eAC1D,eAAe,mBAAmB,SACjC,oBAAoB,OAAO,WAAW,aAAa,eAAe;;;;;;;;;;;wBAWrD,qBACd,uBAAuB,eACvB,eAAe,YAEf,eAAe,mBAAmB,QAClC,QA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AAqB,kBAClB;;;;;;;;;;;;;wBAqCI,qBAAqB,uBAAuB,eAC1D,OAAO,qBAAqB,QAC5B,QAAQ,sBACP,gBAAgB;;;;;;;wBAOH,qBAAqB,cAAc,gBAAgB,eACjE,OAAO,iBAAiB,QACxB,QAAQ,qBACR,sBACC,gBAAgB;;wBAEH,qBAAqB,uBAAuB,gBAAgB,eAC1E,OAAO,qBAAqB,QAC5B,QAAQ,sBACP,gBAAgB;;;;;;;;;;;;wBA8CH,8BAA8B,uBAAuB,eACnE,MAAM,qBAAqB,QAC3B,QAAQ,yBACN,cAAc,gBAAgB,QAAQ,kBAAkB,mBAAmB"}
package/dist/slug.js ADDED
@@ -0,0 +1,268 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // @anizoptera/uuid-slug 0.5.0 | https://github.com/Anizoptera/uuid-slug#readme
3
+ import { INVALID_OPTIONS as e, INVALID_UUID as t, INVALID_UUID_SLUG as n, INVALID_UUID_VERSION as r, UuidSlugError as i, checkByteRange as a, checkRange as o, exactLocalUuidBytes as s, isUint8Array as c, isUuidSlugError as l, normalizeUuidSlugInput as u, normalizeUuidStringInput as d, stringInput as f, uuidByteView as p } from "./errors.js";
4
+ import { BASE64URL_NAME as m } from "./base64url-name.js";
5
+ import { BASE32HEX as h, BASE32HEX_NAME as g, BASE64URL as _, decodeInto as v, encode as y, isEncoded as b } from "./alphabet.js";
6
+ import { UUID_TEXT_LOWERCASE as x } from "./types.js";
7
+ import { bytesToUuidString as S, exactUuidByteView as C, formatUuidBytesUnchecked as w, invalidUuidBytes as T, isRfcVariant as E, isUuidString as D, isUuidV7Text as O, resolveUuidTextCase as k, uuidStringToBytes as A, uuidTimestampFromBytesUnchecked as j, uuidVersion as M } from "./uuid.js";
8
+ import { extractPayloadFields as N } from "./v7-payload.js";
9
+ import { validateTimestampBytes as P } from "./timestamp.js";
10
+ import { uuidValueBytes as F } from "./uuid-value-protocol.js";
11
+ import { runtime as I } from "#runtime";
12
+ //#region src/slug.ts
13
+ const L = "Timestamp is only defined for UUIDv7.";
14
+ /*#__NO_SIDE_EFFECTS__*/
15
+ function captureNativePlainUuidBase64() {
16
+ return typeof Bun > "u" ? void 0 : Uint8Array.prototype.toBase64;
17
+ }
18
+ let R = /*#__PURE__*/ captureNativePlainUuidBase64();
19
+ const z = {
20
+ alphabet: m,
21
+ omitPadding: !0
22
+ };
23
+ function uuidBytesToPlainSlugGeneral(t, n, r) {
24
+ let a = typeof n != "number", s = a ? 0 : n, l = /* @__PURE__ */ c(t) ? t : /* @__PURE__ */ C(t);
25
+ if (l instanceof Error) return l;
26
+ let u = /* @__PURE__ */ o(l.length, s, 16);
27
+ if (u) return u;
28
+ if (a && r !== void 0) return new i(e, "Pass the alphabet once: second for a whole UUID, or third after a numeric offset.");
29
+ let d = a ? n : r ?? "base64url", f = d === "base64url" ? _ : d === "base32hex" ? h : /* @__PURE__ */ resolveSlugAlphabet(d);
30
+ return f instanceof Error ? f : /* @__PURE__ */ y(l.length === 16 ? l : l.subarray(s, s + 16), f);
31
+ }
32
+ const B = " or ", V = /* @__PURE__ */ new Uint8Array(16), H = "Only Uint8Array input accepts a non-zero byteOffset. Wrap another buffer in a Uint8Array, or omit the offset.", U = {
33
+ base32hex: h,
34
+ base64url: _
35
+ };
36
+ /*#__NO_SIDE_EFFECTS__*/
37
+ function resolveSlugAlphabet(t) {
38
+ let n = typeof t == "string" ? t : /* @__PURE__ */ f(t);
39
+ return n === "base64url" ? _ : n === "base32hex" ? h : new i(e, `Unknown slug alphabet; expected ${m}${B}${g}.`);
40
+ }
41
+ /*#__NO_SIDE_EFFECTS__*/
42
+ function slugLength(e) {
43
+ return Math.ceil(128 / e.bitsPerChar);
44
+ }
45
+ const W = /*#__PURE__*/ Object.values(U).reduce((e, t) => (e[/* @__PURE__ */ slugLength(t)] = t, e), []), G = /*#__PURE__*/ Object.values(U).map((e) => `${/* @__PURE__ */ slugLength(e)} (${e.name})`).join(B);
46
+ /*#__NO_SIDE_EFFECTS__*/
47
+ function uuidBytesToPlainSlug(e, t = 0, n) {
48
+ if (/* @__PURE__ */ c(e) && e.length === 16) {
49
+ let r = t === 0 ? n ?? "base64url" : n === void 0 ? t : void 0;
50
+ if (r === "base32hex") return /* @__PURE__ */ y(e, h);
51
+ if (r === "base64url") {
52
+ if (R) try {
53
+ return R.call(e, z);
54
+ } catch {
55
+ R = void 0;
56
+ }
57
+ return /* @__PURE__ */ y(e, _);
58
+ }
59
+ }
60
+ return uuidBytesToPlainSlugGeneral(e, t, n);
61
+ }
62
+ function plainSlugToUuidBytes(e, t, r = 0) {
63
+ let s = e;
64
+ if (typeof s != "string" && (s = u(s), typeof s != "string")) return s;
65
+ let c = W[s.length];
66
+ if (!c) return new i(n, s.length === 27 ? "27 characters is a masked base32hex slug; decode it with the codec that issued it." : `UUID slug must be ${G} characters, got ${s.length}.`);
67
+ let l = t ?? /* @__PURE__ */ new Uint8Array(16), d = t === void 0 ? /* @__PURE__ */ o(16, r, 16) : /* @__PURE__ */ a(t, r, 16);
68
+ if (d) return d;
69
+ if (t && !/* @__PURE__ */ b(s, c, 16, !0)) {
70
+ for (let e = 0; e < s.length; e += 1) {
71
+ let t = s.charCodeAt(e);
72
+ if (t >= 128 || c.decode[t] < 0) return new i(c.code, `Invalid ${c.name} character ${JSON.stringify(s[e])} at offset ${e}.`);
73
+ }
74
+ return new i(c.code, `${c.name} value has non-canonical trailing bits.`);
75
+ }
76
+ let f = v(s, c, l, r, 16);
77
+ return f instanceof Error ? f : l;
78
+ }
79
+ /*#__NO_SIDE_EFFECTS__*/
80
+ function uuidStringToPlainSlug(e, t = m) {
81
+ let n = e;
82
+ if (typeof n != "string" && (n = d(n), typeof n != "string")) return n;
83
+ let r = /* @__PURE__ */ resolveSlugAlphabet(t);
84
+ if (r instanceof Error) return r;
85
+ let i = A(n, V);
86
+ return i instanceof Error ? i : /* @__PURE__ */ y(i, r);
87
+ }
88
+ /*#__NO_SIDE_EFFECTS__*/
89
+ function plainSlugToUuidString(e, t = x) {
90
+ let n = k(t);
91
+ if (n instanceof Error) return n;
92
+ let r = e;
93
+ if (typeof r != "string" && (r = u(r), typeof r != "string")) return r;
94
+ let i = W[r.length], a = i ? v(r, i, V, 0, 16) : plainSlugToUuidBytes(r);
95
+ return a instanceof Error ? a : /* @__PURE__ */ w(V, 0, n);
96
+ }
97
+ function decodeKeylessUuid(e) {
98
+ let t;
99
+ if (typeof e == "string") t = e;
100
+ else {
101
+ let n = readObjectUuidInput(e);
102
+ if (typeof n != "string") return n;
103
+ t = n;
104
+ }
105
+ return t.length === 22 || t.length === 26 ? plainSlugToUuidBytes(t) : A(t);
106
+ }
107
+ function readObjectUuidInput(e) {
108
+ let t = p(e);
109
+ return t ? t.length === 16 ? t : /* @__PURE__ */ T() : F(e) || (/* @__PURE__ */ l(e) ? e : /* @__PURE__ */ f(e) ?? /* @__PURE__ */ T());
110
+ }
111
+ function extractUuidVersion(e) {
112
+ let t = /* @__PURE__ */ s(e);
113
+ if (t) return /* @__PURE__ */ M(t, 0);
114
+ let n = decodeKeylessUuid(e);
115
+ return n instanceof Error || n === e && /* @__PURE__ */ l(n) ? n : /* @__PURE__ */ M(n, 0);
116
+ }
117
+ function uuidToBytes(t, n, r, u = 0) {
118
+ let d = typeof n == "number", f = d ? r : n, p = d ? u : r ?? 0, m = f === void 0 ? void 0 : /* @__PURE__ */ a(f, p, 16);
119
+ if (m) return m;
120
+ let h = f;
121
+ if (d) {
122
+ let r = n;
123
+ if (/* @__PURE__ */ c(t)) {
124
+ let e = /* @__PURE__ */ o(t.length, r, 16);
125
+ if (e) return e;
126
+ let n = t.subarray(r, r + 16);
127
+ return h ? (h.set(n, p), h) : new Uint8Array(n);
128
+ }
129
+ if (r !== 0) return new i(e, H);
130
+ }
131
+ let g = /* @__PURE__ */ s(t);
132
+ if (g) return h ? (h.set(g, p), h) : new Uint8Array(g);
133
+ let _ = decodeKeylessUuid(t);
134
+ return _ instanceof Error || _ === t && /* @__PURE__ */ l(_) ? _ : h ? (h.set(_, p), h) : typeof t == "string" ? _ : new Uint8Array(_);
135
+ }
136
+ function uuidToString(t, n = x, r = x) {
137
+ let a;
138
+ if (typeof n == "number") {
139
+ if (/* @__PURE__ */ c(t)) return /* @__PURE__ */ S(t, n, r);
140
+ if (n !== 0) return new i(e, H);
141
+ a = r;
142
+ } else a = n;
143
+ if (a === "lowercase" && D(t)) return t;
144
+ let o = /* @__PURE__ */ s(t);
145
+ if (o) {
146
+ let e = k(a);
147
+ return e instanceof Error ? e : /* @__PURE__ */ w(o, 0, e);
148
+ }
149
+ let u = typeof t == "string" ? t : readObjectUuidInput(t);
150
+ if (typeof u == "string" && u.length === 36) {
151
+ let e = u.toLowerCase();
152
+ if (D(e)) {
153
+ let t = k(a);
154
+ return t instanceof Error ? t : t === "lowercase" ? e : e.toUpperCase();
155
+ }
156
+ }
157
+ let d = typeof u == "string" ? W[u.length] : void 0, f = typeof u == "string" ? d ? v(u, d, V, 0, 16) : A(u) : u, p = typeof f == "number" ? V : f;
158
+ if (p instanceof Error || p === t && /* @__PURE__ */ l(p)) return p;
159
+ let m = k(a);
160
+ return m instanceof Error ? m : /* @__PURE__ */ w(p, 0, m);
161
+ }
162
+ function uuidToPlainSlug(t, n = m, r = m) {
163
+ let a;
164
+ if (typeof n == "number") {
165
+ if (/* @__PURE__ */ c(t)) return /* @__PURE__ */ uuidBytesToPlainSlug(t, n, r);
166
+ if (n !== 0) return new i(e, H);
167
+ a = r;
168
+ } else a = n;
169
+ let o = /* @__PURE__ */ s(t);
170
+ if (o) return /* @__PURE__ */ uuidBytesToPlainSlug(o, a);
171
+ let u = decodeKeylessUuid(t);
172
+ return u instanceof Error || u === t && /* @__PURE__ */ l(u) ? u : /* @__PURE__ */ uuidBytesToPlainSlug(u, a);
173
+ }
174
+ /*#__NO_SIDE_EFFECTS__*/
175
+ function isPlainUuidSlug(e) {
176
+ if (typeof e != "string" || !e) return !1;
177
+ let t = W[e.length];
178
+ return t !== void 0 && /* @__PURE__ */ b(e, t, 16);
179
+ }
180
+ /*#__NO_SIDE_EFFECTS__*/
181
+ function slugByte(e, t, n) {
182
+ let r = Math.floor(n * 8 / t.bitsPerChar), i = Math.floor((n * 8 + 7) / t.bitsPerChar), a = 0;
183
+ for (let n = r; n <= i; n += 1) a = a << t.bitsPerChar | t.decode[e.charCodeAt(n)];
184
+ return a >>> (i + 1) * t.bitsPerChar - (n + 1) * 8 & 255;
185
+ }
186
+ /*#__NO_SIDE_EFFECTS__*/
187
+ function isVersionedSlug(e, t) {
188
+ if (!/* @__PURE__ */ isPlainUuidSlug(e)) return !1;
189
+ let n = W[e.length];
190
+ return /* @__PURE__ */ slugByte(e, n, 6) >>> 4 === t && /* @__PURE__ */ slugByte(e, n, 8) >>> 6 == 2;
191
+ }
192
+ /*#__NO_SIDE_EFFECTS__*/
193
+ function isPlainUuidV4Slug(e) {
194
+ return /* @__PURE__ */ isVersionedSlug(e, 4);
195
+ }
196
+ /*#__NO_SIDE_EFFECTS__*/
197
+ function isPlainUuidV7Slug(e) {
198
+ return /* @__PURE__ */ isVersionedSlug(e, 7);
199
+ }
200
+ function validatedHexNibble(e, t) {
201
+ let n = e.charCodeAt(t);
202
+ return (n & 15) + (n > 57 ? 9 : 0);
203
+ }
204
+ function fixedCanonicalUuidV7UnixMs(e) {
205
+ let t = validatedHexNibble(e, 0) << 12 | validatedHexNibble(e, 1) << 8 | validatedHexNibble(e, 2) << 4 | validatedHexNibble(e, 3), n = (validatedHexNibble(e, 4) << 28 | validatedHexNibble(e, 5) << 24 | validatedHexNibble(e, 6) << 20 | validatedHexNibble(e, 7) << 16 | validatedHexNibble(e, 9) << 12 | validatedHexNibble(e, 10) << 8 | validatedHexNibble(e, 11) << 4 | validatedHexNibble(e, 12)) >>> 0;
206
+ return t * 4294967296 + n;
207
+ }
208
+ function parsedCanonicalUuidV7UnixMs(e) {
209
+ return parseInt(e.slice(0, 8) + e.slice(9, 13), 16);
210
+ }
211
+ const K = I.jitless ? parsedCanonicalUuidV7UnixMs : fixedCanonicalUuidV7UnixMs;
212
+ /*#__NO_SIDE_EFFECTS__*/
213
+ function extractStringTimestamp(e) {
214
+ let n = 0;
215
+ if (/* @__PURE__ */ O(e) && (e.length === 32 || e.length === 36)) return e.length === 36 ? K(e) : parseInt(e.slice(0, 12), 16);
216
+ if (/* @__PURE__ */ isPlainUuidV7Slug(e)) {
217
+ let t = W[e.length];
218
+ for (let r = 0; r < 6; r += 1) n = n * 256 + /* @__PURE__ */ slugByte(e, t, r);
219
+ return n;
220
+ }
221
+ let a = A(e);
222
+ return a instanceof Error ? /* @__PURE__ */ isPlainUuidSlug(e) ? new i(r, L) : new i(t, "Expected UUIDv7 text or a plain UUIDv7 slug.") : /* @__PURE__ */ M(a) !== 7 || !/* @__PURE__ */ E(a) ? new i(r, L) : /* @__PURE__ */ j(a, 0);
223
+ }
224
+ /*#__NO_SIDE_EFFECTS__*/
225
+ function extractUuidV7UnixMs(t, n = 0) {
226
+ if (typeof t == "string") return n === 0 ? /* @__PURE__ */ extractStringTimestamp(t) : new i(e, H);
227
+ if (/* @__PURE__ */ l(t)) return t;
228
+ if (n !== 0 && !/* @__PURE__ */ c(t)) return new i(e, H);
229
+ let a = /* @__PURE__ */ c(t) ? t : /* @__PURE__ */ C(t);
230
+ if (a instanceof Error) {
231
+ let e = /* @__PURE__ */ f(t);
232
+ return e === void 0 ? a : /* @__PURE__ */ extractStringTimestamp(e);
233
+ }
234
+ return /* @__PURE__ */ o(a.length, n, 16) || (/* @__PURE__ */ M(a, n) !== 7 || !/* @__PURE__ */ E(a, n) ? new i(r, L) : /* @__PURE__ */ j(a, n));
235
+ }
236
+ /*#__NO_SIDE_EFFECTS__*/
237
+ function extractUuidV7Payload(t, n, a = 0) {
238
+ let s;
239
+ if (typeof t == "string") {
240
+ if (a !== 0) return new i(e, H);
241
+ s = decodeKeylessUuid(t);
242
+ } else if (/* @__PURE__ */ l(t)) return t;
243
+ else {
244
+ if (a !== 0 && !/* @__PURE__ */ c(t)) return new i(e, H);
245
+ if (s = /* @__PURE__ */ c(t) ? t : /* @__PURE__ */ C(t), s instanceof Error) {
246
+ let e = /* @__PURE__ */ f(t);
247
+ e !== void 0 && (s = uuidToBytes(e));
248
+ }
249
+ }
250
+ return s instanceof Error ? s : /* @__PURE__ */ o(s.length, a, 16) || (/* @__PURE__ */ M(s, a) !== 7 || !/* @__PURE__ */ E(s, a) ? new i(r, L) : N(s, a, /* @__PURE__ */ j(s, a), n));
251
+ }
252
+ function validatePlainUuidV7SlugUnixMs(e, t) {
253
+ let n;
254
+ if (typeof e == "string") n = e;
255
+ else {
256
+ let t = u(e);
257
+ if (typeof t != "string") return t;
258
+ n = t;
259
+ }
260
+ let r = W[n.length], i = r ? v(n, r, V, 0, 16) : plainSlugToUuidBytes(n);
261
+ if (i instanceof Error) return i;
262
+ let a = P(typeof i == "number" ? V : i, t);
263
+ return a instanceof Error ? a : n.length === 22 ? n : n.toLowerCase();
264
+ }
265
+ //#endregion
266
+ export { i as UuidSlugError, decodeKeylessUuid, extractUuidV7Payload, extractUuidV7UnixMs, extractUuidVersion, isPlainUuidSlug, isPlainUuidV4Slug, isPlainUuidV7Slug, plainSlugToUuidBytes, plainSlugToUuidString, readObjectUuidInput, resolveSlugAlphabet, uuidBytesToPlainSlug, uuidStringToPlainSlug, uuidToBytes, uuidToPlainSlug, uuidToString, validatePlainUuidV7SlugUnixMs };
267
+
268
+ //# sourceMappingURL=slug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.js","names":["UUID_V7_TIMESTAMP_ONLY","nativePlainUuidBase64","NATIVE_PLAIN_UUID_BASE64_OPTIONS","BASE64URL_NAME","alphabetIsSecond","offsetOrAlphabet","offset","view","bytes","badRange","alphabet","UuidSlugError","INVALID_OPTIONS","selectedAlphabet","alpha","BASE64URL","BASE32HEX","ALTERNATIVE_SEPARATOR","textSlugScratch","BYTE_OFFSET_NEEDS_BYTES","SLUG_ALPHABET_CODECS","name","BASE32HEX_NAME","SLUG_ALPHABET_BY_LENGTH","table","SLUG_LENGTHS","slug","plainUuidSlug","normalizeUuidSlugInput","INVALID_UUID_SLUG","target","output","outputOffset","i","code","result","decodeInto","uuidText","uuid","normalizeUuidStringInput","uuidStringToBytes","UUID_TEXT_LOWERCASE","selectedCase","resolveUuidTextCase","textCase","decoded","text","input","uuidByteView","uuidValueBytes","localBytes","readsAtOffset","outputOrByteOffset","outputOrOutputOffset","offsetAfterOutput","destination","byteOffset","badSource","source","byteOffsetOrCase","caseAfterOffset","isUuidString","lower","byteOffsetOrAlphabet","alphabetAfterOffset","value","start","end","version","index","high","low","canonicalUuidV7UnixMsUnchecked","runtime","timestamp","INVALID_UUID_VERSION","INVALID_UUID","checkRange","extractPayloadFields","layout","plainSlug","normalized","valid","validateTimestampBytes","window"],"sources":["../src/slug.ts"],"mappings":";;;;;;;;;;;;AAmFA,MAAMA,IAAyB;;AAI/B,SAAS,+BAA+B;CACtC,OAAO,OAAO,MAAQ,MAClB,KAAA,IAEE,WAAW,UAGX;AACR;AACA,IAAIC,IAAsC,2CAA6B;AACvE,MAAMC,IAAmC;CAAE,UAAUC;CAAgB,aAAa;AAAK;AAGvF,SAAS,4BACP,GACA,GACA,GAC+B;CAC/B,IAAMC,IAAmB,OAAOC,KAAqB,UAC/CC,IAASF,IAAmB,IAAIC,GAChCE,IAAO,kBAAaC,CAAK,IAAIA,IAAQ,kBAAkBA,CAAK;CAClE,IAAID,aAAgB,OAAO,OAAOA;CAClC,IAAME,IAAW,kBAAWF,EAAK,QAAQD,GAAQ,EAAE;CACnD,IAAIG,GAAU,OAAOA;CACrB,IAAIL,KAAoBM,MAAa,KAAA,GACnC,OAAO,IAAIC,EACTC,GACA,mFACF;CAKF,IAAMC,IAAmBT,IAAmBC,IAAoBK,KAAA,aAC1DI,IACJD,MAAA,cACIE,IACAF,MAAA,cACEG,IACA,oCAAoBH,CAAgB;CAE5C,OADIC,aAAiB,QAAcA,IAC5B,kBACLP,EAAK,WAAW,KAAKA,IAAOA,EAAK,SAASD,GAAQA,IAAS,EAA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