From 6997bb8ef42c6d4dfada93bcc082d1aba02d311b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 28 May 2024 09:14:52 +1000 Subject: [PATCH 1/5] refactor(encoding): deprecate `Ascii85Options` --- encoding/ascii85.ts | 41 ++++++++++++++++++++++++++++++++++------ encoding/ascii85_test.ts | 1 - 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index 01611d980603..77a21eb96a9f 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -25,10 +25,18 @@ import { validateBinaryLike } from "./_util.ts"; -/** Supported ascii85 standards for {@linkcode Ascii85Options}. */ +/** + * Supported ascii85 standards for {@linkcode EncodeAscii85Options} and + * {@linkcode DecodeAscii85Options}. + */ export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85"; -/** Options for {@linkcode encodeAscii85} and {@linkcode decodeAscii85}. */ +/** + * Options for {@linkcode encodeAscii85}. + * + * @deprecated This will be removed in 1.0.0. Use + * {@linkcode EncodeAscii85Options} instead. + */ export interface Ascii85Options { /** * Character set and delimiter (if supported and used). @@ -43,6 +51,23 @@ export interface Ascii85Options { */ delimiter?: boolean; } + +/** Options for {@linkcode encodeAscii85}. */ +export interface EncodeAscii85Options { + /** + * Character set and delimiter (if supported and used). + * + * @default {"Adobe"} + */ + standard?: Ascii85Standard; + /** + * Whether to use a delimiter (if supported). + * + * @default {false} + */ + delimiter?: boolean; +} + const rfc1924 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~" as const; const Z85 = @@ -66,7 +91,7 @@ const Z85 = */ export function encodeAscii85( data: ArrayBuffer | Uint8Array | string, - options?: Ascii85Options, + options?: EncodeAscii85Options, ): string { let uint8 = validateBinaryLike(data); @@ -129,6 +154,9 @@ export function encodeAscii85( return output.slice(0, output.length - difference).join(""); } +/** Options for {@linkcode decodeAscii85}. */ +export type DecodeAscii85Options = Omit; + /** * Decodes a ascii85-encoded string. * @@ -149,11 +177,12 @@ export function encodeAscii85( */ export function decodeAscii85( ascii85: string, - options?: Ascii85Options, + options: DecodeAscii85Options = {}, ): Uint8Array { - const encoding = options?.standard ?? "Adobe"; + const { standard = "Adobe" } = options; + // translate all encodings to most basic adobe/btoa one and decompress some special characters ("z" and "y") - switch (encoding) { + switch (standard) { case "Adobe": ascii85 = ascii85.replaceAll(/(<~|~>)/g, "").replaceAll("z", "!!!!!"); break; diff --git a/encoding/ascii85_test.ts b/encoding/ascii85_test.ts index 1e78c5bbb7d9..9372bc5906c3 100644 --- a/encoding/ascii85_test.ts +++ b/encoding/ascii85_test.ts @@ -174,7 +174,6 @@ for (const [standard, tests] of Object.entries(testCasesDelimiter)) { assertEquals( decodeAscii85(b85 as string, { standard: standard as Ascii85Standard, - delimiter: true, }), utf8encoder.encode(bin), ); From 35a090d279124d93e9ced252781cada7aaa7e525 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 28 May 2024 09:18:44 +1000 Subject: [PATCH 2/5] tweak --- encoding/ascii85.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index 77a21eb96a9f..00c644a78082 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -35,7 +35,7 @@ export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85"; * Options for {@linkcode encodeAscii85}. * * @deprecated This will be removed in 1.0.0. Use - * {@linkcode EncodeAscii85Options} instead. + * {@linkcode EncodeAscii85Options} or {@linkcode DecodeAscii85Options} instead. */ export interface Ascii85Options { /** From 5d9bc2948572ae89d3747cdaf971ac2b2ac4aaf0 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 28 May 2024 09:20:21 +1000 Subject: [PATCH 3/5] tweak --- encoding/ascii85.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index 00c644a78082..75169d18667c 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -91,11 +91,12 @@ const Z85 = */ export function encodeAscii85( data: ArrayBuffer | Uint8Array | string, - options?: EncodeAscii85Options, + options: EncodeAscii85Options = {}, ): string { let uint8 = validateBinaryLike(data); - const standard = options?.standard ?? "Adobe"; + const { standard = "Adobe" } = options; + let output: string[] = []; let v: number; let n = 0; From f689d878b46504147f67447165e0344d92625c7b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 30 May 2024 11:24:00 +1000 Subject: [PATCH 4/5] tweak --- encoding/ascii85.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index 75169d18667c..9fe3c5dfc4c0 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -37,20 +37,7 @@ export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85"; * @deprecated This will be removed in 1.0.0. Use * {@linkcode EncodeAscii85Options} or {@linkcode DecodeAscii85Options} instead. */ -export interface Ascii85Options { - /** - * Character set and delimiter (if supported and used). - * - * @default {"Adobe"} - */ - standard?: Ascii85Standard; - /** - * Whether to use a delimiter (if supported). - * - * @default {false} - */ - delimiter?: boolean; -} +export interface Ascii85Options extends EncodeAscii85Options {} /** Options for {@linkcode encodeAscii85}. */ export interface EncodeAscii85Options { From 863eae6487f90f37e70b1c059e0d708b794a89e1 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 30 May 2024 19:28:28 +1000 Subject: [PATCH 5/5] tweaks --- encoding/ascii85.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index 1c8f303496fb..1b89e233f854 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -31,14 +31,6 @@ import { validateBinaryLike } from "./_validate_binary_like.ts"; */ export type Ascii85Standard = "Adobe" | "btoa" | "RFC 1924" | "Z85"; -/** - * Options for {@linkcode encodeAscii85}. - * - * @deprecated This will be removed in 1.0.0. Use - * {@linkcode EncodeAscii85Options} or {@linkcode DecodeAscii85Options} instead. - */ -export interface Ascii85Options extends EncodeAscii85Options {} - /** Options for {@linkcode encodeAscii85}. */ export interface EncodeAscii85Options { /**