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.
- package/README.md +150 -54
- package/esm/cli.js +155 -43
- package/esm/deno.d.ts +5 -1
- package/esm/deno.js +18 -7
- package/esm/src/config.d.ts +4 -0
- package/esm/src/config.d.ts.map +1 -0
- package/esm/src/config.js +95 -0
- package/esm/src/contants.d.ts +6 -2
- package/esm/src/contants.d.ts.map +1 -1
- package/esm/src/contants.js +34 -15
- package/esm/src/diff.d.ts +4 -0
- package/esm/src/diff.d.ts.map +1 -0
- package/esm/src/diff.js +53 -0
- package/esm/src/file.d.ts +5 -9
- package/esm/src/file.d.ts.map +1 -1
- package/esm/src/file.js +14 -103
- 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 +21 -107
- 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 +20 -113
- 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 +17 -108
- package/esm/src/translator.d.ts +15 -0
- package/esm/src/translator.d.ts.map +1 -0
- package/esm/src/translator.js +284 -0
- package/esm/src/types.d.ts +58 -13
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/utilites.d.ts +3 -10
- package/esm/src/utilites.d.ts.map +1 -1
- package/esm/src/utilites.js +41 -131
- package/package.json +20 -6
- package/schema/glotto.schema.json +87 -0
- package/script/cli.js +153 -41
- package/script/deno.d.ts +5 -1
- package/script/deno.js +18 -7
- package/script/src/config.d.ts +4 -0
- package/script/src/config.d.ts.map +1 -0
- package/script/src/config.js +132 -0
- package/script/src/contants.d.ts +6 -2
- package/script/src/contants.d.ts.map +1 -1
- package/script/src/contants.js +35 -16
- package/script/src/diff.d.ts +4 -0
- package/script/src/diff.d.ts.map +1 -0
- package/script/src/diff.js +57 -0
- package/script/src/file.d.ts +5 -9
- package/script/src/file.d.ts.map +1 -1
- package/script/src/file.js +19 -113
- 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 +20 -106
- 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 +19 -112
- 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 +16 -107
- package/script/src/translator.d.ts +15 -0
- package/script/src/translator.d.ts.map +1 -0
- package/script/src/translator.js +294 -0
- package/script/src/types.d.ts +58 -13
- package/script/src/types.d.ts.map +1 -1
- package/script/src/utilites.d.ts +3 -10
- package/script/src/utilites.d.ts.map +1 -1
- package/script/src/utilites.js +44 -138
- 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
package/script/src/utilites.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.validateArgs = validateArgs;
|
|
4
|
+
exports.formatBytes = formatBytes;
|
|
5
|
+
exports.delay = delay;
|
|
6
|
+
const contants_js_1 = require("./contants.js");
|
|
7
|
+
function splitCsv(value) {
|
|
8
|
+
return value.split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
9
|
+
}
|
|
10
|
+
function validateArgs(args) {
|
|
5
11
|
if (!args.key) {
|
|
6
12
|
throw new Error('AI Key is required');
|
|
7
13
|
}
|
|
@@ -20,151 +26,51 @@ const validateArgs = (args) => {
|
|
|
20
26
|
if (!args.to) {
|
|
21
27
|
throw new Error('Target language (to) parameter is required');
|
|
22
28
|
}
|
|
29
|
+
const toList = splitCsv(args.to);
|
|
30
|
+
const outputList = splitCsv(args.output);
|
|
31
|
+
if (toList.length === 0) {
|
|
32
|
+
throw new Error('Target language (to) must contain at least one value');
|
|
33
|
+
}
|
|
34
|
+
if (outputList.length === 0) {
|
|
35
|
+
throw new Error('Output must contain at least one value');
|
|
36
|
+
}
|
|
37
|
+
if (toList.length !== outputList.length) {
|
|
38
|
+
throw new Error(`--to (${toList.length}) and --output (${outputList.length}) must have the same number of values`);
|
|
39
|
+
}
|
|
40
|
+
let maxBatchBytes = contants_js_1.DEFAULT_MAX_BATCH_BYTES;
|
|
41
|
+
const rawMaxBatchSize = args['max-batch-size'];
|
|
42
|
+
if (rawMaxBatchSize !== undefined) {
|
|
43
|
+
const parsed = parseInt(rawMaxBatchSize, 10);
|
|
44
|
+
if (isNaN(parsed) || parsed <= 0) {
|
|
45
|
+
throw new Error('--max-batch-size must be a positive integer (value in KB, e.g. --max-batch-size 8)');
|
|
46
|
+
}
|
|
47
|
+
maxBatchBytes = parsed * 1024;
|
|
48
|
+
}
|
|
23
49
|
return {
|
|
24
50
|
key: args.key,
|
|
25
51
|
provider: args.provider,
|
|
26
52
|
model: args.model,
|
|
27
53
|
input: args.input,
|
|
28
|
-
output:
|
|
54
|
+
output: outputList,
|
|
29
55
|
from: args.from,
|
|
30
|
-
to:
|
|
56
|
+
to: toList,
|
|
31
57
|
url: args.url,
|
|
58
|
+
noLimit: args['no-limit'] ?? false,
|
|
59
|
+
noTimeout: args['no-timeout'] ?? false,
|
|
60
|
+
maxBatchBytes,
|
|
61
|
+
stats: args.stats ?? false,
|
|
62
|
+
incremental: args.incremental ?? false,
|
|
32
63
|
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const systemPrompt = `You are a specialized i18next JSON translation expert. Your role is to translate content from ${from} to ${to} with these strict requirements:
|
|
37
|
-
|
|
38
|
-
1. COMPLETE TRANSLATION:
|
|
39
|
-
- Translate ALL text values comprehensively
|
|
40
|
-
- Double-check to ensure no text is left untranslated
|
|
41
|
-
- Pay special attention to arrays and nested objects to ensure everything is translated
|
|
42
|
-
- If unsure about any translation, provide the most accurate and natural translation possible
|
|
43
|
-
|
|
44
|
-
2. TRANSLATION QUALITY:
|
|
45
|
-
- Use natural, context-appropriate language
|
|
46
|
-
- Maintain consistent terminology throughout the translation
|
|
47
|
-
- Use formal language unless the source is clearly casual
|
|
48
|
-
- Preserve the exact meaning and tone of the original text
|
|
49
|
-
- For UI elements, use standard localized terms common in ${to} applications
|
|
50
|
-
|
|
51
|
-
3. STRUCTURAL PRESERVATION:
|
|
52
|
-
- Keep all JSON structure and keys exactly as they are
|
|
53
|
-
- Maintain all variables and interpolation patterns ({{name}}, __VARIABLE__, $t(), etc.)
|
|
54
|
-
- Preserve all HTML tags and markdown formatting
|
|
55
|
-
- Keep all whitespace, nesting, and formatting intact
|
|
56
|
-
|
|
57
|
-
4. VALIDATION:
|
|
58
|
-
- Return only valid JSON
|
|
59
|
-
- Verify that all text is translated
|
|
60
|
-
- Ensure no source language text remains
|
|
61
|
-
- Confirm all arrays and nested objects are fully translated`;
|
|
62
|
-
const userPrompt = `Please translate this i18next JSON file with these specific requirements:
|
|
63
|
-
|
|
64
|
-
1. THOROUGH TRANSLATION:
|
|
65
|
-
- Translate every single text value from ${from} to ${to}
|
|
66
|
-
- Pay special attention to arrays and nested objects
|
|
67
|
-
- Verify no text is left in ${from}
|
|
68
|
-
- Double-check all translations for completeness
|
|
69
|
-
|
|
70
|
-
2. PRESERVE STRUCTURE:
|
|
71
|
-
- Keep all keys unchanged (e.g. "button.submit")
|
|
72
|
-
- Maintain all variables: {{name}}, __VAR__, $t()
|
|
73
|
-
- Preserve HTML tags and markdown
|
|
74
|
-
- Keep all special characters
|
|
75
|
-
- Maintain exact JSON structure
|
|
76
|
-
|
|
77
|
-
3. QUALITY REQUIREMENTS:
|
|
78
|
-
- Use natural ${to} language
|
|
79
|
-
- Maintain consistent terminology
|
|
80
|
-
- Use formal language unless source is casual
|
|
81
|
-
- Ensure translations match the context
|
|
82
|
-
- Use standard ${to} UI terminology for interface elements
|
|
83
|
-
|
|
84
|
-
4. OUTPUT:
|
|
85
|
-
- Return only the translated JSON
|
|
86
|
-
- No explanations or comments
|
|
87
|
-
- No additional text
|
|
88
|
-
- No formatting changes
|
|
89
|
-
- Must be valid JSON`;
|
|
90
|
-
return { systemPrompt, userPrompt };
|
|
91
|
-
};
|
|
92
|
-
exports.generatePrompts = generatePrompts;
|
|
93
|
-
const stripJsonMarkdown = (text) => {
|
|
94
|
-
const trimmed = text.trim();
|
|
95
|
-
// Extract from code fence if present (handles surrounding text too)
|
|
96
|
-
const fenceMatch = trimmed.match(/```(?:\w+)?\s*\n?([\s\S]*?)\n?```/);
|
|
97
|
-
if (fenceMatch) {
|
|
98
|
-
const candidate = fenceMatch[1].trim();
|
|
99
|
-
if (candidate.startsWith('{') || candidate.startsWith('[')) {
|
|
100
|
-
return candidate;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// Find outermost JSON structure by tracking bracket depth,
|
|
104
|
-
// correctly ignoring brackets inside strings and escape sequences
|
|
105
|
-
const firstBrace = trimmed.indexOf('{');
|
|
106
|
-
const firstBracket = trimmed.indexOf('[');
|
|
107
|
-
if (firstBrace === -1 && firstBracket === -1)
|
|
108
|
-
return trimmed;
|
|
109
|
-
let startIndex;
|
|
110
|
-
let openChar;
|
|
111
|
-
let closeChar;
|
|
112
|
-
if (firstBrace === -1 || (firstBracket !== -1 && firstBracket < firstBrace)) {
|
|
113
|
-
startIndex = firstBracket;
|
|
114
|
-
openChar = '[';
|
|
115
|
-
closeChar = ']';
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
startIndex = firstBrace;
|
|
119
|
-
openChar = '{';
|
|
120
|
-
closeChar = '}';
|
|
121
|
-
}
|
|
122
|
-
let depth = 0;
|
|
123
|
-
let inString = false;
|
|
124
|
-
let escaped = false;
|
|
125
|
-
for (let i = startIndex; i < trimmed.length; i++) {
|
|
126
|
-
const char = trimmed[i];
|
|
127
|
-
if (escaped) {
|
|
128
|
-
escaped = false;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (char === '\\' && inString) {
|
|
132
|
-
escaped = true;
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (char === '"') {
|
|
136
|
-
inString = !inString;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (inString)
|
|
140
|
-
continue;
|
|
141
|
-
if (char === openChar)
|
|
142
|
-
depth++;
|
|
143
|
-
else if (char === closeChar && --depth === 0)
|
|
144
|
-
return trimmed.slice(startIndex, i + 1);
|
|
145
|
-
}
|
|
146
|
-
return trimmed;
|
|
147
|
-
};
|
|
148
|
-
exports.stripJsonMarkdown = stripJsonMarkdown;
|
|
149
|
-
const isValidJson = (value) => {
|
|
150
|
-
try {
|
|
151
|
-
JSON.parse(value);
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
exports.isValidJson = isValidJson;
|
|
159
|
-
const formatBytes = (bytes) => {
|
|
160
|
-
if (bytes < 1024)
|
|
64
|
+
}
|
|
65
|
+
function formatBytes(bytes) {
|
|
66
|
+
if (bytes < 1024) {
|
|
161
67
|
return `${bytes} B`;
|
|
162
|
-
|
|
68
|
+
}
|
|
69
|
+
if (bytes < 1024 * 1024) {
|
|
163
70
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
71
|
+
}
|
|
164
72
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const delay = (ms) => {
|
|
73
|
+
}
|
|
74
|
+
function delay(ms) {
|
|
168
75
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
169
|
-
}
|
|
170
|
-
exports.delay = delay;
|
|
76
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
-
export type { Uint8Array_ };
|
|
3
|
-
export declare const alphabet: Uint8Array<ArrayBufferLike>;
|
|
4
|
-
export declare const rAlphabet: Uint8Array<ArrayBuffer>;
|
|
5
|
-
/**
|
|
6
|
-
* Calculate the output size needed to encode a given input size for
|
|
7
|
-
* {@linkcode encodeIntoHex}.
|
|
8
|
-
*
|
|
9
|
-
* @param originalSize The size of the input buffer.
|
|
10
|
-
* @returns The size of the output buffer.
|
|
11
|
-
*
|
|
12
|
-
* @example Basic Usage
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { assertEquals } from "@std/assert";
|
|
15
|
-
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
16
|
-
*
|
|
17
|
-
* assertEquals(calcSizeHex(1), 2);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function calcSizeHex(originalSize: number): number;
|
|
21
|
-
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
22
|
-
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
23
|
-
//# sourceMappingURL=_common16.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common16.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common16.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,QAAQ,6BAA+C,CAAC;AACrE,eAAO,MAAM,SAAS,yBAA+B,CAAC;AAMtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAOR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAeR"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
export const alphabet = new TextEncoder().encode("0123456789abcdef");
|
|
3
|
-
export const rAlphabet = new Uint8Array(128).fill(16); // alphabet.Hex.length
|
|
4
|
-
alphabet.forEach((byte, i) => rAlphabet[byte] = i);
|
|
5
|
-
new TextEncoder()
|
|
6
|
-
.encode("ABCDEF")
|
|
7
|
-
.forEach((byte, i) => rAlphabet[byte] = i + 10);
|
|
8
|
-
/**
|
|
9
|
-
* Calculate the output size needed to encode a given input size for
|
|
10
|
-
* {@linkcode encodeIntoHex}.
|
|
11
|
-
*
|
|
12
|
-
* @param originalSize The size of the input buffer.
|
|
13
|
-
* @returns The size of the output buffer.
|
|
14
|
-
*
|
|
15
|
-
* @example Basic Usage
|
|
16
|
-
* ```ts
|
|
17
|
-
* import { assertEquals } from "@std/assert";
|
|
18
|
-
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
19
|
-
*
|
|
20
|
-
* assertEquals(calcSizeHex(1), 2);
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function calcSizeHex(originalSize) {
|
|
24
|
-
return originalSize * 2;
|
|
25
|
-
}
|
|
26
|
-
export function encode(buffer, i, o, alphabet) {
|
|
27
|
-
for (; i < buffer.length; ++i) {
|
|
28
|
-
const x = buffer[i];
|
|
29
|
-
buffer[o++] = alphabet[x >> 4];
|
|
30
|
-
buffer[o++] = alphabet[x & 0xF];
|
|
31
|
-
}
|
|
32
|
-
return o;
|
|
33
|
-
}
|
|
34
|
-
export function decode(buffer, i, o, alphabet) {
|
|
35
|
-
if ((buffer.length - o) % 2 === 1) {
|
|
36
|
-
throw new RangeError(`Cannot decode input as hex: Length (${buffer.length - o}) must be divisible by 2`);
|
|
37
|
-
}
|
|
38
|
-
i += 1;
|
|
39
|
-
for (; i < buffer.length; i += 2) {
|
|
40
|
-
buffer[o++] = (getByte(buffer[i - 1], alphabet) << 4) |
|
|
41
|
-
getByte(buffer[i], alphabet);
|
|
42
|
-
}
|
|
43
|
-
return o;
|
|
44
|
-
}
|
|
45
|
-
function getByte(char, alphabet) {
|
|
46
|
-
const byte = alphabet[char] ?? 16;
|
|
47
|
-
if (byte === 16) { // alphabet.Hex.length
|
|
48
|
-
throw new TypeError(`Cannot decode input as hex: Invalid character (${String.fromCharCode(char)})`);
|
|
49
|
-
}
|
|
50
|
-
return byte;
|
|
51
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
-
export type { Uint8Array_ };
|
|
3
|
-
export declare const padding: number;
|
|
4
|
-
export declare const alphabet: Record<Base32Alphabet, Uint8Array>;
|
|
5
|
-
export declare const rAlphabet: Record<Base32Alphabet, Uint8Array>;
|
|
6
|
-
/**
|
|
7
|
-
* Options for encoding and decoding base32 strings.
|
|
8
|
-
*/
|
|
9
|
-
export interface Base32Options {
|
|
10
|
-
/** The base32 alphabet. Defaults to "base32" */
|
|
11
|
-
alphabet?: Base32Alphabet;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The base32 alphabets.
|
|
15
|
-
*/
|
|
16
|
-
export type Base32Alphabet = "base32" | "base32hex" | "base32crockford";
|
|
17
|
-
/**
|
|
18
|
-
* Calculate the output size needed to encode a given input size for
|
|
19
|
-
* {@linkcode encodeIntoBase32}.
|
|
20
|
-
*
|
|
21
|
-
* @param rawSize The size of the input buffer.
|
|
22
|
-
* @returns The size of the output buffer.
|
|
23
|
-
*
|
|
24
|
-
* @example Basic Usage
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { assertEquals } from "@std/assert";
|
|
27
|
-
* import { calcSizeBase32 } from "@std/encoding/unstable-base32";
|
|
28
|
-
*
|
|
29
|
-
* assertEquals(calcSizeBase32(1), 8);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function calcSizeBase32(rawSize: number): number;
|
|
33
|
-
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
34
|
-
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
35
|
-
//# sourceMappingURL=_common32.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common32.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common32.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIxD,CAAC;AAQF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmER;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAyFR"}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
export const padding = "=".charCodeAt(0);
|
|
3
|
-
export const alphabet = {
|
|
4
|
-
base32: new TextEncoder().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),
|
|
5
|
-
base32hex: new TextEncoder().encode("0123456789ABCDEFGHIJKLMNOPQRSTUV"),
|
|
6
|
-
base32crockford: new TextEncoder().encode("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),
|
|
7
|
-
};
|
|
8
|
-
export const rAlphabet = {
|
|
9
|
-
base32: new Uint8Array(128).fill(32), // alphabet.base32.length
|
|
10
|
-
base32hex: new Uint8Array(128).fill(32),
|
|
11
|
-
base32crockford: new Uint8Array(128).fill(32),
|
|
12
|
-
};
|
|
13
|
-
alphabet.base32
|
|
14
|
-
.forEach((byte, i) => rAlphabet.base32[byte] = i);
|
|
15
|
-
alphabet.base32hex
|
|
16
|
-
.forEach((byte, i) => rAlphabet.base32hex[byte] = i);
|
|
17
|
-
alphabet.base32crockford
|
|
18
|
-
.forEach((byte, i) => rAlphabet.base32crockford[byte] = i);
|
|
19
|
-
/**
|
|
20
|
-
* Calculate the output size needed to encode a given input size for
|
|
21
|
-
* {@linkcode encodeIntoBase32}.
|
|
22
|
-
*
|
|
23
|
-
* @param rawSize The size of the input buffer.
|
|
24
|
-
* @returns The size of the output buffer.
|
|
25
|
-
*
|
|
26
|
-
* @example Basic Usage
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { assertEquals } from "@std/assert";
|
|
29
|
-
* import { calcSizeBase32 } from "@std/encoding/unstable-base32";
|
|
30
|
-
*
|
|
31
|
-
* assertEquals(calcSizeBase32(1), 8);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export function calcSizeBase32(rawSize) {
|
|
35
|
-
return ((rawSize + 4) / 5 | 0) * 8;
|
|
36
|
-
}
|
|
37
|
-
export function encode(buffer, i, o, alphabet, padding) {
|
|
38
|
-
i += 4;
|
|
39
|
-
for (; i < buffer.length; i += 5) {
|
|
40
|
-
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
41
|
-
buffer[o++] = alphabet[x >> 19];
|
|
42
|
-
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
43
|
-
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
44
|
-
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
45
|
-
x = (x << 16) | (buffer[i - 1] << 8) | buffer[i];
|
|
46
|
-
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
47
|
-
buffer[o++] = alphabet[x >> 10 & 0x1F];
|
|
48
|
-
buffer[o++] = alphabet[x >> 5 & 0x1F];
|
|
49
|
-
buffer[o++] = alphabet[x & 0x1F];
|
|
50
|
-
}
|
|
51
|
-
switch (i) {
|
|
52
|
-
case buffer.length + 3: {
|
|
53
|
-
const x = buffer[i - 4] << 16;
|
|
54
|
-
buffer[o++] = alphabet[x >> 19];
|
|
55
|
-
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
56
|
-
buffer[o++] = padding;
|
|
57
|
-
buffer[o++] = padding;
|
|
58
|
-
buffer[o++] = padding;
|
|
59
|
-
buffer[o++] = padding;
|
|
60
|
-
buffer[o++] = padding;
|
|
61
|
-
buffer[o++] = padding;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case buffer.length + 2: {
|
|
65
|
-
const x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8);
|
|
66
|
-
buffer[o++] = alphabet[x >> 19];
|
|
67
|
-
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
68
|
-
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
69
|
-
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
70
|
-
buffer[o++] = padding;
|
|
71
|
-
buffer[o++] = padding;
|
|
72
|
-
buffer[o++] = padding;
|
|
73
|
-
buffer[o++] = padding;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case buffer.length + 1: {
|
|
77
|
-
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
78
|
-
buffer[o++] = alphabet[x >> 19];
|
|
79
|
-
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
80
|
-
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
81
|
-
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
82
|
-
x <<= 16;
|
|
83
|
-
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
84
|
-
buffer[o++] = padding;
|
|
85
|
-
buffer[o++] = padding;
|
|
86
|
-
buffer[o++] = padding;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case buffer.length: {
|
|
90
|
-
let x = (buffer[i - 4] << 16) | (buffer[i - 3] << 8) | buffer[i - 2];
|
|
91
|
-
buffer[o++] = alphabet[x >> 19];
|
|
92
|
-
buffer[o++] = alphabet[x >> 14 & 0x1F];
|
|
93
|
-
buffer[o++] = alphabet[x >> 9 & 0x1F];
|
|
94
|
-
buffer[o++] = alphabet[x >> 4 & 0x1F];
|
|
95
|
-
x = (x << 16) | (buffer[i - 1] << 8);
|
|
96
|
-
buffer[o++] = alphabet[x >> 15 & 0x1F];
|
|
97
|
-
buffer[o++] = alphabet[x >> 10 & 0x1F];
|
|
98
|
-
buffer[o++] = alphabet[x >> 5 & 0x1F];
|
|
99
|
-
buffer[o++] = padding;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return o;
|
|
104
|
-
}
|
|
105
|
-
export function decode(buffer, i, o, alphabet, padding) {
|
|
106
|
-
for (let x = buffer.length - 6; x < buffer.length; ++x) {
|
|
107
|
-
if (buffer[x] === padding) {
|
|
108
|
-
for (let y = x + 1; y < buffer.length; ++y) {
|
|
109
|
-
if (buffer[y] !== padding) {
|
|
110
|
-
throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(buffer[y])})`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
buffer = buffer.subarray(0, x);
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
switch ((buffer.length - o) % 8) {
|
|
118
|
-
case 6:
|
|
119
|
-
case 3:
|
|
120
|
-
case 1:
|
|
121
|
-
throw new RangeError(`Cannot decode input as base32: Length (${buffer.length - o}), excluding padding, must not have a remainder of 1, 3, or 6 when divided by 8`);
|
|
122
|
-
}
|
|
123
|
-
i += 7;
|
|
124
|
-
for (; i < buffer.length; i += 8) {
|
|
125
|
-
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
126
|
-
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
127
|
-
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
128
|
-
(getByte(buffer[i - 4], alphabet) << 4);
|
|
129
|
-
buffer[o++] = x >> 16;
|
|
130
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
131
|
-
x = (x << 16) |
|
|
132
|
-
(getByte(buffer[i - 3], alphabet) << 15) |
|
|
133
|
-
(getByte(buffer[i - 2], alphabet) << 10) |
|
|
134
|
-
(getByte(buffer[i - 1], alphabet) << 5) |
|
|
135
|
-
getByte(buffer[i], alphabet);
|
|
136
|
-
buffer[o++] = x >> 16 & 0xFF;
|
|
137
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
138
|
-
buffer[o++] = x & 0xFF;
|
|
139
|
-
}
|
|
140
|
-
switch (i) {
|
|
141
|
-
case buffer.length + 5: {
|
|
142
|
-
const x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
143
|
-
(getByte(buffer[i - 6], alphabet) << 14);
|
|
144
|
-
buffer[o++] = x >> 16;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
case buffer.length + 3: {
|
|
148
|
-
const x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
149
|
-
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
150
|
-
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
151
|
-
(getByte(buffer[i - 4], alphabet) << 4);
|
|
152
|
-
buffer[o++] = x >> 16;
|
|
153
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case buffer.length + 2: {
|
|
157
|
-
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
158
|
-
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
159
|
-
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
160
|
-
(getByte(buffer[i - 4], alphabet) << 4);
|
|
161
|
-
buffer[o++] = x >> 16;
|
|
162
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
163
|
-
x = (x << 16) |
|
|
164
|
-
(getByte(buffer[i - 3], alphabet) << 15);
|
|
165
|
-
buffer[o++] = x >> 16 & 0xFF;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case buffer.length: {
|
|
169
|
-
let x = (getByte(buffer[i - 7], alphabet) << 19) |
|
|
170
|
-
(getByte(buffer[i - 6], alphabet) << 14) |
|
|
171
|
-
(getByte(buffer[i - 5], alphabet) << 9) |
|
|
172
|
-
(getByte(buffer[i - 4], alphabet) << 4);
|
|
173
|
-
buffer[o++] = x >> 16;
|
|
174
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
175
|
-
x = (x << 16) |
|
|
176
|
-
(getByte(buffer[i - 3], alphabet) << 15) |
|
|
177
|
-
(getByte(buffer[i - 2], alphabet) << 10) |
|
|
178
|
-
(getByte(buffer[i - 1], alphabet) << 5);
|
|
179
|
-
buffer[o++] = x >> 16 & 0xFF;
|
|
180
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return o;
|
|
185
|
-
}
|
|
186
|
-
function getByte(char, alphabet) {
|
|
187
|
-
const byte = alphabet[char] ?? 32;
|
|
188
|
-
if (byte === 32) { // alphabet.Base32.length
|
|
189
|
-
throw new TypeError(`Cannot decode input as base32: Invalid character (${String.fromCharCode(char)})`);
|
|
190
|
-
}
|
|
191
|
-
return byte;
|
|
192
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
-
export type { Uint8Array_ };
|
|
3
|
-
export declare const padding: number;
|
|
4
|
-
export declare const alphabet: Record<Base64Alphabet, Uint8Array>;
|
|
5
|
-
export declare const rAlphabet: Record<Base64Alphabet, Uint8Array>;
|
|
6
|
-
/**
|
|
7
|
-
* Options for encoding and decoding base64 strings.
|
|
8
|
-
*/
|
|
9
|
-
export interface Base64Options {
|
|
10
|
-
/** The base64 alphabet. Defaults to "base64" */
|
|
11
|
-
alphabet?: Base64Alphabet;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The base64 alphabets.
|
|
15
|
-
*/
|
|
16
|
-
export type Base64Alphabet = "base64" | "base64url";
|
|
17
|
-
/**
|
|
18
|
-
* Calculate the output size needed to encode a given input size for
|
|
19
|
-
* {@linkcode encodeIntoBase64}.
|
|
20
|
-
*
|
|
21
|
-
* @param originalSize The size of the input buffer.
|
|
22
|
-
* @returns The size of the output buffer.
|
|
23
|
-
*
|
|
24
|
-
* @example Basic Usage
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { assertEquals } from "@std/assert";
|
|
27
|
-
* import { calcSizeBase64 } from "@std/encoding/unstable-base64";
|
|
28
|
-
*
|
|
29
|
-
* assertEquals(calcSizeBase64(1), 4);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function calcSizeBase64(originalSize: number): number;
|
|
33
|
-
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
34
|
-
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
35
|
-
//# sourceMappingURL=_common64.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common64.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common64.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAKvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAGxD,CAAC;AAMF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CA4BR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmDR"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
export const padding = "=".charCodeAt(0);
|
|
3
|
-
export const alphabet = {
|
|
4
|
-
base64: new TextEncoder()
|
|
5
|
-
.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),
|
|
6
|
-
base64url: new TextEncoder()
|
|
7
|
-
.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),
|
|
8
|
-
};
|
|
9
|
-
export const rAlphabet = {
|
|
10
|
-
base64: new Uint8Array(128).fill(64), // alphabet.base64.length
|
|
11
|
-
base64url: new Uint8Array(128).fill(64),
|
|
12
|
-
};
|
|
13
|
-
alphabet.base64
|
|
14
|
-
.forEach((byte, i) => rAlphabet.base64[byte] = i);
|
|
15
|
-
alphabet.base64url
|
|
16
|
-
.forEach((byte, i) => rAlphabet.base64url[byte] = i);
|
|
17
|
-
/**
|
|
18
|
-
* Calculate the output size needed to encode a given input size for
|
|
19
|
-
* {@linkcode encodeIntoBase64}.
|
|
20
|
-
*
|
|
21
|
-
* @param originalSize The size of the input buffer.
|
|
22
|
-
* @returns The size of the output buffer.
|
|
23
|
-
*
|
|
24
|
-
* @example Basic Usage
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { assertEquals } from "@std/assert";
|
|
27
|
-
* import { calcSizeBase64 } from "@std/encoding/unstable-base64";
|
|
28
|
-
*
|
|
29
|
-
* assertEquals(calcSizeBase64(1), 4);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function calcSizeBase64(originalSize) {
|
|
33
|
-
return ((originalSize + 2) / 3 | 0) * 4;
|
|
34
|
-
}
|
|
35
|
-
export function encode(buffer, i, o, alphabet, padding) {
|
|
36
|
-
i += 2;
|
|
37
|
-
for (; i < buffer.length; i += 3) {
|
|
38
|
-
const x = (buffer[i - 2] << 16) | (buffer[i - 1] << 8) | buffer[i];
|
|
39
|
-
buffer[o++] = alphabet[x >> 18];
|
|
40
|
-
buffer[o++] = alphabet[x >> 12 & 0x3F];
|
|
41
|
-
buffer[o++] = alphabet[x >> 6 & 0x3F];
|
|
42
|
-
buffer[o++] = alphabet[x & 0x3F];
|
|
43
|
-
}
|
|
44
|
-
switch (i) {
|
|
45
|
-
case buffer.length + 1: {
|
|
46
|
-
const x = buffer[i - 2] << 16;
|
|
47
|
-
buffer[o++] = alphabet[x >> 18];
|
|
48
|
-
buffer[o++] = alphabet[x >> 12 & 0x3F];
|
|
49
|
-
buffer[o++] = padding;
|
|
50
|
-
buffer[o++] = padding;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case buffer.length: {
|
|
54
|
-
const x = (buffer[i - 2] << 16) | (buffer[i - 1] << 8);
|
|
55
|
-
buffer[o++] = alphabet[x >> 18];
|
|
56
|
-
buffer[o++] = alphabet[x >> 12 & 0x3F];
|
|
57
|
-
buffer[o++] = alphabet[x >> 6 & 0x3F];
|
|
58
|
-
buffer[o++] = padding;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return o;
|
|
63
|
-
}
|
|
64
|
-
export function decode(buffer, i, o, alphabet, padding) {
|
|
65
|
-
for (let x = buffer.length - 2; x < buffer.length; ++x) {
|
|
66
|
-
if (buffer[x] === padding) {
|
|
67
|
-
for (let y = x + 1; y < buffer.length; ++y) {
|
|
68
|
-
if (buffer[y] !== padding) {
|
|
69
|
-
throw new TypeError(`Cannot decode input as base64: Invalid character (${String.fromCharCode(buffer[y])})`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
buffer = buffer.subarray(0, x);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if ((buffer.length - o) % 4 === 1) {
|
|
77
|
-
throw new RangeError(`Cannot decode input as base64: Length (${buffer.length - o}), excluding padding, must not have a remainder of 1 when divided by 4`);
|
|
78
|
-
}
|
|
79
|
-
i += 3;
|
|
80
|
-
for (; i < buffer.length; i += 4) {
|
|
81
|
-
const x = (getByte(buffer[i - 3], alphabet) << 18) |
|
|
82
|
-
(getByte(buffer[i - 2], alphabet) << 12) |
|
|
83
|
-
(getByte(buffer[i - 1], alphabet) << 6) |
|
|
84
|
-
getByte(buffer[i], alphabet);
|
|
85
|
-
buffer[o++] = x >> 16;
|
|
86
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
87
|
-
buffer[o++] = x & 0xFF;
|
|
88
|
-
}
|
|
89
|
-
switch (i) {
|
|
90
|
-
case buffer.length + 1: {
|
|
91
|
-
const x = (getByte(buffer[i - 3], alphabet) << 18) |
|
|
92
|
-
(getByte(buffer[i - 2], alphabet) << 12);
|
|
93
|
-
buffer[o++] = x >> 16;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case buffer.length: {
|
|
97
|
-
const x = (getByte(buffer[i - 3], alphabet) << 18) |
|
|
98
|
-
(getByte(buffer[i - 2], alphabet) << 12) |
|
|
99
|
-
(getByte(buffer[i - 1], alphabet) << 6);
|
|
100
|
-
buffer[o++] = x >> 16;
|
|
101
|
-
buffer[o++] = x >> 8 & 0xFF;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return o;
|
|
106
|
-
}
|
|
107
|
-
function getByte(char, alphabet) {
|
|
108
|
-
const byte = alphabet[char] ?? 64;
|
|
109
|
-
if (byte === 64) { // alphabet.Base64.length
|
|
110
|
-
throw new TypeError(`Cannot decode input as base64: Invalid character (${String.fromCharCode(char)})`);
|
|
111
|
-
}
|
|
112
|
-
return byte;
|
|
113
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common_detach.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common_detach.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,GACd,CAAC,WAAW,EAAE,MAAM,CAAC,CAWvB"}
|