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,13 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- export function detach(buffer, maxSize) {
3
- const originalSize = buffer.length;
4
- if (buffer.byteOffset) {
5
- const b = new Uint8Array(buffer.buffer);
6
- b.set(buffer);
7
- buffer = b.subarray(0, originalSize);
8
- }
9
- // deno-lint-ignore no-explicit-any
10
- buffer = new Uint8Array(buffer.buffer.transfer(maxSize));
11
- buffer.set(buffer.subarray(0, originalSize), maxSize - originalSize);
12
- return [buffer, maxSize - originalSize];
13
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Proxy type of {@code Uint8Array<ArrayBuffer} or {@code Uint8Array} in TypeScript 5.7 or below respectively.
3
- *
4
- * This type is internal utility type and should not be used directly.
5
- *
6
- * @internal @private
7
- */
8
- export type Uint8Array_ = ReturnType<Uint8Array["slice"]>;
9
- //# sourceMappingURL=_types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_types.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_types.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- export {};
@@ -1,2 +0,0 @@
1
- export declare function validateBinaryLike(source: unknown): Uint8Array;
2
- //# sourceMappingURL=_validate_binary_like.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_validate_binary_like.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.ts"],"names":[],"mappings":"AAeA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,CAa9D"}
@@ -1,26 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- const encoder = new TextEncoder();
3
- function getTypeName(value) {
4
- const type = typeof value;
5
- if (type !== "object") {
6
- return type;
7
- }
8
- else if (value === null) {
9
- return "null";
10
- }
11
- else {
12
- return value?.constructor?.name ?? "object";
13
- }
14
- }
15
- export function validateBinaryLike(source) {
16
- if (typeof source === "string") {
17
- return encoder.encode(source);
18
- }
19
- else if (source instanceof Uint8Array) {
20
- return source;
21
- }
22
- else if (source instanceof ArrayBuffer) {
23
- return new Uint8Array(source);
24
- }
25
- throw new TypeError(`Cannot validate the input as it must be a Uint8Array, a string, or an ArrayBuffer: received a value of the type ${getTypeName(source)}`);
26
- }
@@ -1,61 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Supported ascii85 standards for {@linkcode EncodeAscii85Options} and
5
- * {@linkcode DecodeAscii85Options}.
6
- */
7
- export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85";
8
- /** Options for {@linkcode encodeAscii85}. */
9
- export interface EncodeAscii85Options {
10
- /**
11
- * Character set and delimiter (if supported and used).
12
- *
13
- * @default {"Adobe"}
14
- */
15
- standard?: Ascii85Standard;
16
- /**
17
- * Whether to use a delimiter (if supported).
18
- *
19
- * @default {false}
20
- */
21
- delimiter?: boolean;
22
- }
23
- /**
24
- * Converts data into an ascii85-encoded string.
25
- *
26
- * @param data The data to encode.
27
- * @param options Options for encoding.
28
- *
29
- * @returns The ascii85-encoded string.
30
- *
31
- * @example Usage
32
- * ```ts
33
- * import { encodeAscii85 } from "@std/encoding/ascii85";
34
- * import { assertEquals } from "@std/assert";
35
- *
36
- * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
37
- * ```
38
- */
39
- export declare function encodeAscii85(data: ArrayBuffer | Uint8Array | string, options?: EncodeAscii85Options): string;
40
- /** Options for {@linkcode decodeAscii85}. */
41
- export type DecodeAscii85Options = Omit<EncodeAscii85Options, "delimiter">;
42
- /**
43
- * Decodes a ascii85-encoded string.
44
- *
45
- * @param ascii85 The ascii85-encoded string to decode.
46
- * @param options Options for decoding.
47
- * @returns The decoded data.
48
- *
49
- * @example Usage
50
- * ```ts
51
- * import { decodeAscii85 } from "@std/encoding/ascii85";
52
- * import { assertEquals } from "@std/assert";
53
- *
54
- * assertEquals(
55
- * decodeAscii85("87cURD]j7BEbo80"),
56
- * new TextEncoder().encode("Hello world!"),
57
- * );
58
- * ```
59
- */
60
- export declare function decodeAscii85(ascii85: string, options?: DecodeAscii85Options): Uint8Array_;
61
- //# sourceMappingURL=ascii85.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ascii85.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/ascii85.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAwB5B;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AAEpE,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAOD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,EACvC,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA6DR;AAED,6CAA6C;AAC7C,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,WAAW,CA4Cb"}
@@ -1,152 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- /**
4
- * Utilities for working with {@link https://en.wikipedia.org/wiki/Ascii85 | ascii85} encoding.
5
- *
6
- * ## Specifying a standard and delimiter
7
- *
8
- * By default, all functions are using the most popular Adobe version of ascii85
9
- * and not adding any delimiter. However, there are three more standards
10
- * supported - btoa (different delimiter and additional compression of 4 bytes
11
- * equal to 32), {@link https://rfc.zeromq.org/spec/32/ | Z85} and
12
- * {@link https://www.rfc-editor.org/rfc/rfc1924.html | RFC 1924}. It's possible to use a
13
- * different encoding by specifying it in `options` object as a second parameter.
14
- *
15
- * Similarly, it's possible to make `encode` add a delimiter (`<~` and `~>` for
16
- * Adobe, `xbtoa Begin` and `xbtoa End` with newlines between the delimiters and
17
- * encoded data for btoa. Checksums for btoa are not supported. Delimiters are not
18
- * supported by other encodings.)
19
- *
20
- * @module
21
- */
22
- import { validateBinaryLike } from "./_validate_binary_like.js";
23
- const rfc1924 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
24
- const Z85 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
25
- /**
26
- * Converts data into an ascii85-encoded string.
27
- *
28
- * @param data The data to encode.
29
- * @param options Options for encoding.
30
- *
31
- * @returns The ascii85-encoded string.
32
- *
33
- * @example Usage
34
- * ```ts
35
- * import { encodeAscii85 } from "@std/encoding/ascii85";
36
- * import { assertEquals } from "@std/assert";
37
- *
38
- * assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
39
- * ```
40
- */
41
- export function encodeAscii85(data, options = {}) {
42
- let uint8 = validateBinaryLike(data);
43
- const { standard = "Adobe" } = options;
44
- let output = [];
45
- let v;
46
- let n = 0;
47
- let difference = 0;
48
- if (uint8.length % 4 !== 0) {
49
- const tmp = uint8;
50
- difference = 4 - (tmp.length % 4);
51
- uint8 = new Uint8Array(tmp.length + difference);
52
- uint8.set(tmp);
53
- }
54
- const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
55
- for (let i = 0; i < uint8.length; i += 4) {
56
- v = view.getUint32(i);
57
- // Adobe and btoa standards compress 4 zeroes to single "z" character
58
- if ((standard === "Adobe" || standard === "btoa") &&
59
- v === 0 &&
60
- i < uint8.length - difference - 3) {
61
- output[n++] = "z";
62
- continue;
63
- }
64
- // btoa compresses 4 spaces - that is, bytes equal to 32 - into single "y" character
65
- if (standard === "btoa" && v === 538976288) {
66
- output[n++] = "y";
67
- continue;
68
- }
69
- for (let j = 4; j >= 0; j--) {
70
- output[n + j] = String.fromCharCode((v % 85) + 33);
71
- v = Math.trunc(v / 85);
72
- }
73
- n += 5;
74
- }
75
- switch (standard) {
76
- case "Adobe":
77
- if (options?.delimiter) {
78
- return `<~${output.slice(0, output.length - difference).join("")}~>`;
79
- }
80
- break;
81
- case "btoa":
82
- if (options?.delimiter) {
83
- return `xbtoa Begin\n${output
84
- .slice(0, output.length - difference)
85
- .join("")}\nxbtoa End`;
86
- }
87
- break;
88
- case "RFC 1924":
89
- output = output.map((val) => rfc1924[val.charCodeAt(0) - 33]);
90
- break;
91
- case "Z85":
92
- output = output.map((val) => Z85[val.charCodeAt(0) - 33]);
93
- break;
94
- }
95
- return output.slice(0, output.length - difference).join("");
96
- }
97
- /**
98
- * Decodes a ascii85-encoded string.
99
- *
100
- * @param ascii85 The ascii85-encoded string to decode.
101
- * @param options Options for decoding.
102
- * @returns The decoded data.
103
- *
104
- * @example Usage
105
- * ```ts
106
- * import { decodeAscii85 } from "@std/encoding/ascii85";
107
- * import { assertEquals } from "@std/assert";
108
- *
109
- * assertEquals(
110
- * decodeAscii85("87cURD]j7BEbo80"),
111
- * new TextEncoder().encode("Hello world!"),
112
- * );
113
- * ```
114
- */
115
- export function decodeAscii85(ascii85, options = {}) {
116
- const { standard = "Adobe" } = options;
117
- // translate all encodings to most basic adobe/btoa one and decompress some special characters ("z" and "y")
118
- switch (standard) {
119
- case "Adobe":
120
- ascii85 = ascii85.replaceAll(/(<~|~>)/g, "").replaceAll("z", "!!!!!");
121
- break;
122
- case "btoa":
123
- ascii85 = ascii85
124
- .replaceAll(/(xbtoa Begin|xbtoa End|\n)/g, "")
125
- .replaceAll("z", "!!!!!")
126
- .replaceAll("y", "+<VdL");
127
- break;
128
- case "RFC 1924":
129
- ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(rfc1924.indexOf(match) + 33));
130
- break;
131
- case "Z85":
132
- ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(Z85.indexOf(match) + 33));
133
- break;
134
- }
135
- // remove all invalid characters
136
- ascii85 = ascii85.replaceAll(/[^!-u]/g, "");
137
- const len = ascii85.length;
138
- const output = new Uint8Array(len + 4 - (len % 4));
139
- const view = new DataView(output.buffer);
140
- let v = 0;
141
- let n = 0;
142
- let max = 0;
143
- for (let i = 0; i < len;) {
144
- for (max += 5; i < max; i++) {
145
- v = v * 85 + (i < len ? ascii85.charCodeAt(i) : 117) - 33;
146
- }
147
- view.setUint32(n, v);
148
- v = 0;
149
- n += 4;
150
- }
151
- return output.slice(0, Math.trunc(len * 0.8));
152
- }
@@ -1,40 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Converts data into a base32-encoded string.
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
7
- *
8
- * @param data The data to encode.
9
- * @returns The base32-encoded string.
10
- *
11
- * @example Usage
12
- * ```ts
13
- * import { encodeBase32 } from "@std/encoding/base32";
14
- * import { assertEquals } from "@std/assert";
15
- *
16
- * assertEquals(encodeBase32("6c60c0"), "GZRTMMDDGA======");
17
- * ```
18
- */
19
- export declare function encodeBase32(data: ArrayBuffer | Uint8Array | string): string;
20
- /**
21
- * Decodes a base32-encoded string.
22
- *
23
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
24
- *
25
- * @param b32 The base32-encoded string to decode.
26
- * @returns The decoded data.
27
- *
28
- * @example Usage
29
- * ```ts
30
- * import { decodeBase32 } from "@std/encoding/base32";
31
- * import { assertEquals } from "@std/assert";
32
- *
33
- * assertEquals(
34
- * decodeBase32("GZRTMMDDGA======"),
35
- * new TextEncoder().encode("6c60c0"),
36
- * );
37
- * ```
38
- */
39
- export declare function decodeBase32(b32: string): Uint8Array_;
40
- //# sourceMappingURL=base32.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/base32.ts"],"names":[],"mappings":"AA4BA,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,CAUrD"}
@@ -1,87 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // Copyright (c) 2014 Jameson Little. MIT License.
3
- // This module is browser compatible.
4
- /**
5
- * Utilities for
6
- * {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6 | base32}
7
- * encoding and decoding.
8
- *
9
- * Modified from {@link https://github.com/beatgammit/base64-js}.
10
- *
11
- * ```ts
12
- * import { encodeBase32, decodeBase32 } from "@std/encoding/base32";
13
- * import { assertEquals } from "@std/assert";
14
- *
15
- * assertEquals(encodeBase32("foobar"), "MZXW6YTBOI======");
16
- *
17
- * assertEquals(
18
- * decodeBase32("MZXW6YTBOI======"),
19
- * new TextEncoder().encode("foobar")
20
- * );
21
- * ```
22
- *
23
- * @module
24
- */
25
- import { calcSizeBase32, decode, encode } from "./_common32.js";
26
- import { detach } from "./_common_detach.js";
27
- const padding = "=".charCodeAt(0);
28
- const alphabet = new TextEncoder()
29
- .encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
30
- const rAlphabet = new Uint8Array(128).fill(32); //alphabet.length
31
- alphabet.forEach((byte, i) => rAlphabet[byte] = i);
32
- /**
33
- * Converts data into a base32-encoded string.
34
- *
35
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
36
- *
37
- * @param data The data to encode.
38
- * @returns The base32-encoded string.
39
- *
40
- * @example Usage
41
- * ```ts
42
- * import { encodeBase32 } from "@std/encoding/base32";
43
- * import { assertEquals } from "@std/assert";
44
- *
45
- * assertEquals(encodeBase32("6c60c0"), "GZRTMMDDGA======");
46
- * ```
47
- */
48
- export function encodeBase32(data) {
49
- if (typeof data === "string") {
50
- data = new TextEncoder().encode(data);
51
- }
52
- else if (data instanceof ArrayBuffer)
53
- data = new Uint8Array(data).slice();
54
- else
55
- data = data.slice();
56
- const [output, i] = detach(data, calcSizeBase32(data.length));
57
- encode(output, i, 0, alphabet, padding);
58
- return new TextDecoder().decode(output);
59
- }
60
- /**
61
- * Decodes a base32-encoded string.
62
- *
63
- * @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
64
- *
65
- * @param b32 The base32-encoded string to decode.
66
- * @returns The decoded data.
67
- *
68
- * @example Usage
69
- * ```ts
70
- * import { decodeBase32 } from "@std/encoding/base32";
71
- * import { assertEquals } from "@std/assert";
72
- *
73
- * assertEquals(
74
- * decodeBase32("GZRTMMDDGA======"),
75
- * new TextEncoder().encode("6c60c0"),
76
- * );
77
- * ```
78
- */
79
- export function decodeBase32(b32) {
80
- const output = new TextEncoder().encode(b32);
81
- if (output.length % 8) {
82
- throw new TypeError(`Invalid base32 string: length (${output.length}) must be a multiple of 8`);
83
- }
84
- // deno-lint-ignore no-explicit-any
85
- return new Uint8Array(output.buffer
86
- .transfer(decode(output, 0, 0, rAlphabet, padding)));
87
- }
@@ -1,40 +0,0 @@
1
- import type { Uint8Array_ } from "./_types.js";
2
- export type { Uint8Array_ };
3
- /**
4
- * Converts data into a base58-encoded string.
5
- *
6
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-3}
7
- *
8
- * @param data The data to encode.
9
- * @returns The base58-encoded string.
10
- *
11
- * @example Usage
12
- * ```ts
13
- * import { encodeBase58 } from "@std/encoding/base58";
14
- * import { assertEquals } from "@std/assert";
15
- *
16
- * assertEquals(encodeBase58("Hello World!"), "2NEpo7TZRRrLZSi2U");
17
- * ```
18
- */
19
- export declare function encodeBase58(data: ArrayBuffer | Uint8Array | string): string;
20
- /**
21
- * Decodes a base58-encoded string.
22
- *
23
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-4}
24
- *
25
- * @param b58 The base58-encoded string to decode.
26
- * @returns The decoded data.
27
- *
28
- * @example Usage
29
- * ```ts
30
- * import { decodeBase58 } from "@std/encoding/base58";
31
- * import { assertEquals } from "@std/assert";
32
- *
33
- * assertEquals(
34
- * decodeBase58("2NEpo7TZRRrLZSi2U"),
35
- * new TextEncoder().encode("Hello World!")
36
- * );
37
- * ```
38
- */
39
- export declare function decodeBase58(b58: string): Uint8Array_;
40
- //# sourceMappingURL=base58.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/base58.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAe5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAgD5E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAkDrD"}
@@ -1,131 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- /**
4
- * Utilities for
5
- * {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03 | base58}
6
- * encoding and decoding.
7
- *
8
- * ```ts
9
- * import { encodeBase58, decodeBase58 } from "@std/encoding/base58";
10
- * import { assertEquals } from "@std/assert";
11
- *
12
- * const hello = new TextEncoder().encode("Hello World!");
13
- *
14
- * assertEquals(encodeBase58(hello), "2NEpo7TZRRrLZSi2U");
15
- *
16
- * assertEquals(decodeBase58("2NEpo7TZRRrLZSi2U"), hello);
17
- * ```
18
- *
19
- * @module
20
- */
21
- import { validateBinaryLike } from "./_validate_binary_like.js";
22
- // deno-fmt-ignore
23
- const mapBase58 = {
24
- "1": 0, "2": 1, "3": 2, "4": 3, "5": 4, "6": 5, "7": 6, "8": 7, "9": 8, A: 9,
25
- B: 10, C: 11, D: 12, E: 13, F: 14, G: 15, H: 16, J: 17, K: 18, L: 19, M: 20,
26
- N: 21, P: 22, Q: 23, R: 24, S: 25, T: 26, U: 27, V: 28, W: 29, X: 30, Y: 31,
27
- Z: 32, a: 33, b: 34, c: 35, d: 36, e: 37, f: 38, g: 39, h: 40, i: 41, j: 42,
28
- k: 43, m: 44, n: 45, o: 46, p: 47, q: 48, r: 49, s: 50, t: 51, u: 52, v: 53,
29
- w: 54, x: 55, y: 56, z: 57
30
- };
31
- const base58alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");
32
- /**
33
- * Converts data into a base58-encoded string.
34
- *
35
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-3}
36
- *
37
- * @param data The data to encode.
38
- * @returns The base58-encoded string.
39
- *
40
- * @example Usage
41
- * ```ts
42
- * import { encodeBase58 } from "@std/encoding/base58";
43
- * import { assertEquals } from "@std/assert";
44
- *
45
- * assertEquals(encodeBase58("Hello World!"), "2NEpo7TZRRrLZSi2U");
46
- * ```
47
- */
48
- export function encodeBase58(data) {
49
- const uint8tData = validateBinaryLike(data);
50
- let length = 0;
51
- let zeroes = 0;
52
- // Counting leading zeroes
53
- let index = 0;
54
- while (uint8tData[index] === 0) {
55
- zeroes++;
56
- index++;
57
- }
58
- const notZeroUint8Data = uint8tData.slice(index);
59
- const size = Math.round((uint8tData.length * 138) / 100 + 1);
60
- const b58Encoding = [];
61
- notZeroUint8Data.forEach((byte) => {
62
- let i = 0;
63
- let carry = byte;
64
- for (let reverseIterator = size - 1; (carry > 0 || i < length) && reverseIterator !== -1; reverseIterator--, i++) {
65
- carry += (b58Encoding[reverseIterator] ?? 0) * 256;
66
- b58Encoding[reverseIterator] = Math.round(carry % 58);
67
- carry = Math.floor(carry / 58);
68
- }
69
- length = i;
70
- });
71
- const strResult = Array.from({
72
- length: b58Encoding.length + zeroes,
73
- });
74
- if (zeroes > 0) {
75
- strResult.fill("1", 0, zeroes);
76
- }
77
- b58Encoding.forEach((byteValue) => strResult.push(base58alphabet[byteValue]));
78
- return strResult.join("");
79
- }
80
- /**
81
- * Decodes a base58-encoded string.
82
- *
83
- * @see {@link https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-4}
84
- *
85
- * @param b58 The base58-encoded string to decode.
86
- * @returns The decoded data.
87
- *
88
- * @example Usage
89
- * ```ts
90
- * import { decodeBase58 } from "@std/encoding/base58";
91
- * import { assertEquals } from "@std/assert";
92
- *
93
- * assertEquals(
94
- * decodeBase58("2NEpo7TZRRrLZSi2U"),
95
- * new TextEncoder().encode("Hello World!")
96
- * );
97
- * ```
98
- */
99
- export function decodeBase58(b58) {
100
- const splitInput = b58.trim().split("");
101
- let length = 0;
102
- let ones = 0;
103
- // Counting leading ones
104
- let index = 0;
105
- while (splitInput[index] === "1") {
106
- ones++;
107
- index++;
108
- }
109
- const notZeroData = splitInput.slice(index);
110
- const size = Math.round((b58.length * 733) / 1000 + 1);
111
- const output = [];
112
- notZeroData.forEach((char, idx) => {
113
- let carry = mapBase58[char];
114
- let i = 0;
115
- if (carry === undefined) {
116
- throw new TypeError(`Invalid base58 char at index ${idx} with value ${char}`);
117
- }
118
- for (let reverseIterator = size - 1; (carry > 0 || i < length) && reverseIterator !== -1; reverseIterator--, i++) {
119
- carry += 58 * (output[reverseIterator] ?? 0);
120
- output[reverseIterator] = Math.round(carry % 256);
121
- carry = Math.floor(carry / 256);
122
- }
123
- length = i;
124
- });
125
- const validOutput = output.filter((item) => item !== undefined);
126
- if (ones > 0) {
127
- const onesResult = Array.from({ length: ones }).fill(0, 0, ones);
128
- return new Uint8Array([...onesResult, ...validOutput]);
129
- }
130
- return new Uint8Array(validOutput);
131
- }
@@ -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"}