glotto 2.9.0 → 3.1.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 (151) hide show
  1. package/README.md +150 -54
  2. package/esm/cli.js +155 -43
  3. package/esm/deno.d.ts +5 -1
  4. package/esm/deno.js +18 -7
  5. package/esm/src/config.d.ts +4 -0
  6. package/esm/src/config.d.ts.map +1 -0
  7. package/esm/src/config.js +95 -0
  8. package/esm/src/contants.d.ts +6 -2
  9. package/esm/src/contants.d.ts.map +1 -1
  10. package/esm/src/contants.js +34 -15
  11. package/esm/src/diff.d.ts +4 -0
  12. package/esm/src/diff.d.ts.map +1 -0
  13. package/esm/src/diff.js +53 -0
  14. package/esm/src/file.d.ts +5 -9
  15. package/esm/src/file.d.ts.map +1 -1
  16. package/esm/src/file.js +14 -103
  17. package/esm/src/providers/anthropic.d.ts +6 -11
  18. package/esm/src/providers/anthropic.d.ts.map +1 -1
  19. package/esm/src/providers/anthropic.js +21 -107
  20. package/esm/src/providers/gemini.d.ts +6 -11
  21. package/esm/src/providers/gemini.d.ts.map +1 -1
  22. package/esm/src/providers/gemini.js +20 -113
  23. package/esm/src/providers/openai.d.ts +6 -11
  24. package/esm/src/providers/openai.d.ts.map +1 -1
  25. package/esm/src/providers/openai.js +17 -108
  26. package/esm/src/translator.d.ts +15 -0
  27. package/esm/src/translator.d.ts.map +1 -0
  28. package/esm/src/translator.js +284 -0
  29. package/esm/src/types.d.ts +58 -13
  30. package/esm/src/types.d.ts.map +1 -1
  31. package/esm/src/utilites.d.ts +3 -10
  32. package/esm/src/utilites.d.ts.map +1 -1
  33. package/esm/src/utilites.js +41 -131
  34. package/package.json +20 -6
  35. package/schema/glotto.schema.json +87 -0
  36. package/script/cli.js +153 -41
  37. package/script/deno.d.ts +5 -1
  38. package/script/deno.js +18 -7
  39. package/script/src/config.d.ts +4 -0
  40. package/script/src/config.d.ts.map +1 -0
  41. package/script/src/config.js +132 -0
  42. package/script/src/contants.d.ts +6 -2
  43. package/script/src/contants.d.ts.map +1 -1
  44. package/script/src/contants.js +35 -16
  45. package/script/src/diff.d.ts +4 -0
  46. package/script/src/diff.d.ts.map +1 -0
  47. package/script/src/diff.js +57 -0
  48. package/script/src/file.d.ts +5 -9
  49. package/script/src/file.d.ts.map +1 -1
  50. package/script/src/file.js +19 -113
  51. package/script/src/providers/anthropic.d.ts +6 -11
  52. package/script/src/providers/anthropic.d.ts.map +1 -1
  53. package/script/src/providers/anthropic.js +20 -106
  54. package/script/src/providers/gemini.d.ts +6 -11
  55. package/script/src/providers/gemini.d.ts.map +1 -1
  56. package/script/src/providers/gemini.js +19 -112
  57. package/script/src/providers/openai.d.ts +6 -11
  58. package/script/src/providers/openai.d.ts.map +1 -1
  59. package/script/src/providers/openai.js +16 -107
  60. package/script/src/translator.d.ts +15 -0
  61. package/script/src/translator.d.ts.map +1 -0
  62. package/script/src/translator.js +294 -0
  63. package/script/src/types.d.ts +58 -13
  64. package/script/src/types.d.ts.map +1 -1
  65. package/script/src/utilites.d.ts +3 -10
  66. package/script/src/utilites.d.ts.map +1 -1
  67. package/script/src/utilites.js +44 -138
  68. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  69. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  70. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  71. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  72. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  73. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -192
  74. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  75. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  76. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
  77. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  78. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  79. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  80. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  81. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  82. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  83. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  84. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  85. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -26
  86. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  87. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  88. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -152
  89. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  90. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  91. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -87
  92. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  93. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  94. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -131
  95. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  96. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  97. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
  98. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  99. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  100. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -72
  101. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  102. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  103. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  104. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  105. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  106. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -99
  107. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  108. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  109. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -205
  110. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  111. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  112. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -57
  113. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  114. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  115. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -198
  116. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  117. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  118. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
  119. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  120. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  121. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
  122. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  123. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  124. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
  125. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  126. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  127. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -29
  128. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  129. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  130. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -156
  131. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  132. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  133. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -91
  134. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  135. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  136. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -135
  137. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  138. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  139. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
  140. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  141. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  142. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -76
  143. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  144. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  145. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -91
  146. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  147. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  148. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -115
  149. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  150. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  151. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -211
@@ -1,135 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2025 the Deno authors. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encodeBase58 = encodeBase58;
6
- exports.decodeBase58 = decodeBase58;
7
- /**
8
- * Utilities for
9
- * {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03 | base58}
10
- * encoding and decoding.
11
- *
12
- * ```ts
13
- * import { encodeBase58, decodeBase58 } from "@std/encoding/base58";
14
- * import { assertEquals } from "@std/assert";
15
- *
16
- * const hello = new TextEncoder().encode("Hello World!");
17
- *
18
- * assertEquals(encodeBase58(hello), "2NEpo7TZRRrLZSi2U");
19
- *
20
- * assertEquals(decodeBase58("2NEpo7TZRRrLZSi2U"), hello);
21
- * ```
22
- *
23
- * @module
24
- */
25
- const _validate_binary_like_js_1 = require("./_validate_binary_like.js");
26
- // deno-fmt-ignore
27
- const mapBase58 = {
28
- "1": 0, "2": 1, "3": 2, "4": 3, "5": 4, "6": 5, "7": 6, "8": 7, "9": 8, A: 9,
29
- B: 10, C: 11, D: 12, E: 13, F: 14, G: 15, H: 16, J: 17, K: 18, L: 19, M: 20,
30
- N: 21, P: 22, Q: 23, R: 24, S: 25, T: 26, U: 27, V: 28, W: 29, X: 30, Y: 31,
31
- Z: 32, a: 33, b: 34, c: 35, d: 36, e: 37, f: 38, g: 39, h: 40, i: 41, j: 42,
32
- k: 43, m: 44, n: 45, o: 46, p: 47, q: 48, r: 49, s: 50, t: 51, u: 52, v: 53,
33
- w: 54, x: 55, y: 56, z: 57
34
- };
35
- const base58alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");
36
- /**
37
- * Converts data into a base58-encoded string.
38
- *
39
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-3}
40
- *
41
- * @param data The data to encode.
42
- * @returns The base58-encoded string.
43
- *
44
- * @example Usage
45
- * ```ts
46
- * import { encodeBase58 } from "@std/encoding/base58";
47
- * import { assertEquals } from "@std/assert";
48
- *
49
- * assertEquals(encodeBase58("Hello World!"), "2NEpo7TZRRrLZSi2U");
50
- * ```
51
- */
52
- function encodeBase58(data) {
53
- const uint8tData = (0, _validate_binary_like_js_1.validateBinaryLike)(data);
54
- let length = 0;
55
- let zeroes = 0;
56
- // Counting leading zeroes
57
- let index = 0;
58
- while (uint8tData[index] === 0) {
59
- zeroes++;
60
- index++;
61
- }
62
- const notZeroUint8Data = uint8tData.slice(index);
63
- const size = Math.round((uint8tData.length * 138) / 100 + 1);
64
- const b58Encoding = [];
65
- notZeroUint8Data.forEach((byte) => {
66
- let i = 0;
67
- let carry = byte;
68
- for (let reverseIterator = size - 1; (carry > 0 || i < length) && reverseIterator !== -1; reverseIterator--, i++) {
69
- carry += (b58Encoding[reverseIterator] ?? 0) * 256;
70
- b58Encoding[reverseIterator] = Math.round(carry % 58);
71
- carry = Math.floor(carry / 58);
72
- }
73
- length = i;
74
- });
75
- const strResult = Array.from({
76
- length: b58Encoding.length + zeroes,
77
- });
78
- if (zeroes > 0) {
79
- strResult.fill("1", 0, zeroes);
80
- }
81
- b58Encoding.forEach((byteValue) => strResult.push(base58alphabet[byteValue]));
82
- return strResult.join("");
83
- }
84
- /**
85
- * Decodes a base58-encoded string.
86
- *
87
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-4}
88
- *
89
- * @param b58 The base58-encoded string to decode.
90
- * @returns The decoded data.
91
- *
92
- * @example Usage
93
- * ```ts
94
- * import { decodeBase58 } from "@std/encoding/base58";
95
- * import { assertEquals } from "@std/assert";
96
- *
97
- * assertEquals(
98
- * decodeBase58("2NEpo7TZRRrLZSi2U"),
99
- * new TextEncoder().encode("Hello World!")
100
- * );
101
- * ```
102
- */
103
- function decodeBase58(b58) {
104
- const splitInput = b58.trim().split("");
105
- let length = 0;
106
- let ones = 0;
107
- // Counting leading ones
108
- let index = 0;
109
- while (splitInput[index] === "1") {
110
- ones++;
111
- index++;
112
- }
113
- const notZeroData = splitInput.slice(index);
114
- const size = Math.round((b58.length * 733) / 1000 + 1);
115
- const output = [];
116
- notZeroData.forEach((char, idx) => {
117
- let carry = mapBase58[char];
118
- let i = 0;
119
- if (carry === undefined) {
120
- throw new TypeError(`Invalid base58 char at index ${idx} with value ${char}`);
121
- }
122
- for (let reverseIterator = size - 1; (carry > 0 || i < length) && reverseIterator !== -1; reverseIterator--, i++) {
123
- carry += 58 * (output[reverseIterator] ?? 0);
124
- output[reverseIterator] = Math.round(carry % 256);
125
- carry = Math.floor(carry / 256);
126
- }
127
- length = i;
128
- });
129
- const validOutput = output.filter((item) => item !== undefined);
130
- if (ones > 0) {
131
- const onesResult = Array.from({ length: ones }).fill(0, 0, ones);
132
- return new Uint8Array([...onesResult, ...validOutput]);
133
- }
134
- return new Uint8Array(validOutput);
135
- }
@@ -1,40 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Converts data into a base64-encoded string.
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
7
- *
8
- * @param data The data to encode.
9
- * @returns The base64-encoded string.
10
- *
11
- * @example Usage
12
- * ```ts
13
- * import { encodeBase64 } from "@std/encoding/base64";
14
- * import { assertEquals } from "@std/assert";
15
- *
16
- * assertEquals(encodeBase64("foobar"), "Zm9vYmFy");
17
- * ```
18
- */
19
- export declare function encodeBase64(data: ArrayBuffer | Uint8Array | string): string;
20
- /**
21
- * Decodes a base64-encoded string.
22
- *
23
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
24
- *
25
- * @param b64 The base64-encoded string to decode.
26
- * @returns The decoded data.
27
- *
28
- * @example Usage
29
- * ```ts
30
- * import { decodeBase64 } from "@std/encoding/base64";
31
- * import { assertEquals } from "@std/assert";
32
- *
33
- * assertEquals(
34
- * decodeBase64("Zm9vYmFy"),
35
- * new TextEncoder().encode("foobar")
36
- * );
37
- * ```
38
- */
39
- export declare function decodeBase64(b64: string): Uint8Array_;
40
- //# sourceMappingURL=base64.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/base64.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAQ5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAW5E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAKrD"}
@@ -1,86 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2025 the Deno authors. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encodeBase64 = encodeBase64;
6
- exports.decodeBase64 = decodeBase64;
7
- /**
8
- * Utilities for
9
- * {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4 | base64}
10
- * encoding and decoding.
11
- *
12
- * ```ts
13
- * import {
14
- * encodeBase64,
15
- * decodeBase64,
16
- * } from "@std/encoding/base64";
17
- * import { assertEquals } from "@std/assert";
18
- *
19
- * const foobar = new TextEncoder().encode("foobar");
20
- *
21
- * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
22
- * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
23
- * ```
24
- *
25
- * @module
26
- */
27
- const _common64_js_1 = require("./_common64.js");
28
- const _common_detach_js_1 = require("./_common_detach.js");
29
- const padding = "=".charCodeAt(0);
30
- const alphabet = new TextEncoder()
31
- .encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
32
- const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length
33
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
34
- /**
35
- * Converts data into a base64-encoded string.
36
- *
37
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
38
- *
39
- * @param data The data to encode.
40
- * @returns The base64-encoded string.
41
- *
42
- * @example Usage
43
- * ```ts
44
- * import { encodeBase64 } from "@std/encoding/base64";
45
- * import { assertEquals } from "@std/assert";
46
- *
47
- * assertEquals(encodeBase64("foobar"), "Zm9vYmFy");
48
- * ```
49
- */
50
- function encodeBase64(data) {
51
- if (typeof data === "string") {
52
- data = new TextEncoder().encode(data);
53
- }
54
- else if (data instanceof ArrayBuffer)
55
- data = new Uint8Array(data).slice();
56
- else
57
- data = data.slice();
58
- const [output, i] = (0, _common_detach_js_1.detach)(data, (0, _common64_js_1.calcSizeBase64)(data.length));
59
- (0, _common64_js_1.encode)(output, i, 0, alphabet, padding);
60
- return new TextDecoder().decode(output);
61
- }
62
- /**
63
- * Decodes a base64-encoded string.
64
- *
65
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
66
- *
67
- * @param b64 The base64-encoded string to decode.
68
- * @returns The decoded data.
69
- *
70
- * @example Usage
71
- * ```ts
72
- * import { decodeBase64 } from "@std/encoding/base64";
73
- * import { assertEquals } from "@std/assert";
74
- *
75
- * assertEquals(
76
- * decodeBase64("Zm9vYmFy"),
77
- * new TextEncoder().encode("foobar")
78
- * );
79
- * ```
80
- */
81
- function decodeBase64(b64) {
82
- const output = new TextEncoder().encode(b64);
83
- // deno-lint-ignore no-explicit-any
84
- return new Uint8Array(output.buffer
85
- .transfer((0, _common64_js_1.decode)(output, 0, 0, rAlphabet, padding)));
86
- }
@@ -1,40 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Convert data into a base64url-encoded string.
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
7
- *
8
- * @param data The data to encode.
9
- * @returns The base64url-encoded string.
10
- *
11
- * @example Usage
12
- * ```ts
13
- * import { encodeBase64Url } from "@std/encoding/base64url";
14
- * import { assertEquals } from "@std/assert";
15
- *
16
- * assertEquals(encodeBase64Url("foobar"), "Zm9vYmFy");
17
- * ```
18
- */
19
- export declare function encodeBase64Url(data: ArrayBuffer | Uint8Array | string): string;
20
- /**
21
- * Decodes a given base64url-encoded string.
22
- *
23
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
24
- *
25
- * @param b64url The base64url-encoded string to decode.
26
- * @returns The decoded data.
27
- *
28
- * @example Usage
29
- * ```ts
30
- * import { decodeBase64Url } from "@std/encoding/base64url";
31
- * import { assertEquals } from "@std/assert";
32
- *
33
- * assertEquals(
34
- * decodeBase64Url("Zm9vYmFy"),
35
- * new TextEncoder().encode("foobar")
36
- * );
37
- * ```
38
- */
39
- export declare function decodeBase64Url(b64url: string): Uint8Array_;
40
- //# sourceMappingURL=base64url.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base64url.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/base64url.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAQ5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GACtC,MAAM,CAeR;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAK3D"}
@@ -1,76 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2025 the Deno authors. MIT license.
3
- // This module is browser compatible.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encodeBase64Url = encodeBase64Url;
6
- exports.decodeBase64Url = decodeBase64Url;
7
- /**
8
- * Utilities for
9
- * {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5 | base64url}
10
- * encoding and decoding.
11
- *
12
- * @module
13
- */
14
- const _common64_js_1 = require("./_common64.js");
15
- const _common_detach_js_1 = require("./_common_detach.js");
16
- const padding = "=".charCodeAt(0);
17
- const alphabet = new TextEncoder()
18
- .encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
19
- const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length
20
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
21
- /**
22
- * Convert data into a base64url-encoded string.
23
- *
24
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
25
- *
26
- * @param data The data to encode.
27
- * @returns The base64url-encoded string.
28
- *
29
- * @example Usage
30
- * ```ts
31
- * import { encodeBase64Url } from "@std/encoding/base64url";
32
- * import { assertEquals } from "@std/assert";
33
- *
34
- * assertEquals(encodeBase64Url("foobar"), "Zm9vYmFy");
35
- * ```
36
- */
37
- function encodeBase64Url(data) {
38
- if (typeof data === "string") {
39
- data = new TextEncoder().encode(data);
40
- }
41
- else if (data instanceof ArrayBuffer)
42
- data = new Uint8Array(data).slice();
43
- else
44
- data = data.slice();
45
- const [output, i] = (0, _common_detach_js_1.detach)(data, (0, _common64_js_1.calcSizeBase64)(data.length));
46
- let o = (0, _common64_js_1.encode)(output, i, 0, alphabet, padding);
47
- o = output.indexOf(padding, o - 2);
48
- return new TextDecoder().decode(
49
- // deno-lint-ignore no-explicit-any
50
- o > 0 ? new Uint8Array(output.buffer.transfer(o)) : output);
51
- }
52
- /**
53
- * Decodes a given base64url-encoded string.
54
- *
55
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
56
- *
57
- * @param b64url The base64url-encoded string to decode.
58
- * @returns The decoded data.
59
- *
60
- * @example Usage
61
- * ```ts
62
- * import { decodeBase64Url } from "@std/encoding/base64url";
63
- * import { assertEquals } from "@std/assert";
64
- *
65
- * assertEquals(
66
- * decodeBase64Url("Zm9vYmFy"),
67
- * new TextEncoder().encode("foobar")
68
- * );
69
- * ```
70
- */
71
- function decodeBase64Url(b64url) {
72
- const output = new TextEncoder().encode(b64url);
73
- // deno-lint-ignore no-explicit-any
74
- return new Uint8Array(output.buffer
75
- .transfer((0, _common64_js_1.decode)(output, 0, 0, rAlphabet, padding)));
76
- }
@@ -1,39 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Converts data into a hex-encoded string.
5
- *
6
- * @param src The data to encode.
7
- *
8
- * @returns The hex-encoded string.
9
- *
10
- * @example Usage
11
- * ```ts
12
- * import { encodeHex } from "@std/encoding/hex";
13
- * import { assertEquals } from "@std/assert";
14
- *
15
- * assertEquals(encodeHex("abc"), "616263");
16
- * ```
17
- */
18
- export declare function encodeHex(src: string | Uint8Array | ArrayBuffer): string;
19
- /**
20
- * Decodes the given hex-encoded string. If the input is malformed, an error is
21
- * thrown.
22
- *
23
- * @param src The hex-encoded string to decode.
24
- *
25
- * @returns The decoded data.
26
- *
27
- * @example Usage
28
- * ```ts
29
- * import { decodeHex } from "@std/encoding/hex";
30
- * import { assertEquals } from "@std/assert";
31
- *
32
- * assertEquals(
33
- * decodeHex("616263"),
34
- * new TextEncoder().encode("abc"),
35
- * );
36
- * ```
37
- */
38
- export declare function decodeHex(src: string): Uint8Array_;
39
- //# sourceMappingURL=hex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/hex.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAU5B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAWxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAKlD"}
@@ -1,91 +0,0 @@
1
- "use strict";
2
- // Copyright 2009 The Go Authors. All rights reserved.
3
- // https://github.com/golang/go/blob/master/LICENSE
4
- // Copyright 2018-2025 the Deno authors. MIT license.
5
- // This module is browser compatible.
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.encodeHex = encodeHex;
8
- exports.decodeHex = decodeHex;
9
- /**
10
- * Port of the Go
11
- * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
12
- * library.
13
- *
14
- * ```ts
15
- * import {
16
- * decodeHex,
17
- * encodeHex,
18
- * } from "@std/encoding/hex";
19
- * import { assertEquals } from "@std/assert";
20
- *
21
- * assertEquals(encodeHex("abc"), "616263");
22
- *
23
- * assertEquals(
24
- * decodeHex("616263"),
25
- * new TextEncoder().encode("abc"),
26
- * );
27
- * ```
28
- *
29
- * @module
30
- */
31
- const _common16_js_1 = require("./_common16.js");
32
- const _common_detach_js_1 = require("./_common_detach.js");
33
- const alphabet = new TextEncoder()
34
- .encode("0123456789abcdef");
35
- const rAlphabet = new Uint8Array(128).fill(16); // alphabet.length
36
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
37
- new TextEncoder()
38
- .encode("ABCDEF")
39
- .forEach((byte, i) => rAlphabet[byte] = i + 10);
40
- /**
41
- * Converts data into a hex-encoded string.
42
- *
43
- * @param src The data to encode.
44
- *
45
- * @returns The hex-encoded string.
46
- *
47
- * @example Usage
48
- * ```ts
49
- * import { encodeHex } from "@std/encoding/hex";
50
- * import { assertEquals } from "@std/assert";
51
- *
52
- * assertEquals(encodeHex("abc"), "616263");
53
- * ```
54
- */
55
- function encodeHex(src) {
56
- if (typeof src === "string") {
57
- src = new TextEncoder().encode(src);
58
- }
59
- else if (src instanceof ArrayBuffer)
60
- src = new Uint8Array(src).slice();
61
- else
62
- src = src.slice();
63
- const [output, i] = (0, _common_detach_js_1.detach)(src, (0, _common16_js_1.calcSizeHex)(src.length));
64
- (0, _common16_js_1.encode)(output, i, 0, alphabet);
65
- return new TextDecoder().decode(output);
66
- }
67
- /**
68
- * Decodes the given hex-encoded string. If the input is malformed, an error is
69
- * thrown.
70
- *
71
- * @param src The hex-encoded string to decode.
72
- *
73
- * @returns The decoded data.
74
- *
75
- * @example Usage
76
- * ```ts
77
- * import { decodeHex } from "@std/encoding/hex";
78
- * import { assertEquals } from "@std/assert";
79
- *
80
- * assertEquals(
81
- * decodeHex("616263"),
82
- * new TextEncoder().encode("abc"),
83
- * );
84
- * ```
85
- */
86
- function decodeHex(src) {
87
- const output = new TextEncoder().encode(src);
88
- // deno-lint-ignore no-explicit-any
89
- return new Uint8Array(output.buffer
90
- .transfer((0, _common16_js_1.decode)(output, 0, 0, rAlphabet)));
91
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Utilities for encoding and decoding common formats like hex, base64, and varint.
3
- *
4
- * ## Basic Usage
5
- *
6
- * ```ts
7
- * import { encodeBase64, decodeBase64 } from "@std/encoding";
8
- * import { assertEquals } from "@std/assert";
9
- *
10
- * const foobar = new TextEncoder().encode("foobar");
11
- * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
12
- * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
13
- * ```
14
- *
15
- * ## Various Encoding Formats
16
- *
17
- * ```ts
18
- * import {
19
- * encodeHex,
20
- * encodeBase32,
21
- * encodeBase58,
22
- * encodeBase64,
23
- * encodeAscii85,
24
- * decodeHex,
25
- * decodeBase32,
26
- * decodeBase58,
27
- * decodeBase64,
28
- * decodeAscii85,
29
- * } from "@std/encoding";
30
- * import { assertEquals } from "@std/assert";
31
- *
32
- * // Many different encodings for different character sets
33
- * assertEquals(encodeHex("Hello world!"), "48656c6c6f20776f726c6421");
34
- * assertEquals(encodeBase32("Hello world!"), "JBSWY3DPEB3W64TMMQQQ====");
35
- * assertEquals(encodeBase58("Hello world!"), "2NEpo7TZRhna7vSvL");
36
- * assertEquals(encodeBase64("Hello world!"), "SGVsbG8gd29ybGQh");
37
- * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
38
- *
39
- * // Decoding
40
- * assertEquals(new TextDecoder().decode(decodeHex("48656c6c6f20776f726c6421")), "Hello world!");
41
- * assertEquals(new TextDecoder().decode(decodeBase32("JBSWY3DPEB3W64TMMQQQ====")), "Hello world!");
42
- * assertEquals(new TextDecoder().decode(decodeBase58("2NEpo7TZRhna7vSvL")), "Hello world!");
43
- * assertEquals(new TextDecoder().decode(decodeBase64("SGVsbG8gd29ybGQh")), "Hello world!");
44
- * assertEquals(new TextDecoder().decode(decodeAscii85("87cURD]j7BEbo80")), "Hello world!");
45
- * ```
46
- *
47
- * ## URL-Safe Base64
48
- *
49
- * ```ts
50
- * import { encodeBase64, encodeBase64Url } from "@std/encoding";
51
- * import { assertEquals } from "@std/assert";
52
- *
53
- * assertEquals(encodeBase64("ice creams"), "aWNlIGNyZWFtcw=="); // Not url-safe because of `=`
54
- * assertEquals(encodeBase64Url("ice creams"), "aWNlIGNyZWFtcw"); // URL-safe!
55
- *
56
- * // Base64Url replaces + with - and / with _
57
- * assertEquals(encodeBase64("subjects?"), "c3ViamVjdHM/"); // slash is not URL-safe
58
- * assertEquals(encodeBase64Url("subjects?"), "c3ViamVjdHM_"); // _ is URL-safe
59
- * ```
60
- *
61
- * ## Binary Data Encoding
62
- *
63
- * ```ts
64
- * import { encodeHex, encodeBase64 } from "@std/encoding";
65
- * import { assertEquals } from "@std/assert";
66
- *
67
- * // Working with binary data
68
- * const binaryData = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
69
- * assertEquals(encodeHex(binaryData), "deadbeef");
70
- * assertEquals(encodeBase64(binaryData), "3q2+7w==");
71
- * ```
72
- *
73
- * ## Varint Encoding
74
- *
75
- * Learn more from the [protobuf Varint encoding docs](https://protobuf.dev/programming-guides/encoding/#varints).
76
- *
77
- * ```ts
78
- * import { encodeVarint, decodeVarint } from "@std/encoding";
79
- * import { assertEquals } from "@std/assert";
80
- *
81
- * // Varint encoding support
82
- * assertEquals(encodeVarint(9601n), [new Uint8Array([129, 75]), 2]);
83
- *
84
- * // Decode a varint
85
- * const bytes = new Uint8Array([129, 75]);
86
- * assertEquals(decodeVarint(bytes), [9601n, 2]);
87
- * ```
88
- *
89
- * @module
90
- */
91
- export * from "./ascii85.js";
92
- export * from "./base32.js";
93
- export * from "./base58.js";
94
- export * from "./base64.js";
95
- export * from "./base64url.js";
96
- export * from "./hex.js";
97
- export * from "./varint.js";
98
- //# sourceMappingURL=mod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/mod.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}