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,82 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- /**
4
- * Utilities for
5
- * {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4 | base64}
6
- * encoding and decoding.
7
- *
8
- * ```ts
9
- * import {
10
- * encodeBase64,
11
- * decodeBase64,
12
- * } from "@std/encoding/base64";
13
- * import { assertEquals } from "@std/assert";
14
- *
15
- * const foobar = new TextEncoder().encode("foobar");
16
- *
17
- * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
18
- * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
19
- * ```
20
- *
21
- * @module
22
- */
23
- import { calcSizeBase64, decode, encode } from "./_common64.js";
24
- import { detach } from "./_common_detach.js";
25
- const padding = "=".charCodeAt(0);
26
- const alphabet = new TextEncoder()
27
- .encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
28
- const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length
29
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
30
- /**
31
- * Converts data into a base64-encoded string.
32
- *
33
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
34
- *
35
- * @param data The data to encode.
36
- * @returns The base64-encoded string.
37
- *
38
- * @example Usage
39
- * ```ts
40
- * import { encodeBase64 } from "@std/encoding/base64";
41
- * import { assertEquals } from "@std/assert";
42
- *
43
- * assertEquals(encodeBase64("foobar"), "Zm9vYmFy");
44
- * ```
45
- */
46
- export function encodeBase64(data) {
47
- if (typeof data === "string") {
48
- data = new TextEncoder().encode(data);
49
- }
50
- else if (data instanceof ArrayBuffer)
51
- data = new Uint8Array(data).slice();
52
- else
53
- data = data.slice();
54
- const [output, i] = detach(data, calcSizeBase64(data.length));
55
- encode(output, i, 0, alphabet, padding);
56
- return new TextDecoder().decode(output);
57
- }
58
- /**
59
- * Decodes a base64-encoded string.
60
- *
61
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-4}
62
- *
63
- * @param b64 The base64-encoded string to decode.
64
- * @returns The decoded data.
65
- *
66
- * @example Usage
67
- * ```ts
68
- * import { decodeBase64 } from "@std/encoding/base64";
69
- * import { assertEquals } from "@std/assert";
70
- *
71
- * assertEquals(
72
- * decodeBase64("Zm9vYmFy"),
73
- * new TextEncoder().encode("foobar")
74
- * );
75
- * ```
76
- */
77
- export function decodeBase64(b64) {
78
- const output = new TextEncoder().encode(b64);
79
- // deno-lint-ignore no-explicit-any
80
- return new Uint8Array(output.buffer
81
- .transfer(decode(output, 0, 0, rAlphabet, padding)));
82
- }
@@ -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,72 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- /**
4
- * Utilities for
5
- * {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5 | base64url}
6
- * encoding and decoding.
7
- *
8
- * @module
9
- */
10
- import { calcSizeBase64, decode, encode } from "./_common64.js";
11
- import { detach } from "./_common_detach.js";
12
- const padding = "=".charCodeAt(0);
13
- const alphabet = new TextEncoder()
14
- .encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
15
- const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length
16
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
17
- /**
18
- * Convert data into a base64url-encoded string.
19
- *
20
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
21
- *
22
- * @param data The data to encode.
23
- * @returns The base64url-encoded string.
24
- *
25
- * @example Usage
26
- * ```ts
27
- * import { encodeBase64Url } from "@std/encoding/base64url";
28
- * import { assertEquals } from "@std/assert";
29
- *
30
- * assertEquals(encodeBase64Url("foobar"), "Zm9vYmFy");
31
- * ```
32
- */
33
- export function encodeBase64Url(data) {
34
- if (typeof data === "string") {
35
- data = new TextEncoder().encode(data);
36
- }
37
- else if (data instanceof ArrayBuffer)
38
- data = new Uint8Array(data).slice();
39
- else
40
- data = data.slice();
41
- const [output, i] = detach(data, calcSizeBase64(data.length));
42
- let o = encode(output, i, 0, alphabet, padding);
43
- o = output.indexOf(padding, o - 2);
44
- return new TextDecoder().decode(
45
- // deno-lint-ignore no-explicit-any
46
- o > 0 ? new Uint8Array(output.buffer.transfer(o)) : output);
47
- }
48
- /**
49
- * Decodes a given base64url-encoded string.
50
- *
51
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-5}
52
- *
53
- * @param b64url The base64url-encoded string to decode.
54
- * @returns The decoded data.
55
- *
56
- * @example Usage
57
- * ```ts
58
- * import { decodeBase64Url } from "@std/encoding/base64url";
59
- * import { assertEquals } from "@std/assert";
60
- *
61
- * assertEquals(
62
- * decodeBase64Url("Zm9vYmFy"),
63
- * new TextEncoder().encode("foobar")
64
- * );
65
- * ```
66
- */
67
- export function decodeBase64Url(b64url) {
68
- const output = new TextEncoder().encode(b64url);
69
- // deno-lint-ignore no-explicit-any
70
- return new Uint8Array(output.buffer
71
- .transfer(decode(output, 0, 0, rAlphabet, padding)));
72
- }
@@ -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,87 +0,0 @@
1
- // Copyright 2009 The Go Authors. All rights reserved.
2
- // https://github.com/golang/go/blob/master/LICENSE
3
- // Copyright 2018-2025 the Deno authors. MIT license.
4
- // This module is browser compatible.
5
- /**
6
- * Port of the Go
7
- * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
8
- * library.
9
- *
10
- * ```ts
11
- * import {
12
- * decodeHex,
13
- * encodeHex,
14
- * } from "@std/encoding/hex";
15
- * import { assertEquals } from "@std/assert";
16
- *
17
- * assertEquals(encodeHex("abc"), "616263");
18
- *
19
- * assertEquals(
20
- * decodeHex("616263"),
21
- * new TextEncoder().encode("abc"),
22
- * );
23
- * ```
24
- *
25
- * @module
26
- */
27
- import { calcSizeHex, decode, encode } from "./_common16.js";
28
- import { detach } from "./_common_detach.js";
29
- const alphabet = new TextEncoder()
30
- .encode("0123456789abcdef");
31
- const rAlphabet = new Uint8Array(128).fill(16); // alphabet.length
32
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
33
- new TextEncoder()
34
- .encode("ABCDEF")
35
- .forEach((byte, i) => rAlphabet[byte] = i + 10);
36
- /**
37
- * Converts data into a hex-encoded string.
38
- *
39
- * @param src The data to encode.
40
- *
41
- * @returns The hex-encoded string.
42
- *
43
- * @example Usage
44
- * ```ts
45
- * import { encodeHex } from "@std/encoding/hex";
46
- * import { assertEquals } from "@std/assert";
47
- *
48
- * assertEquals(encodeHex("abc"), "616263");
49
- * ```
50
- */
51
- export function encodeHex(src) {
52
- if (typeof src === "string") {
53
- src = new TextEncoder().encode(src);
54
- }
55
- else if (src instanceof ArrayBuffer)
56
- src = new Uint8Array(src).slice();
57
- else
58
- src = src.slice();
59
- const [output, i] = detach(src, calcSizeHex(src.length));
60
- encode(output, i, 0, alphabet);
61
- return new TextDecoder().decode(output);
62
- }
63
- /**
64
- * Decodes the given hex-encoded string. If the input is malformed, an error is
65
- * thrown.
66
- *
67
- * @param src The hex-encoded string to decode.
68
- *
69
- * @returns The decoded data.
70
- *
71
- * @example Usage
72
- * ```ts
73
- * import { decodeHex } from "@std/encoding/hex";
74
- * import { assertEquals } from "@std/assert";
75
- *
76
- * assertEquals(
77
- * decodeHex("616263"),
78
- * new TextEncoder().encode("abc"),
79
- * );
80
- * ```
81
- */
82
- export function decodeHex(src) {
83
- const output = new TextEncoder().encode(src);
84
- // deno-lint-ignore no-explicit-any
85
- return new Uint8Array(output.buffer
86
- .transfer(decode(output, 0, 0, rAlphabet)));
87
- }
@@ -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"}
@@ -1,99 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- /**
4
- * Utilities for encoding and decoding common formats like hex, base64, and varint.
5
- *
6
- * ## Basic Usage
7
- *
8
- * ```ts
9
- * import { encodeBase64, decodeBase64 } from "@std/encoding";
10
- * import { assertEquals } from "@std/assert";
11
- *
12
- * const foobar = new TextEncoder().encode("foobar");
13
- * assertEquals(encodeBase64(foobar), "Zm9vYmFy");
14
- * assertEquals(decodeBase64("Zm9vYmFy"), foobar);
15
- * ```
16
- *
17
- * ## Various Encoding Formats
18
- *
19
- * ```ts
20
- * import {
21
- * encodeHex,
22
- * encodeBase32,
23
- * encodeBase58,
24
- * encodeBase64,
25
- * encodeAscii85,
26
- * decodeHex,
27
- * decodeBase32,
28
- * decodeBase58,
29
- * decodeBase64,
30
- * decodeAscii85,
31
- * } from "@std/encoding";
32
- * import { assertEquals } from "@std/assert";
33
- *
34
- * // Many different encodings for different character sets
35
- * assertEquals(encodeHex("Hello world!"), "48656c6c6f20776f726c6421");
36
- * assertEquals(encodeBase32("Hello world!"), "JBSWY3DPEB3W64TMMQQQ====");
37
- * assertEquals(encodeBase58("Hello world!"), "2NEpo7TZRhna7vSvL");
38
- * assertEquals(encodeBase64("Hello world!"), "SGVsbG8gd29ybGQh");
39
- * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
40
- *
41
- * // Decoding
42
- * assertEquals(new TextDecoder().decode(decodeHex("48656c6c6f20776f726c6421")), "Hello world!");
43
- * assertEquals(new TextDecoder().decode(decodeBase32("JBSWY3DPEB3W64TMMQQQ====")), "Hello world!");
44
- * assertEquals(new TextDecoder().decode(decodeBase58("2NEpo7TZRhna7vSvL")), "Hello world!");
45
- * assertEquals(new TextDecoder().decode(decodeBase64("SGVsbG8gd29ybGQh")), "Hello world!");
46
- * assertEquals(new TextDecoder().decode(decodeAscii85("87cURD]j7BEbo80")), "Hello world!");
47
- * ```
48
- *
49
- * ## URL-Safe Base64
50
- *
51
- * ```ts
52
- * import { encodeBase64, encodeBase64Url } from "@std/encoding";
53
- * import { assertEquals } from "@std/assert";
54
- *
55
- * assertEquals(encodeBase64("ice creams"), "aWNlIGNyZWFtcw=="); // Not url-safe because of `=`
56
- * assertEquals(encodeBase64Url("ice creams"), "aWNlIGNyZWFtcw"); // URL-safe!
57
- *
58
- * // Base64Url replaces + with - and / with _
59
- * assertEquals(encodeBase64("subjects?"), "c3ViamVjdHM/"); // slash is not URL-safe
60
- * assertEquals(encodeBase64Url("subjects?"), "c3ViamVjdHM_"); // _ is URL-safe
61
- * ```
62
- *
63
- * ## Binary Data Encoding
64
- *
65
- * ```ts
66
- * import { encodeHex, encodeBase64 } from "@std/encoding";
67
- * import { assertEquals } from "@std/assert";
68
- *
69
- * // Working with binary data
70
- * const binaryData = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
71
- * assertEquals(encodeHex(binaryData), "deadbeef");
72
- * assertEquals(encodeBase64(binaryData), "3q2+7w==");
73
- * ```
74
- *
75
- * ## Varint Encoding
76
- *
77
- * Learn more from the [protobuf Varint encoding docs](https://protobuf.dev/programming-guides/encoding/#varints).
78
- *
79
- * ```ts
80
- * import { encodeVarint, decodeVarint } from "@std/encoding";
81
- * import { assertEquals } from "@std/assert";
82
- *
83
- * // Varint encoding support
84
- * assertEquals(encodeVarint(9601n), [new Uint8Array([129, 75]), 2]);
85
- *
86
- * // Decode a varint
87
- * const bytes = new Uint8Array([129, 75]);
88
- * assertEquals(decodeVarint(bytes), [9601n, 2]);
89
- * ```
90
- *
91
- * @module
92
- */
93
- export * from "./ascii85.js";
94
- export * from "./base32.js";
95
- export * from "./base58.js";
96
- export * from "./base64.js";
97
- export * from "./base64url.js";
98
- export * from "./hex.js";
99
- export * from "./varint.js";
@@ -1,120 +0,0 @@
1
- /**
2
- * Utilities for {@link https://protobuf.dev/programming-guides/encoding/#varints Varint} encoding
3
- * of typed integers. Varint encoding represents integers using a variable number of bytes, with
4
- * smaller values requiring fewer bytes.
5
- *
6
- * ```ts
7
- * import { encodeVarint, decodeVarint } from "@std/encoding/varint";
8
- * import { assertEquals } from "@std/assert";
9
- *
10
- * const buf = new Uint8Array(10);
11
- * assertEquals(
12
- * encodeVarint(42n, buf),
13
- * [new Uint8Array([42]), 1]
14
- * );
15
- *
16
- * assertEquals(
17
- * decodeVarint(new Uint8Array([42])),
18
- * [ 42n, 1 ]
19
- * );
20
- * ```
21
- *
22
- * @module
23
- */
24
- import type { Uint8Array_ } from "./_types.js";
25
- export type { Uint8Array_ };
26
- /**
27
- * The maximum value of an unsigned 64-bit integer.
28
- * Equivalent to `2n**64n - 1n`
29
- */
30
- export declare const MaxUint64 = 18446744073709551615n;
31
- /**
32
- * The maximum length, in bytes, of a Varint encoded 64-bit integer.
33
- */
34
- export declare const MaxVarintLen64 = 10;
35
- /**
36
- * The maximum length, in bytes, of a Varint encoded 32-bit integer.
37
- */
38
- export declare const MaxVarintLen32 = 5;
39
- /**
40
- * Given a non empty `buf`, starting at `offset` (default: 0), begin decoding bytes as
41
- * Varint encoded bytes, for a maximum of 10 bytes (offset + 10). The returned
42
- * tuple is of the decoded varint 32-bit number, and the new offset with which
43
- * to continue decoding other data.
44
- *
45
- * If a `bigint` in return is undesired, the `decode32` function will return a
46
- * `number`, but this should only be used in cases where the varint is
47
- * _assured_ to be 32-bits. If in doubt, use `decode()`.
48
- *
49
- * To know how many bytes the Varint took to encode, simply negate `offset`
50
- * from the returned new `offset`.
51
- *
52
- * @param buf The buffer to decode from.
53
- * @param offset The offset to start decoding from.
54
- * @returns A tuple of the decoded varint 64-bit number, and the new offset.
55
- *
56
- * @example Usage
57
- * ```ts
58
- * import { decodeVarint } from "@std/encoding/varint";
59
- * import { assertEquals } from "@std/assert";
60
- *
61
- * const buf = new Uint8Array([0x8E, 0x02]);
62
- * assertEquals(decodeVarint(buf), [270n, 2]);
63
- * ```
64
- */
65
- export declare function decodeVarint(buf: Uint8Array, offset?: number): [bigint, number];
66
- /**
67
- * Given a `buf`, starting at `offset` (default: 0), begin decoding bytes as
68
- * Varint encoded bytes, for a maximum of 5 bytes (offset + 5). The returned
69
- * tuple is of the decoded varint 32-bit number, and the new offset with which
70
- * to continue decoding other data.
71
- *
72
- * Varints are _not 32-bit by default_ so this should only be used in cases
73
- * where the varint is _assured_ to be 32-bits. If in doubt, use `decode()`.
74
- *
75
- * To know how many bytes the Varint took to encode, simply negate `offset`
76
- * from the returned new `offset`.
77
- *
78
- * @param buf The buffer to decode from.
79
- * @param offset The offset to start decoding from.
80
- * @returns A tuple of the decoded varint 32-bit number, and the new offset.
81
- *
82
- * @example Usage
83
- * ```ts
84
- * import { decodeVarint32 } from "@std/encoding/varint";
85
- * import { assertEquals } from "@std/assert";
86
- *
87
- * const buf = new Uint8Array([0x8E, 0x02]);
88
- * assertEquals(decodeVarint32(buf), [270, 2]);
89
- * ```
90
- */
91
- export declare function decodeVarint32(buf: Uint8Array, offset?: number): [number, number];
92
- /**
93
- * Takes unsigned number `num` and converts it into a Varint encoded
94
- * `Uint8Array`, returning a tuple consisting of a `Uint8Array` slice of the
95
- * encoded Varint, and an offset where the Varint encoded bytes end within the
96
- * `Uint8Array`.
97
- *
98
- * If `buf` is not given then a Uint8Array will be created.
99
- * `offset` defaults to `0`.
100
- *
101
- * If passed `buf` then that will be written into, starting at `offset`. The
102
- * resulting returned `Uint8Array` will be a slice of `buf`. The resulting
103
- * returned number is effectively `offset + bytesWritten`.
104
- *
105
- * @param num The number to encode.
106
- * @param buf The buffer to write into.
107
- * @param offset The offset to start writing at.
108
- * @returns A tuple of the encoded Varint `Uint8Array` and the new offset.
109
- *
110
- * @example Usage
111
- * ```ts
112
- * import { encodeVarint } from "@std/encoding/varint";
113
- * import { assertEquals } from "@std/assert";
114
- *
115
- * const buf = new Uint8Array(10);
116
- * assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]);
117
- * ```
118
- */
119
- export declare function encodeVarint(num: bigint | number, buf?: Uint8Array, offset?: number): [Uint8Array_, number];
120
- //# sourceMappingURL=varint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/varint.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC;;GAEG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAahC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D1E;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAe5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,GAAG,GAAE,UAA2C,EAChD,MAAM,SAAI,GACT,CAAC,WAAW,EAAE,MAAM,CAAC,CAuBvB"}