glotto 2.9.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -55
- package/esm/cli.js +47 -39
- package/esm/deno.d.ts +0 -1
- package/esm/deno.js +1 -2
- package/esm/src/contants.d.ts +2 -2
- package/esm/src/contants.d.ts.map +1 -1
- package/esm/src/contants.js +22 -12
- package/esm/src/file.d.ts +2 -7
- package/esm/src/file.d.ts.map +1 -1
- package/esm/src/file.js +1 -108
- package/esm/src/providers/anthropic.d.ts +6 -11
- package/esm/src/providers/anthropic.d.ts.map +1 -1
- package/esm/src/providers/anthropic.js +14 -108
- package/esm/src/providers/gemini.d.ts +6 -11
- package/esm/src/providers/gemini.d.ts.map +1 -1
- package/esm/src/providers/gemini.js +13 -114
- package/esm/src/providers/openai.d.ts +6 -11
- package/esm/src/providers/openai.d.ts.map +1 -1
- package/esm/src/providers/openai.js +10 -109
- package/esm/src/translator.d.ts +8 -0
- package/esm/src/translator.d.ts.map +1 -0
- package/esm/src/translator.js +200 -0
- package/esm/src/types.d.ts +28 -11
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/utilites.d.ts +0 -6
- package/esm/src/utilites.d.ts.map +1 -1
- package/esm/src/utilites.js +18 -132
- package/package.json +1 -1
- package/script/cli.js +45 -37
- package/script/deno.d.ts +0 -1
- package/script/deno.js +1 -2
- package/script/src/contants.d.ts +2 -2
- package/script/src/contants.d.ts.map +1 -1
- package/script/src/contants.js +23 -13
- package/script/src/file.d.ts +2 -7
- package/script/src/file.d.ts.map +1 -1
- package/script/src/file.js +2 -114
- package/script/src/providers/anthropic.d.ts +6 -11
- package/script/src/providers/anthropic.d.ts.map +1 -1
- package/script/src/providers/anthropic.js +13 -107
- package/script/src/providers/gemini.d.ts +6 -11
- package/script/src/providers/gemini.d.ts.map +1 -1
- package/script/src/providers/gemini.js +12 -113
- package/script/src/providers/openai.d.ts +6 -11
- package/script/src/providers/openai.d.ts.map +1 -1
- package/script/src/providers/openai.js +9 -108
- package/script/src/translator.d.ts +8 -0
- package/script/src/translator.d.ts.map +1 -0
- package/script/src/translator.js +209 -0
- package/script/src/types.d.ts +28 -11
- package/script/src/types.d.ts.map +1 -1
- package/script/src/utilites.d.ts +0 -6
- package/script/src/utilites.d.ts.map +1 -1
- package/script/src/utilites.js +19 -136
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -192
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -26
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -152
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -87
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -131
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -72
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -99
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -205
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -57
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -198
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -156
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -91
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -135
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -76
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -91
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -115
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -211
|
@@ -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"}
|