glotto 2.9.0 → 3.0.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 (138) hide show
  1. package/README.md +86 -55
  2. package/esm/cli.js +47 -39
  3. package/esm/deno.d.ts +0 -1
  4. package/esm/deno.js +1 -2
  5. package/esm/src/contants.d.ts +2 -2
  6. package/esm/src/contants.d.ts.map +1 -1
  7. package/esm/src/contants.js +22 -12
  8. package/esm/src/file.d.ts +2 -7
  9. package/esm/src/file.d.ts.map +1 -1
  10. package/esm/src/file.js +1 -108
  11. package/esm/src/providers/anthropic.d.ts +6 -11
  12. package/esm/src/providers/anthropic.d.ts.map +1 -1
  13. package/esm/src/providers/anthropic.js +14 -108
  14. package/esm/src/providers/gemini.d.ts +6 -11
  15. package/esm/src/providers/gemini.d.ts.map +1 -1
  16. package/esm/src/providers/gemini.js +13 -114
  17. package/esm/src/providers/openai.d.ts +6 -11
  18. package/esm/src/providers/openai.d.ts.map +1 -1
  19. package/esm/src/providers/openai.js +10 -109
  20. package/esm/src/translator.d.ts +8 -0
  21. package/esm/src/translator.d.ts.map +1 -0
  22. package/esm/src/translator.js +200 -0
  23. package/esm/src/types.d.ts +28 -11
  24. package/esm/src/types.d.ts.map +1 -1
  25. package/esm/src/utilites.d.ts +0 -6
  26. package/esm/src/utilites.d.ts.map +1 -1
  27. package/esm/src/utilites.js +18 -132
  28. package/package.json +1 -1
  29. package/script/cli.js +45 -37
  30. package/script/deno.d.ts +0 -1
  31. package/script/deno.js +1 -2
  32. package/script/src/contants.d.ts +2 -2
  33. package/script/src/contants.d.ts.map +1 -1
  34. package/script/src/contants.js +23 -13
  35. package/script/src/file.d.ts +2 -7
  36. package/script/src/file.d.ts.map +1 -1
  37. package/script/src/file.js +2 -114
  38. package/script/src/providers/anthropic.d.ts +6 -11
  39. package/script/src/providers/anthropic.d.ts.map +1 -1
  40. package/script/src/providers/anthropic.js +13 -107
  41. package/script/src/providers/gemini.d.ts +6 -11
  42. package/script/src/providers/gemini.d.ts.map +1 -1
  43. package/script/src/providers/gemini.js +12 -113
  44. package/script/src/providers/openai.d.ts +6 -11
  45. package/script/src/providers/openai.d.ts.map +1 -1
  46. package/script/src/providers/openai.js +9 -108
  47. package/script/src/translator.d.ts +8 -0
  48. package/script/src/translator.d.ts.map +1 -0
  49. package/script/src/translator.js +209 -0
  50. package/script/src/types.d.ts +28 -11
  51. package/script/src/types.d.ts.map +1 -1
  52. package/script/src/utilites.d.ts +0 -6
  53. package/script/src/utilites.d.ts.map +1 -1
  54. package/script/src/utilites.js +19 -136
  55. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  56. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  57. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  58. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  59. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  60. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -192
  61. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  62. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  63. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
  64. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  65. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  66. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  67. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  68. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  69. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  70. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  71. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  72. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -26
  73. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  74. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  75. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -152
  76. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  77. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  78. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -87
  79. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  80. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  81. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -131
  82. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  83. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  84. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
  85. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  86. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  87. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -72
  88. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  89. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  90. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  91. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  92. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  93. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -99
  94. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  95. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  96. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -205
  97. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  98. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  99. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -57
  100. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  101. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  102. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -198
  103. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  104. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  105. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
  106. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  107. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  108. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
  109. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  110. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  111. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
  112. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  113. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  114. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -29
  115. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  116. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  117. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -156
  118. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  119. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  120. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -91
  121. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  122. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  123. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -135
  124. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  125. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  126. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
  127. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  128. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  129. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -76
  130. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  131. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  132. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -91
  133. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  134. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  135. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -115
  136. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  137. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  138. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -211
@@ -1,205 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // Copyright 2020 Keith Cirkel. All rights reserved. MIT license.
3
- // Copyright 2023 Skye "MierenManz". All rights reserved. MIT license.
4
- /**
5
- * Utilities for {@link https://protobuf.dev/programming-guides/encoding/#varints Varint} encoding
6
- * of typed integers. Varint encoding represents integers using a variable number of bytes, with
7
- * smaller values requiring fewer bytes.
8
- *
9
- * ```ts
10
- * import { encodeVarint, decodeVarint } from "@std/encoding/varint";
11
- * import { assertEquals } from "@std/assert";
12
- *
13
- * const buf = new Uint8Array(10);
14
- * assertEquals(
15
- * encodeVarint(42n, buf),
16
- * [new Uint8Array([42]), 1]
17
- * );
18
- *
19
- * assertEquals(
20
- * decodeVarint(new Uint8Array([42])),
21
- * [ 42n, 1 ]
22
- * );
23
- * ```
24
- *
25
- * @module
26
- */
27
- /**
28
- * The maximum value of an unsigned 64-bit integer.
29
- * Equivalent to `2n**64n - 1n`
30
- */
31
- export const MaxUint64 = 18446744073709551615n;
32
- /**
33
- * The maximum length, in bytes, of a Varint encoded 64-bit integer.
34
- */
35
- export const MaxVarintLen64 = 10;
36
- /**
37
- * The maximum length, in bytes, of a Varint encoded 32-bit integer.
38
- */
39
- export const MaxVarintLen32 = 5;
40
- const MSB = 0x80;
41
- const REST = 0x7f;
42
- const SHIFT = 7;
43
- const MSBN = 0x80n;
44
- const SHIFTN = 7n;
45
- // ArrayBuffer and TypedArray's for "pointer casting"
46
- const AB = new ArrayBuffer(8);
47
- const U32_VIEW = new Uint32Array(AB);
48
- const U64_VIEW = new BigUint64Array(AB);
49
- /**
50
- * Given a non empty `buf`, starting at `offset` (default: 0), begin decoding bytes as
51
- * Varint encoded bytes, for a maximum of 10 bytes (offset + 10). The returned
52
- * tuple is of the decoded varint 32-bit number, and the new offset with which
53
- * to continue decoding other data.
54
- *
55
- * If a `bigint` in return is undesired, the `decode32` function will return a
56
- * `number`, but this should only be used in cases where the varint is
57
- * _assured_ to be 32-bits. If in doubt, use `decode()`.
58
- *
59
- * To know how many bytes the Varint took to encode, simply negate `offset`
60
- * from the returned new `offset`.
61
- *
62
- * @param buf The buffer to decode from.
63
- * @param offset The offset to start decoding from.
64
- * @returns A tuple of the decoded varint 64-bit number, and the new offset.
65
- *
66
- * @example Usage
67
- * ```ts
68
- * import { decodeVarint } from "@std/encoding/varint";
69
- * import { assertEquals } from "@std/assert";
70
- *
71
- * const buf = new Uint8Array([0x8E, 0x02]);
72
- * assertEquals(decodeVarint(buf), [270n, 2]);
73
- * ```
74
- */
75
- export function decodeVarint(buf, offset = 0) {
76
- // Clear the last result from the Two's complement view
77
- U64_VIEW[0] = 0n;
78
- // Setup the initiat state of the function
79
- let intermediate = 0;
80
- let position = 0;
81
- let i = offset;
82
- // If the buffer is empty Throw
83
- if (buf.length === 0)
84
- throw new RangeError("Cannot read empty buffer");
85
- let byte;
86
- do {
87
- // Get a single byte from the buffer
88
- byte = buf[i];
89
- // 1. Take the lower 7 bits of the byte.
90
- // 2. Shift the bits into the correct position.
91
- // 3. Bitwise OR it with the intermediate value
92
- // QUIRK: in the 5th (and 10th) iteration of this loop it will overflow on the shift.
93
- // This causes only the lower 4 bits to be shifted into place and removing the upper 3 bits
94
- intermediate |= (byte & 0b01111111) << position;
95
- // If position is 28
96
- // it means that this iteration needs to be written the the two's complement view
97
- // This only happens once due to the `-4` in this branch
98
- if (position === 28) {
99
- // Write to the view
100
- U32_VIEW[0] = intermediate;
101
- // set `intermediate` to the remaining 3 bits
102
- // We only want the remaining three bits because the other 4 have been "consumed" on line 21
103
- intermediate = (byte & 0b01110000) >>> 4;
104
- // set `position` to -4 because later 7 will be added, making it 3
105
- position = -4;
106
- }
107
- // Increment the shift position by 7
108
- position += 7;
109
- // Increment the iterator by 1
110
- i++;
111
- // Keep going while there is a continuation bit
112
- } while ((byte & 0b10000000) === 0b10000000);
113
- // subtract the initial offset from `i` to get the bytes read
114
- const nRead = i - offset;
115
- // If 10 bytes have been read and intermediate has overflown
116
- // it means that the varint is malformed
117
- // If 11 bytes have been read it means that the varint is malformed
118
- // If `i` is bigger than the buffer it means we overread the buffer and the varint is malformed
119
- if ((nRead === 10 && intermediate > -1) || nRead === 11 || i > buf.length) {
120
- throw new RangeError("Cannot decode the varint input: Malformed or overflow varint");
121
- }
122
- // Write the intermediate value to the "empty" slot
123
- // if the first slot is taken. Take the second slot
124
- U32_VIEW[Number(nRead > 4)] = intermediate;
125
- return [U64_VIEW[0], i];
126
- }
127
- /**
128
- * Given a `buf`, starting at `offset` (default: 0), begin decoding bytes as
129
- * Varint encoded bytes, for a maximum of 5 bytes (offset + 5). The returned
130
- * tuple is of the decoded varint 32-bit number, and the new offset with which
131
- * to continue decoding other data.
132
- *
133
- * Varints are _not 32-bit by default_ so this should only be used in cases
134
- * where the varint is _assured_ to be 32-bits. If in doubt, use `decode()`.
135
- *
136
- * To know how many bytes the Varint took to encode, simply negate `offset`
137
- * from the returned new `offset`.
138
- *
139
- * @param buf The buffer to decode from.
140
- * @param offset The offset to start decoding from.
141
- * @returns A tuple of the decoded varint 32-bit number, and the new offset.
142
- *
143
- * @example Usage
144
- * ```ts
145
- * import { decodeVarint32 } from "@std/encoding/varint";
146
- * import { assertEquals } from "@std/assert";
147
- *
148
- * const buf = new Uint8Array([0x8E, 0x02]);
149
- * assertEquals(decodeVarint32(buf), [270, 2]);
150
- * ```
151
- */
152
- export function decodeVarint32(buf, offset = 0) {
153
- let shift = 0;
154
- let decoded = 0;
155
- for (let i = offset; i <= Math.min(buf.length, offset + MaxVarintLen32); i += 1, shift += SHIFT) {
156
- const byte = buf[i];
157
- decoded += (byte & REST) * Math.pow(2, shift);
158
- if (!(byte & MSB))
159
- return [decoded, i + 1];
160
- }
161
- throw new RangeError("Cannot decode the varint input: Malformed or overflow varint");
162
- }
163
- /**
164
- * Takes unsigned number `num` and converts it into a Varint encoded
165
- * `Uint8Array`, returning a tuple consisting of a `Uint8Array` slice of the
166
- * encoded Varint, and an offset where the Varint encoded bytes end within the
167
- * `Uint8Array`.
168
- *
169
- * If `buf` is not given then a Uint8Array will be created.
170
- * `offset` defaults to `0`.
171
- *
172
- * If passed `buf` then that will be written into, starting at `offset`. The
173
- * resulting returned `Uint8Array` will be a slice of `buf`. The resulting
174
- * returned number is effectively `offset + bytesWritten`.
175
- *
176
- * @param num The number to encode.
177
- * @param buf The buffer to write into.
178
- * @param offset The offset to start writing at.
179
- * @returns A tuple of the encoded Varint `Uint8Array` and the new offset.
180
- *
181
- * @example Usage
182
- * ```ts
183
- * import { encodeVarint } from "@std/encoding/varint";
184
- * import { assertEquals } from "@std/assert";
185
- *
186
- * const buf = new Uint8Array(10);
187
- * assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]);
188
- * ```
189
- */
190
- export function encodeVarint(num, buf = new Uint8Array(MaxVarintLen64), offset = 0) {
191
- num = BigInt(num);
192
- if (num < 0n) {
193
- throw new RangeError(`Cannot encode the input into varint as it should be non-negative integer: received ${num}`);
194
- }
195
- for (let i = offset; i <= Math.min(buf.length, MaxVarintLen64); i += 1) {
196
- if (num < MSBN) {
197
- buf[i] = Number(num);
198
- i += 1;
199
- return [buf.slice(offset, i), i];
200
- }
201
- buf[i] = Number((num & 0xffn) | MSBN);
202
- num >>= SHIFTN;
203
- }
204
- throw new RangeError(`Cannot encode the input ${num} into varint as it overflows uint64`);
205
- }
@@ -1,23 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- export declare const alphabet: NodeJS.NonSharedUint8Array;
4
- export declare const rAlphabet: Uint8Array<ArrayBuffer>;
5
- /**
6
- * Calculate the output size needed to encode a given input size for
7
- * {@linkcode encodeIntoHex}.
8
- *
9
- * @param originalSize The size of the input buffer.
10
- * @returns The size of the output buffer.
11
- *
12
- * @example Basic Usage
13
- * ```ts
14
- * import { assertEquals } from "@std/assert";
15
- * import { calcSizeHex } from "@std/encoding/unstable-hex";
16
- *
17
- * assertEquals(calcSizeHex(1), 2);
18
- * ```
19
- */
20
- export declare function calcSizeHex(originalSize: number): number;
21
- export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
22
- export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
23
- //# sourceMappingURL=_common16.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_common16.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common16.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,QAAQ,4BAA+C,CAAC;AACrE,eAAO,MAAM,SAAS,yBAA+B,CAAC;AAMtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAOR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAeR"}
@@ -1,57 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2025 the Deno authors. MIT license.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.rAlphabet = exports.alphabet = void 0;
5
- exports.calcSizeHex = calcSizeHex;
6
- exports.encode = encode;
7
- exports.decode = decode;
8
- exports.alphabet = new TextEncoder().encode("0123456789abcdef");
9
- exports.rAlphabet = new Uint8Array(128).fill(16); // alphabet.Hex.length
10
- exports.alphabet.forEach((byte, i) => exports.rAlphabet[byte] = i);
11
- new TextEncoder()
12
- .encode("ABCDEF")
13
- .forEach((byte, i) => exports.rAlphabet[byte] = i + 10);
14
- /**
15
- * Calculate the output size needed to encode a given input size for
16
- * {@linkcode encodeIntoHex}.
17
- *
18
- * @param originalSize The size of the input buffer.
19
- * @returns The size of the output buffer.
20
- *
21
- * @example Basic Usage
22
- * ```ts
23
- * import { assertEquals } from "@std/assert";
24
- * import { calcSizeHex } from "@std/encoding/unstable-hex";
25
- *
26
- * assertEquals(calcSizeHex(1), 2);
27
- * ```
28
- */
29
- function calcSizeHex(originalSize) {
30
- return originalSize * 2;
31
- }
32
- function encode(buffer, i, o, alphabet) {
33
- for (; i < buffer.length; ++i) {
34
- const x = buffer[i];
35
- buffer[o++] = alphabet[x >> 4];
36
- buffer[o++] = alphabet[x & 0xF];
37
- }
38
- return o;
39
- }
40
- function decode(buffer, i, o, alphabet) {
41
- if ((buffer.length - o) % 2 === 1) {
42
- throw new RangeError(`Cannot decode input as hex: Length (${buffer.length - o}) must be divisible by 2`);
43
- }
44
- i += 1;
45
- for (; i < buffer.length; i += 2) {
46
- buffer[o++] = (getByte(buffer[i - 1], alphabet) << 4) |
47
- getByte(buffer[i], alphabet);
48
- }
49
- return o;
50
- }
51
- function getByte(char, alphabet) {
52
- const byte = alphabet[char] ?? 16;
53
- if (byte === 16) { // alphabet.Hex.length
54
- throw new TypeError(`Cannot decode input as hex: Invalid character (${String.fromCharCode(char)})`);
55
- }
56
- return byte;
57
- }
@@ -1,35 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- export declare const padding: number;
4
- export declare const alphabet: Record<Base32Alphabet, Uint8Array>;
5
- export declare const rAlphabet: Record<Base32Alphabet, Uint8Array>;
6
- /**
7
- * Options for encoding and decoding base32 strings.
8
- */
9
- export interface Base32Options {
10
- /** The base32 alphabet. Defaults to "base32" */
11
- alphabet?: Base32Alphabet;
12
- }
13
- /**
14
- * The base32 alphabets.
15
- */
16
- export type Base32Alphabet = "base32" | "base32hex" | "base32crockford";
17
- /**
18
- * Calculate the output size needed to encode a given input size for
19
- * {@linkcode encodeIntoBase32}.
20
- *
21
- * @param rawSize The size of the input buffer.
22
- * @returns The size of the output buffer.
23
- *
24
- * @example Basic Usage
25
- * ```ts
26
- * import { assertEquals } from "@std/assert";
27
- * import { calcSizeBase32 } from "@std/encoding/unstable-base32";
28
- *
29
- * assertEquals(calcSizeBase32(1), 8);
30
- * ```
31
- */
32
- export declare function calcSizeBase32(rawSize: number): number;
33
- export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
34
- export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
35
- //# sourceMappingURL=_common32.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_common32.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common32.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIxD,CAAC;AAQF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmER;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAyFR"}
@@ -1,198 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2025 the Deno authors. MIT license.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.rAlphabet = exports.alphabet = exports.padding = void 0;
5
- exports.calcSizeBase32 = calcSizeBase32;
6
- exports.encode = encode;
7
- exports.decode = decode;
8
- exports.padding = "=".charCodeAt(0);
9
- exports.alphabet = {
10
- base32: new TextEncoder().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),
11
- base32hex: new TextEncoder().encode("0123456789ABCDEFGHIJKLMNOPQRSTUV"),
12
- base32crockford: new TextEncoder().encode("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),
13
- };
14
- exports.rAlphabet = {
15
- base32: new Uint8Array(128).fill(32), // alphabet.base32.length
16
- base32hex: new Uint8Array(128).fill(32),
17
- base32crockford: new Uint8Array(128).fill(32),
18
- };
19
- exports.alphabet.base32
20
- .forEach((byte, i) => exports.rAlphabet.base32[byte] = i);
21
- exports.alphabet.base32hex
22
- .forEach((byte, i) => exports.rAlphabet.base32hex[byte] = i);
23
- exports.alphabet.base32crockford
24
- .forEach((byte, i) => exports.rAlphabet.base32crockford[byte] = i);
25
- /**
26
- * Calculate the output size needed to encode a given input size for
27
- * {@linkcode encodeIntoBase32}.
28
- *
29
- * @param rawSize The size of the input buffer.
30
- * @returns The size of the output buffer.
31
- *
32
- * @example Basic Usage
33
- * ```ts
34
- * import { assertEquals } from "@std/assert";
35
- * import { calcSizeBase32 } from "@std/encoding/unstable-base32";
36
- *
37
- * assertEquals(calcSizeBase32(1), 8);
38
- * ```
39
- */
40
- function calcSizeBase32(rawSize) {
41
- return ((rawSize + 4) / 5 | 0) * 8;
42
- }
43
- function encode(buffer, i, o, alphabet, padding) {
44
- i += 4;
45
- for (; i < buffer.length; i += 5) {
46
- let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
47
- buffer[o++] = alphabet[x >> 19];
48
- buffer[o++] = alphabet[x >> 14 & 0x1F];
49
- buffer[o++] = alphabet[x >> 9 & 0x1F];
50
- buffer[o++] = alphabet[x >> 4 & 0x1F];
51
- x = (x << 16) | (buffer[i - 1] << 8) | buffer[i];
52
- buffer[o++] = alphabet[x >> 15 & 0x1F];
53
- buffer[o++] = alphabet[x >> 10 & 0x1F];
54
- buffer[o++] = alphabet[x >> 5 & 0x1F];
55
- buffer[o++] = alphabet[x & 0x1F];
56
- }
57
- switch (i) {
58
- case buffer.length + 3: {
59
- const x = buffer[i - 4] << 16;
60
- buffer[o++] = alphabet[x >> 19];
61
- buffer[o++] = alphabet[x >> 14 & 0x1F];
62
- buffer[o++] = padding;
63
- buffer[o++] = padding;
64
- buffer[o++] = padding;
65
- buffer[o++] = padding;
66
- buffer[o++] = padding;
67
- buffer[o++] = padding;
68
- break;
69
- }
70
- case buffer.length + 2: {
71
- const x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8);
72
- buffer[o++] = alphabet[x >> 19];
73
- buffer[o++] = alphabet[x >> 14 & 0x1F];
74
- buffer[o++] = alphabet[x >> 9 & 0x1F];
75
- buffer[o++] = alphabet[x >> 4 & 0x1F];
76
- buffer[o++] = padding;
77
- buffer[o++] = padding;
78
- buffer[o++] = padding;
79
- buffer[o++] = padding;
80
- break;
81
- }
82
- case buffer.length + 1: {
83
- let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
84
- buffer[o++] = alphabet[x >> 19];
85
- buffer[o++] = alphabet[x >> 14 & 0x1F];
86
- buffer[o++] = alphabet[x >> 9 & 0x1F];
87
- buffer[o++] = alphabet[x >> 4 & 0x1F];
88
- x <<= 16;
89
- buffer[o++] = alphabet[x >> 15 & 0x1F];
90
- buffer[o++] = padding;
91
- buffer[o++] = padding;
92
- buffer[o++] = padding;
93
- break;
94
- }
95
- case buffer.length: {
96
- let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
97
- buffer[o++] = alphabet[x >> 19];
98
- buffer[o++] = alphabet[x >> 14 & 0x1F];
99
- buffer[o++] = alphabet[x >> 9 & 0x1F];
100
- buffer[o++] = alphabet[x >> 4 & 0x1F];
101
- x = (x << 16) | (buffer[i - 1] << 8);
102
- buffer[o++] = alphabet[x >> 15 & 0x1F];
103
- buffer[o++] = alphabet[x >> 10 & 0x1F];
104
- buffer[o++] = alphabet[x >> 5 & 0x1F];
105
- buffer[o++] = padding;
106
- break;
107
- }
108
- }
109
- return o;
110
- }
111
- function decode(buffer, i, o, alphabet, padding) {
112
- for (let x = buffer.length - 6; x < buffer.length; ++x) {
113
- if (buffer[x] === padding) {
114
- for (let y = x + 1; y < buffer.length; ++y) {
115
- if (buffer[y] !== padding) {
116
- throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(buffer[y])})`);
117
- }
118
- }
119
- buffer = buffer.subarray(0, x);
120
- break;
121
- }
122
- }
123
- switch ((buffer.length - o) % 8) {
124
- case 6:
125
- case 3:
126
- case 1:
127
- throw new RangeError(`Cannot decode input as base32: Length (${buffer.length - o}), excluding padding, must not have a remainder of 1, 3, or 6 when divided by 8`);
128
- }
129
- i += 7;
130
- for (; i < buffer.length; i += 8) {
131
- let x = (getByte(buffer[i - 7], alphabet) << 19) |
132
- (getByte(buffer[i - 6], alphabet) << 14) |
133
- (getByte(buffer[i - 5], alphabet) << 9) |
134
- (getByte(buffer[i - 4], alphabet) << 4);
135
- buffer[o++] = x >> 16;
136
- buffer[o++] = x >> 8 & 0xFF;
137
- x = (x << 16) |
138
- (getByte(buffer[i - 3], alphabet) << 15) |
139
- (getByte(buffer[i - 2], alphabet) << 10) |
140
- (getByte(buffer[i - 1], alphabet) << 5) |
141
- getByte(buffer[i], alphabet);
142
- buffer[o++] = x >> 16 & 0xFF;
143
- buffer[o++] = x >> 8 & 0xFF;
144
- buffer[o++] = x & 0xFF;
145
- }
146
- switch (i) {
147
- case buffer.length + 5: {
148
- const x = (getByte(buffer[i - 7], alphabet) << 19) |
149
- (getByte(buffer[i - 6], alphabet) << 14);
150
- buffer[o++] = x >> 16;
151
- break;
152
- }
153
- case buffer.length + 3: {
154
- const x = (getByte(buffer[i - 7], alphabet) << 19) |
155
- (getByte(buffer[i - 6], alphabet) << 14) |
156
- (getByte(buffer[i - 5], alphabet) << 9) |
157
- (getByte(buffer[i - 4], alphabet) << 4);
158
- buffer[o++] = x >> 16;
159
- buffer[o++] = x >> 8 & 0xFF;
160
- break;
161
- }
162
- case buffer.length + 2: {
163
- let x = (getByte(buffer[i - 7], alphabet) << 19) |
164
- (getByte(buffer[i - 6], alphabet) << 14) |
165
- (getByte(buffer[i - 5], alphabet) << 9) |
166
- (getByte(buffer[i - 4], alphabet) << 4);
167
- buffer[o++] = x >> 16;
168
- buffer[o++] = x >> 8 & 0xFF;
169
- x = (x << 16) |
170
- (getByte(buffer[i - 3], alphabet) << 15);
171
- buffer[o++] = x >> 16 & 0xFF;
172
- break;
173
- }
174
- case buffer.length: {
175
- let x = (getByte(buffer[i - 7], alphabet) << 19) |
176
- (getByte(buffer[i - 6], alphabet) << 14) |
177
- (getByte(buffer[i - 5], alphabet) << 9) |
178
- (getByte(buffer[i - 4], alphabet) << 4);
179
- buffer[o++] = x >> 16;
180
- buffer[o++] = x >> 8 & 0xFF;
181
- x = (x << 16) |
182
- (getByte(buffer[i - 3], alphabet) << 15) |
183
- (getByte(buffer[i - 2], alphabet) << 10) |
184
- (getByte(buffer[i - 1], alphabet) << 5);
185
- buffer[o++] = x >> 16 & 0xFF;
186
- buffer[o++] = x >> 8 & 0xFF;
187
- break;
188
- }
189
- }
190
- return o;
191
- }
192
- function getByte(char, alphabet) {
193
- const byte = alphabet[char] ?? 32;
194
- if (byte === 32) { // alphabet.Base32.length
195
- throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(char)})`);
196
- }
197
- return byte;
198
- }
@@ -1,35 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- export declare const padding: number;
4
- export declare const alphabet: Record<Base64Alphabet, Uint8Array>;
5
- export declare const rAlphabet: Record<Base64Alphabet, Uint8Array>;
6
- /**
7
- * Options for encoding and decoding base64 strings.
8
- */
9
- export interface Base64Options {
10
- /** The base64 alphabet. Defaults to "base64" */
11
- alphabet?: Base64Alphabet;
12
- }
13
- /**
14
- * The base64 alphabets.
15
- */
16
- export type Base64Alphabet = "base64" | "base64url";
17
- /**
18
- * Calculate the output size needed to encode a given input size for
19
- * {@linkcode encodeIntoBase64}.
20
- *
21
- * @param originalSize The size of the input buffer.
22
- * @returns The size of the output buffer.
23
- *
24
- * @example Basic Usage
25
- * ```ts
26
- * import { assertEquals } from "@std/assert";
27
- * import { calcSizeBase64 } from "@std/encoding/unstable-base64";
28
- *
29
- * assertEquals(calcSizeBase64(1), 4);
30
- * ```
31
- */
32
- export declare function calcSizeBase64(originalSize: number): number;
33
- export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
34
- export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
35
- //# sourceMappingURL=_common64.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_common64.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common64.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAKvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAGxD,CAAC;AAMF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CA4BR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmDR"}