@skmtc/core 0.0.244 → 0.0.246
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/esm/context/CoreContext.d.ts +1 -1
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +2 -2
- package/esm/context/RenderContext.d.ts +1 -1
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +6 -33
- package/esm/generate/generate.d.ts +1 -1
- package/esm/generate/generate.d.ts.map +1 -1
- package/esm/generate/generate.js +2 -2
- package/esm/server/createServer.js +2 -2
- package/esm/typescript/ReactRouterPathParams.js +1 -1
- package/package.json +1 -2
- package/script/context/CoreContext.d.ts +1 -1
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +2 -2
- package/script/context/RenderContext.d.ts +1 -1
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +9 -36
- package/script/generate/generate.d.ts +1 -1
- package/script/generate/generate.d.ts.map +1 -1
- package/script/generate/generate.js +2 -2
- package/script/server/createServer.js +2 -2
- package/script/typescript/ReactRouterPathParams.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.d.ts +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.js +0 -26
- package/esm/deps/jsr.io/@std/encoding/1.0.1/ascii85.d.ts +0 -59
- package/esm/deps/jsr.io/@std/encoding/1.0.1/ascii85.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/ascii85.js +0 -152
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base32.d.ts +0 -38
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base32.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base32.js +0 -224
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base58.d.ts +0 -38
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base58.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base58.js +0 -131
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64.d.ts +0 -38
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64.js +0 -163
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64url.d.ts +0 -38
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64url.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/base64url.js +0 -81
- package/esm/deps/jsr.io/@std/encoding/1.0.1/hex.d.ts +0 -37
- package/esm/deps/jsr.io/@std/encoding/1.0.1/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/hex.js +0 -109
- package/esm/deps/jsr.io/@std/encoding/1.0.1/mod.d.ts +0 -22
- package/esm/deps/jsr.io/@std/encoding/1.0.1/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/mod.js +0 -22
- package/esm/deps/jsr.io/@std/encoding/1.0.1/varint.d.ts +0 -118
- package/esm/deps/jsr.io/@std/encoding/1.0.1/varint.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.1/varint.js +0 -206
- package/script/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.d.ts +0 -2
- package/script/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.1/ascii85.d.ts +0 -59
- package/script/deps/jsr.io/@std/encoding/1.0.1/ascii85.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/ascii85.js +0 -156
- package/script/deps/jsr.io/@std/encoding/1.0.1/base32.d.ts +0 -38
- package/script/deps/jsr.io/@std/encoding/1.0.1/base32.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/base32.js +0 -228
- package/script/deps/jsr.io/@std/encoding/1.0.1/base58.d.ts +0 -38
- package/script/deps/jsr.io/@std/encoding/1.0.1/base58.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/base58.js +0 -135
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64.d.ts +0 -38
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64.js +0 -167
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64url.d.ts +0 -38
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64url.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/base64url.js +0 -108
- package/script/deps/jsr.io/@std/encoding/1.0.1/hex.d.ts +0 -37
- package/script/deps/jsr.io/@std/encoding/1.0.1/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/hex.js +0 -113
- package/script/deps/jsr.io/@std/encoding/1.0.1/mod.d.ts +0 -22
- package/script/deps/jsr.io/@std/encoding/1.0.1/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/mod.js +0 -38
- package/script/deps/jsr.io/@std/encoding/1.0.1/varint.d.ts +0 -118
- package/script/deps/jsr.io/@std/encoding/1.0.1/varint.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.1/varint.js +0 -212
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
// Copyright 2020 Keith Cirkel. All rights reserved. MIT license.
|
|
3
|
-
// Copyright 2023 Skye "MierenManz". All rights reserved. MIT license.
|
|
4
|
-
/**
|
|
5
|
-
* Utilities for {@link https://protobuf.dev/programming-guides/encoding/#varints Varint} encoding
|
|
6
|
-
* of typed integers. Varint encoding represents integers using a variable number of bytes, with
|
|
7
|
-
* smaller values requiring fewer bytes.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { encodeVarint, decodeVarint } from "@std/encoding/varint";
|
|
11
|
-
* import { assertEquals } from "@std/assert";
|
|
12
|
-
*
|
|
13
|
-
* const buf = new Uint8Array(10);
|
|
14
|
-
* assertEquals(
|
|
15
|
-
* encodeVarint(42n, buf),
|
|
16
|
-
* [new Uint8Array([42]), 1]
|
|
17
|
-
* );
|
|
18
|
-
*
|
|
19
|
-
* assertEquals(
|
|
20
|
-
* decodeVarint(new Uint8Array([42])),
|
|
21
|
-
* [ 42n, 1 ]
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @module
|
|
26
|
-
*/
|
|
27
|
-
// This implementation is a port of https://deno.land/x/varint@v2.0.0 by @keithamus
|
|
28
|
-
// This module is browser compatible.
|
|
29
|
-
/**
|
|
30
|
-
* The maximum value of an unsigned 64-bit integer.
|
|
31
|
-
* Equivalent to `2n**64n - 1n`
|
|
32
|
-
*/
|
|
33
|
-
export const MaxUint64 = 18446744073709551615n;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum length, in bytes, of a Varint encoded 64-bit integer.
|
|
36
|
-
*/
|
|
37
|
-
export const MaxVarintLen64 = 10;
|
|
38
|
-
/**
|
|
39
|
-
* The maximum length, in bytes, of a Varint encoded 32-bit integer.
|
|
40
|
-
*/
|
|
41
|
-
export const MaxVarintLen32 = 5;
|
|
42
|
-
const MSB = 0x80;
|
|
43
|
-
const REST = 0x7f;
|
|
44
|
-
const SHIFT = 7;
|
|
45
|
-
const MSBN = 0x80n;
|
|
46
|
-
const SHIFTN = 7n;
|
|
47
|
-
// ArrayBuffer and TypedArray's for "pointer casting"
|
|
48
|
-
const AB = new ArrayBuffer(8);
|
|
49
|
-
const U32_VIEW = new Uint32Array(AB);
|
|
50
|
-
const U64_VIEW = new BigUint64Array(AB);
|
|
51
|
-
/**
|
|
52
|
-
* Given a non empty `buf`, starting at `offset` (default: 0), begin decoding bytes as
|
|
53
|
-
* Varint encoded bytes, for a maximum of 10 bytes (offset + 10). The returned
|
|
54
|
-
* tuple is of the decoded varint 32-bit number, and the new offset with which
|
|
55
|
-
* to continue decoding other data.
|
|
56
|
-
*
|
|
57
|
-
* If a `bigint` in return is undesired, the `decode32` function will return a
|
|
58
|
-
* `number`, but this should only be used in cases where the varint is
|
|
59
|
-
* _assured_ to be 32-bits. If in doubt, use `decode()`.
|
|
60
|
-
*
|
|
61
|
-
* To know how many bytes the Varint took to encode, simply negate `offset`
|
|
62
|
-
* from the returned new `offset`.
|
|
63
|
-
*
|
|
64
|
-
* @param buf The buffer to decode from.
|
|
65
|
-
* @param offset The offset to start decoding from.
|
|
66
|
-
* @returns A tuple of the decoded varint 64-bit number, and the new offset.
|
|
67
|
-
*
|
|
68
|
-
* @example Usage
|
|
69
|
-
* ```ts
|
|
70
|
-
* import { decodeVarint } from "@std/encoding/varint";
|
|
71
|
-
* import { assertEquals } from "@std/assert";
|
|
72
|
-
*
|
|
73
|
-
* const buf = new Uint8Array([0x8E, 0x02]);
|
|
74
|
-
* assertEquals(decodeVarint(buf), [270n, 2]);
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export function decodeVarint(buf, offset = 0) {
|
|
78
|
-
// Clear the last result from the Two's complement view
|
|
79
|
-
U64_VIEW[0] = 0n;
|
|
80
|
-
// Setup the initiat state of the function
|
|
81
|
-
let intermediate = 0;
|
|
82
|
-
let position = 0;
|
|
83
|
-
let i = offset;
|
|
84
|
-
// If the buffer is empty Throw
|
|
85
|
-
if (buf.length === 0)
|
|
86
|
-
throw new RangeError("Cannot read empty buffer");
|
|
87
|
-
let byte;
|
|
88
|
-
do {
|
|
89
|
-
// Get a single byte from the buffer
|
|
90
|
-
byte = buf[i];
|
|
91
|
-
// 1. Take the lower 7 bits of the byte.
|
|
92
|
-
// 2. Shift the bits into the correct position.
|
|
93
|
-
// 3. Bitwise OR it with the intermediate value
|
|
94
|
-
// QUIRK: in the 5th (and 10th) iteration of this loop it will overflow on the shift.
|
|
95
|
-
// This causes only the lower 4 bits to be shifted into place and removing the upper 3 bits
|
|
96
|
-
intermediate |= (byte & 0b01111111) << position;
|
|
97
|
-
// If position is 28
|
|
98
|
-
// it means that this iteration needs to be written the the two's complement view
|
|
99
|
-
// This only happens once due to the `-4` in this branch
|
|
100
|
-
if (position === 28) {
|
|
101
|
-
// Write to the view
|
|
102
|
-
U32_VIEW[0] = intermediate;
|
|
103
|
-
// set `intermediate` to the remaining 3 bits
|
|
104
|
-
// We only want the remaining three bits because the other 4 have been "consumed" on line 21
|
|
105
|
-
intermediate = (byte & 0b01110000) >>> 4;
|
|
106
|
-
// set `position` to -4 because later 7 will be added, making it 3
|
|
107
|
-
position = -4;
|
|
108
|
-
}
|
|
109
|
-
// Increment the shift position by 7
|
|
110
|
-
position += 7;
|
|
111
|
-
// Increment the iterator by 1
|
|
112
|
-
i++;
|
|
113
|
-
// Keep going while there is a continuation bit
|
|
114
|
-
} while ((byte & 0b10000000) === 0b10000000);
|
|
115
|
-
// subtract the initial offset from `i` to get the bytes read
|
|
116
|
-
const nRead = i - offset;
|
|
117
|
-
// If 10 bytes have been read and intermediate has overflown
|
|
118
|
-
// it means that the varint is malformed
|
|
119
|
-
// If 11 bytes have been read it means that the varint is malformed
|
|
120
|
-
// If `i` is bigger than the buffer it means we overread the buffer and the varint is malformed
|
|
121
|
-
if ((nRead === 10 && intermediate > -1) || nRead === 11 || i > buf.length) {
|
|
122
|
-
throw new RangeError("malformed or overflow varint");
|
|
123
|
-
}
|
|
124
|
-
// Write the intermediate value to the "empty" slot
|
|
125
|
-
// if the first slot is taken. Take the second slot
|
|
126
|
-
U32_VIEW[Number(nRead > 4)] = intermediate;
|
|
127
|
-
return [U64_VIEW[0], i];
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Given a `buf`, starting at `offset` (default: 0), begin decoding bytes as
|
|
131
|
-
* Varint encoded bytes, for a maximum of 5 bytes (offset + 5). The returned
|
|
132
|
-
* tuple is of the decoded varint 32-bit number, and the new offset with which
|
|
133
|
-
* to continue decoding other data.
|
|
134
|
-
*
|
|
135
|
-
* Varints are _not 32-bit by default_ so this should only be used in cases
|
|
136
|
-
* where the varint is _assured_ to be 32-bits. If in doubt, use `decode()`.
|
|
137
|
-
*
|
|
138
|
-
* To know how many bytes the Varint took to encode, simply negate `offset`
|
|
139
|
-
* from the returned new `offset`.
|
|
140
|
-
*
|
|
141
|
-
* @param buf The buffer to decode from.
|
|
142
|
-
* @param offset The offset to start decoding from.
|
|
143
|
-
* @returns A tuple of the decoded varint 32-bit number, and the new offset.
|
|
144
|
-
*
|
|
145
|
-
* @example Usage
|
|
146
|
-
* ```ts
|
|
147
|
-
* import { decodeVarint32 } from "@std/encoding/varint";
|
|
148
|
-
* import { assertEquals } from "@std/assert";
|
|
149
|
-
*
|
|
150
|
-
* const buf = new Uint8Array([0x8E, 0x02]);
|
|
151
|
-
* assertEquals(decodeVarint32(buf), [270, 2]);
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export function decodeVarint32(buf, offset = 0) {
|
|
155
|
-
let shift = 0;
|
|
156
|
-
let decoded = 0;
|
|
157
|
-
for (let i = offset; i <= Math.min(buf.length, offset + MaxVarintLen32); i += 1, shift += SHIFT) {
|
|
158
|
-
const byte = buf[i];
|
|
159
|
-
decoded += (byte & REST) * Math.pow(2, shift);
|
|
160
|
-
if (!(byte & MSB))
|
|
161
|
-
return [decoded, i + 1];
|
|
162
|
-
}
|
|
163
|
-
throw new RangeError("malformed or overflow varint");
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Takes unsigned number `num` and converts it into a Varint encoded
|
|
167
|
-
* `Uint8Array`, returning a tuple consisting of a `Uint8Array` slice of the
|
|
168
|
-
* encoded Varint, and an offset where the Varint encoded bytes end within the
|
|
169
|
-
* `Uint8Array`.
|
|
170
|
-
*
|
|
171
|
-
* If `buf` is not given then a Uint8Array will be created.
|
|
172
|
-
* `offset` defaults to `0`.
|
|
173
|
-
*
|
|
174
|
-
* If passed `buf` then that will be written into, starting at `offset`. The
|
|
175
|
-
* resulting returned `Uint8Array` will be a slice of `buf`. The resulting
|
|
176
|
-
* returned number is effectively `offset + bytesWritten`.
|
|
177
|
-
*
|
|
178
|
-
* @param num The number to encode.
|
|
179
|
-
* @param buf The buffer to write into.
|
|
180
|
-
* @param offset The offset to start writing at.
|
|
181
|
-
* @returns A tuple of the encoded Varint `Uint8Array` and the new offset.
|
|
182
|
-
*
|
|
183
|
-
* @example Usage
|
|
184
|
-
* ```ts
|
|
185
|
-
* import { encodeVarint } from "@std/encoding/varint";
|
|
186
|
-
* import { assertEquals } from "@std/assert";
|
|
187
|
-
*
|
|
188
|
-
* const buf = new Uint8Array(10);
|
|
189
|
-
* assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]);
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
export function encodeVarint(num, buf = new Uint8Array(MaxVarintLen64), offset = 0) {
|
|
193
|
-
num = BigInt(num);
|
|
194
|
-
if (num < 0n)
|
|
195
|
-
throw new RangeError("signed input given");
|
|
196
|
-
for (let i = offset; i <= Math.min(buf.length, MaxVarintLen64); i += 1) {
|
|
197
|
-
if (num < MSBN) {
|
|
198
|
-
buf[i] = Number(num);
|
|
199
|
-
i += 1;
|
|
200
|
-
return [buf.slice(offset, i), i];
|
|
201
|
-
}
|
|
202
|
-
buf[i] = Number((num & 0xffn) | MSBN);
|
|
203
|
-
num >>= SHIFTN;
|
|
204
|
-
}
|
|
205
|
-
throw new RangeError(`${num} overflows uint64`);
|
|
206
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_validate_binary_like.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.1/_validate_binary_like.ts"],"names":[],"mappings":"AAeA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,CAa9D"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateBinaryLike = validateBinaryLike;
|
|
5
|
-
const encoder = new TextEncoder();
|
|
6
|
-
function getTypeName(value) {
|
|
7
|
-
const type = typeof value;
|
|
8
|
-
if (type !== "object") {
|
|
9
|
-
return type;
|
|
10
|
-
}
|
|
11
|
-
else if (value === null) {
|
|
12
|
-
return "null";
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return value?.constructor?.name ?? "object";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function validateBinaryLike(source) {
|
|
19
|
-
if (typeof source === "string") {
|
|
20
|
-
return encoder.encode(source);
|
|
21
|
-
}
|
|
22
|
-
else if (source instanceof Uint8Array) {
|
|
23
|
-
return source;
|
|
24
|
-
}
|
|
25
|
-
else if (source instanceof ArrayBuffer) {
|
|
26
|
-
return new Uint8Array(source);
|
|
27
|
-
}
|
|
28
|
-
throw new TypeError(`The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type ${getTypeName(source)}.`);
|
|
29
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supported ascii85 standards for {@linkcode EncodeAscii85Options} and
|
|
3
|
-
* {@linkcode DecodeAscii85Options}.
|
|
4
|
-
*/
|
|
5
|
-
export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85";
|
|
6
|
-
/** Options for {@linkcode encodeAscii85}. */
|
|
7
|
-
export interface EncodeAscii85Options {
|
|
8
|
-
/**
|
|
9
|
-
* Character set and delimiter (if supported and used).
|
|
10
|
-
*
|
|
11
|
-
* @default {"Adobe"}
|
|
12
|
-
*/
|
|
13
|
-
standard?: Ascii85Standard;
|
|
14
|
-
/**
|
|
15
|
-
* Whether to use a delimiter (if supported).
|
|
16
|
-
*
|
|
17
|
-
* @default {false}
|
|
18
|
-
*/
|
|
19
|
-
delimiter?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Converts data into an ascii85-encoded string.
|
|
23
|
-
*
|
|
24
|
-
* @param data The data to encode.
|
|
25
|
-
* @param options Options for encoding.
|
|
26
|
-
*
|
|
27
|
-
* @returns The ascii85-encoded string.
|
|
28
|
-
*
|
|
29
|
-
* @example Usage
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { encodeAscii85 } from "@std/encoding/ascii85";
|
|
32
|
-
* import { assertEquals } from "@std/assert";
|
|
33
|
-
*
|
|
34
|
-
* assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare function encodeAscii85(data: ArrayBuffer | Uint8Array | string, options?: EncodeAscii85Options): string;
|
|
38
|
-
/** Options for {@linkcode decodeAscii85}. */
|
|
39
|
-
export type DecodeAscii85Options = Omit<EncodeAscii85Options, "delimiter">;
|
|
40
|
-
/**
|
|
41
|
-
* Decodes a ascii85-encoded string.
|
|
42
|
-
*
|
|
43
|
-
* @param ascii85 The ascii85-encoded string to decode.
|
|
44
|
-
* @param options Options for decoding.
|
|
45
|
-
* @returns The decoded data.
|
|
46
|
-
*
|
|
47
|
-
* @example Usage
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { decodeAscii85 } from "@std/encoding/ascii85";
|
|
50
|
-
* import { assertEquals } from "@std/assert";
|
|
51
|
-
*
|
|
52
|
-
* assertEquals(
|
|
53
|
-
* decodeAscii85("87cURD]j7BEbo80"),
|
|
54
|
-
* new TextEncoder().encode("Hello world!"),
|
|
55
|
-
* );
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function decodeAscii85(ascii85: string, options?: DecodeAscii85Options): Uint8Array;
|
|
59
|
-
//# 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.1/ascii85.ts"],"names":[],"mappings":"AAyBA;;;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,UAAU,CA4CZ"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.encodeAscii85 = encodeAscii85;
|
|
6
|
-
exports.decodeAscii85 = decodeAscii85;
|
|
7
|
-
/**
|
|
8
|
-
* Utilities for working with {@link https://en.wikipedia.org/wiki/Ascii85 | ascii85} encoding.
|
|
9
|
-
*
|
|
10
|
-
* ## Specifying a standard and delimiter
|
|
11
|
-
*
|
|
12
|
-
* By default, all functions are using the most popular Adobe version of ascii85
|
|
13
|
-
* and not adding any delimiter. However, there are three more standards
|
|
14
|
-
* supported - btoa (different delimiter and additional compression of 4 bytes
|
|
15
|
-
* equal to 32), {@link https://rfc.zeromq.org/spec/32/ | Z85} and
|
|
16
|
-
* {@link https://www.rfc-editor.org/rfc/rfc1924.html | RFC 1924}. It's possible to use a
|
|
17
|
-
* different encoding by specifying it in `options` object as a second parameter.
|
|
18
|
-
*
|
|
19
|
-
* Similarly, it's possible to make `encode` add a delimiter (`<~` and `~>` for
|
|
20
|
-
* Adobe, `xbtoa Begin` and `xbtoa End` with newlines between the delimiters and
|
|
21
|
-
* encoded data for btoa. Checksums for btoa are not supported. Delimiters are not
|
|
22
|
-
* supported by other encodings.)
|
|
23
|
-
*
|
|
24
|
-
* @module
|
|
25
|
-
*/
|
|
26
|
-
const _validate_binary_like_js_1 = require("./_validate_binary_like.js");
|
|
27
|
-
const rfc1924 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
|
|
28
|
-
const Z85 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
|
|
29
|
-
/**
|
|
30
|
-
* Converts data into an ascii85-encoded string.
|
|
31
|
-
*
|
|
32
|
-
* @param data The data to encode.
|
|
33
|
-
* @param options Options for encoding.
|
|
34
|
-
*
|
|
35
|
-
* @returns The ascii85-encoded string.
|
|
36
|
-
*
|
|
37
|
-
* @example Usage
|
|
38
|
-
* ```ts
|
|
39
|
-
* import { encodeAscii85 } from "@std/encoding/ascii85";
|
|
40
|
-
* import { assertEquals } from "@std/assert";
|
|
41
|
-
*
|
|
42
|
-
* assertEquals(encodeAscii85("Hello world!"), "87cURD]j7BEbo80");
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
function encodeAscii85(data, options = {}) {
|
|
46
|
-
let uint8 = (0, _validate_binary_like_js_1.validateBinaryLike)(data);
|
|
47
|
-
const { standard = "Adobe" } = options;
|
|
48
|
-
let output = [];
|
|
49
|
-
let v;
|
|
50
|
-
let n = 0;
|
|
51
|
-
let difference = 0;
|
|
52
|
-
if (uint8.length % 4 !== 0) {
|
|
53
|
-
const tmp = uint8;
|
|
54
|
-
difference = 4 - (tmp.length % 4);
|
|
55
|
-
uint8 = new Uint8Array(tmp.length + difference);
|
|
56
|
-
uint8.set(tmp);
|
|
57
|
-
}
|
|
58
|
-
const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
|
|
59
|
-
for (let i = 0; i < uint8.length; i += 4) {
|
|
60
|
-
v = view.getUint32(i);
|
|
61
|
-
// Adobe and btoa standards compress 4 zeroes to single "z" character
|
|
62
|
-
if ((standard === "Adobe" || standard === "btoa") &&
|
|
63
|
-
v === 0 &&
|
|
64
|
-
i < uint8.length - difference - 3) {
|
|
65
|
-
output[n++] = "z";
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
// btoa compresses 4 spaces - that is, bytes equal to 32 - into single "y" character
|
|
69
|
-
if (standard === "btoa" && v === 538976288) {
|
|
70
|
-
output[n++] = "y";
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
for (let j = 4; j >= 0; j--) {
|
|
74
|
-
output[n + j] = String.fromCharCode((v % 85) + 33);
|
|
75
|
-
v = Math.trunc(v / 85);
|
|
76
|
-
}
|
|
77
|
-
n += 5;
|
|
78
|
-
}
|
|
79
|
-
switch (standard) {
|
|
80
|
-
case "Adobe":
|
|
81
|
-
if (options?.delimiter) {
|
|
82
|
-
return `<~${output.slice(0, output.length - difference).join("")}~>`;
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
case "btoa":
|
|
86
|
-
if (options?.delimiter) {
|
|
87
|
-
return `xbtoa Begin\n${output
|
|
88
|
-
.slice(0, output.length - difference)
|
|
89
|
-
.join("")}\nxbtoa End`;
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
case "RFC 1924":
|
|
93
|
-
output = output.map((val) => rfc1924[val.charCodeAt(0) - 33]);
|
|
94
|
-
break;
|
|
95
|
-
case "Z85":
|
|
96
|
-
output = output.map((val) => Z85[val.charCodeAt(0) - 33]);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
return output.slice(0, output.length - difference).join("");
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Decodes a ascii85-encoded string.
|
|
103
|
-
*
|
|
104
|
-
* @param ascii85 The ascii85-encoded string to decode.
|
|
105
|
-
* @param options Options for decoding.
|
|
106
|
-
* @returns The decoded data.
|
|
107
|
-
*
|
|
108
|
-
* @example Usage
|
|
109
|
-
* ```ts
|
|
110
|
-
* import { decodeAscii85 } from "@std/encoding/ascii85";
|
|
111
|
-
* import { assertEquals } from "@std/assert";
|
|
112
|
-
*
|
|
113
|
-
* assertEquals(
|
|
114
|
-
* decodeAscii85("87cURD]j7BEbo80"),
|
|
115
|
-
* new TextEncoder().encode("Hello world!"),
|
|
116
|
-
* );
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
function decodeAscii85(ascii85, options = {}) {
|
|
120
|
-
const { standard = "Adobe" } = options;
|
|
121
|
-
// translate all encodings to most basic adobe/btoa one and decompress some special characters ("z" and "y")
|
|
122
|
-
switch (standard) {
|
|
123
|
-
case "Adobe":
|
|
124
|
-
ascii85 = ascii85.replaceAll(/(<~|~>)/g, "").replaceAll("z", "!!!!!");
|
|
125
|
-
break;
|
|
126
|
-
case "btoa":
|
|
127
|
-
ascii85 = ascii85
|
|
128
|
-
.replaceAll(/(xbtoa Begin|xbtoa End|\n)/g, "")
|
|
129
|
-
.replaceAll("z", "!!!!!")
|
|
130
|
-
.replaceAll("y", "+<VdL");
|
|
131
|
-
break;
|
|
132
|
-
case "RFC 1924":
|
|
133
|
-
ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(rfc1924.indexOf(match) + 33));
|
|
134
|
-
break;
|
|
135
|
-
case "Z85":
|
|
136
|
-
ascii85 = ascii85.replaceAll(/./g, (match) => String.fromCharCode(Z85.indexOf(match) + 33));
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
// remove all invalid characters
|
|
140
|
-
ascii85 = ascii85.replaceAll(/[^!-u]/g, "");
|
|
141
|
-
const len = ascii85.length;
|
|
142
|
-
const output = new Uint8Array(len + 4 - (len % 4));
|
|
143
|
-
const view = new DataView(output.buffer);
|
|
144
|
-
let v = 0;
|
|
145
|
-
let n = 0;
|
|
146
|
-
let max = 0;
|
|
147
|
-
for (let i = 0; i < len;) {
|
|
148
|
-
for (max += 5; i < max; i++) {
|
|
149
|
-
v = v * 85 + (i < len ? ascii85.charCodeAt(i) : 117) - 33;
|
|
150
|
-
}
|
|
151
|
-
view.setUint32(n, v);
|
|
152
|
-
v = 0;
|
|
153
|
-
n += 4;
|
|
154
|
-
}
|
|
155
|
-
return output.slice(0, Math.trunc(len * 0.8));
|
|
156
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decodes a base32-encoded string.
|
|
3
|
-
*
|
|
4
|
-
* @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
|
|
5
|
-
*
|
|
6
|
-
* @param b32 The base32-encoded string to decode.
|
|
7
|
-
* @returns The decoded data.
|
|
8
|
-
*
|
|
9
|
-
* @example Usage
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { decodeBase32 } from "@std/encoding/base32";
|
|
12
|
-
* import { assertEquals } from "@std/assert";
|
|
13
|
-
*
|
|
14
|
-
* assertEquals(
|
|
15
|
-
* decodeBase32("GZRTMMDDGA======"),
|
|
16
|
-
* new TextEncoder().encode("6c60c0"),
|
|
17
|
-
* );
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function decodeBase32(b32: string): Uint8Array;
|
|
21
|
-
/**
|
|
22
|
-
* Converts data into a base32-encoded string.
|
|
23
|
-
*
|
|
24
|
-
* @see {@link https://www.rfc-editor.org/rfc/rfc4648.html#section-6}
|
|
25
|
-
*
|
|
26
|
-
* @param data The data to encode.
|
|
27
|
-
* @returns The base32-encoded string.
|
|
28
|
-
*
|
|
29
|
-
* @example Usage
|
|
30
|
-
* ```ts
|
|
31
|
-
* import { encodeBase32 } from "@std/encoding/base32";
|
|
32
|
-
* import { assertEquals } from "@std/assert";
|
|
33
|
-
*
|
|
34
|
-
* assertEquals(encodeBase32("6c60c0"), "GZRTMMDDGA======");
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare function encodeBase32(data: ArrayBuffer | Uint8Array | string): string;
|
|
38
|
-
//# 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.1/base32.ts"],"names":[],"mappings":"AA6DA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAkEpD;AAwBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CA6D5E"}
|