diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8d2d016fe5944..a5ad7e5c0c405 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1780,6 +1780,12 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__ "toSpliced", "with", ], + esnext: [ + "toBase64", + "setFromBase64", + "toHex", + "setFromHex", + ], })), Uint8ClampedArray: new Map(Object.entries({ es2022: [ @@ -1908,6 +1914,12 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__ "cause", ], })), + Uint8ArrayConstructor: new Map(Object.entries({ + esnext: [ + "fromBase64", + "fromHex", + ], + })), })) ); diff --git a/src/lib/esnext.array.d.ts b/src/lib/esnext.array.d.ts index 91112ce421ba0..70694a1b1328f 100644 --- a/src/lib/esnext.array.d.ts +++ b/src/lib/esnext.array.d.ts @@ -15,3 +15,73 @@ interface ArrayConstructor { */ fromAsync(iterableOrArrayLike: AsyncIterable | Iterable | ArrayLike, mapFn: (value: Awaited, index: number) => U, thisArg?: any): Promise[]>; } + +interface Uint8ArrayConstructor { + /** + * Creates a new `Uint8Array` from a base64-encoded string. + * @param string The base64-encoded string. + * @param options If provided, specifies the alphabet and handling of the last chunk. + * @returns A new `Uint8Array` instance. + * @throws {SyntaxError} If the input string contains characters outside the specified alphabet, or if the last + * chunk is inconsistent with the `lastChunkHandling` option. + */ + fromBase64( + string: string, + options?: { + alphabet?: "base64" | "base64url"; + lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; + }, + ): Uint8Array; + + /** + * Creates a new `Uint8Array` from a base16-encoded string. + * @returns A new `Uint8Array` instance. + */ + fromHex( + string: string, + ): Uint8Array; +} + +interface Uint8Array { + /** + * Converts the `Uint8Array` to a base64-encoded string. + * @param options If provided, sets the alphabet and padding behavior used. + * @returns A base64-encoded string. + */ + toBase64(options?: { + alphabet?: "base64" | "base64url"; + omitPadding?: boolean; + }): string; + + /** + * Sets the `Uint8Array` from a base64-encoded string. + * @param string The base64-encoded string. + * @param options If provided, specifies the alphabet and handling of the last chunk. + * @returns An object containing the number of bytes read and written. + * @throws {SyntaxError} If the input string contains characters outside the specified alphabet, or if the last + * chunk is inconsistent with the `lastChunkHandling` option. + */ + setFromBase64(string: string, options?: { + alphabet?: "base64" | "base64url"; + lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; + }): { + read: number; + written: number; + }; + + /** + * Converts the `Uint8Array` to a base16-encoded string. + * @returns A base16-encoded string. + */ + toHex(): string; + + /** + * Sets the `Uint8Array` from a base16-encoded string. + * @param string The base16-encoded string. + * @returns An object containing the number of bytes read and written. + */ + setFromHex(string: string): { + read: number; + written: number; + }; +} diff --git a/tests/baselines/reference/findLast(target=esnext).symbols b/tests/baselines/reference/findLast(target=esnext).symbols index 0e47b29a2e7fa..5c5781e1ef877 100644 --- a/tests/baselines/reference/findLast(target=esnext).symbols +++ b/tests/baselines/reference/findLast(target=esnext).symbols @@ -24,7 +24,7 @@ new Int8Array().findLast((item) => item === 0); new Uint8Array().findLast((item) => item === 0); >new Uint8Array().findLast : Symbol(Uint8Array.findLast, Decl(lib.es2023.array.d.ts, --, --), Decl(lib.es2023.array.d.ts, --, --)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) >findLast : Symbol(Uint8Array.findLast, Decl(lib.es2023.array.d.ts, --, --), Decl(lib.es2023.array.d.ts, --, --)) >item : Symbol(item, Decl(findLast.ts, 3, 27)) >item : Symbol(item, Decl(findLast.ts, 3, 27)) @@ -117,7 +117,7 @@ new Int8Array().findLastIndex((item) => item === 0); new Uint8Array().findLastIndex((item) => item === 0); >new Uint8Array().findLastIndex : Symbol(Uint8Array.findLastIndex, Decl(lib.es2023.array.d.ts, --, --)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) >findLastIndex : Symbol(Uint8Array.findLastIndex, Decl(lib.es2023.array.d.ts, --, --)) >item : Symbol(item, Decl(findLast.ts, 17, 32)) >item : Symbol(item, Decl(findLast.ts, 17, 32)) diff --git a/tests/baselines/reference/indexAt(target=esnext).symbols b/tests/baselines/reference/indexAt(target=esnext).symbols index dbccd4a169ca1..d050c538d543e 100644 --- a/tests/baselines/reference/indexAt(target=esnext).symbols +++ b/tests/baselines/reference/indexAt(target=esnext).symbols @@ -16,7 +16,7 @@ new Int8Array().at(0); new Uint8Array().at(0); >new Uint8Array().at : Symbol(Uint8Array.at, Decl(lib.es2022.array.d.ts, --, --)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) >at : Symbol(Uint8Array.at, Decl(lib.es2022.array.d.ts, --, --)) new Uint8ClampedArray().at(0); diff --git a/tests/baselines/reference/subclassUint8Array.symbols b/tests/baselines/reference/subclassUint8Array.symbols index d94301cfecaad..da21e5af448eb 100644 --- a/tests/baselines/reference/subclassUint8Array.symbols +++ b/tests/baselines/reference/subclassUint8Array.symbols @@ -3,6 +3,6 @@ === subclassUint8Array.ts === class CustomBuffer extends Uint8Array { >CustomBuffer : Symbol(CustomBuffer, Decl(subclassUint8Array.ts, 0, 0)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) } diff --git a/tests/baselines/reference/toFromHexBase64(target=es2024).errors.txt b/tests/baselines/reference/toFromHexBase64(target=es2024).errors.txt new file mode 100644 index 0000000000000..39980ed96f271 --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=es2024).errors.txt @@ -0,0 +1,48 @@ +toFromHexBase64.ts(1,25): error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(2,25): error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(3,25): error TS2550: Property 'fromHex' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(12,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(13,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(14,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +toFromHexBase64.ts(20,20): error TS2550: Property 'setFromHex' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + + +==== toFromHexBase64.ts (7 errors) ==== + const arr1 = Uint8Array.fromBase64("AAAAAA=="); + ~~~~~~~~~~ +!!! error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); + ~~~~~~~~~~ +!!! error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + const arr3 = Uint8Array.fromHex("000000"); + ~~~~~~~ +!!! error TS2550: Property 'fromHex' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + + const encodedBase64_1 = arr1.toBase64(); + const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); + const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); + + const encodedHex_1 = arr1.toHex(); + + const target1 = new Uint8Array(10); + const r1 = target1.setFromBase64("AAAAAA=="); + ~~~~~~~~~~~~~ +!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); + ~~~~~~~~~~~~~ +!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + const r3 = target1.setFromBase64("AAAAAA", { + ~~~~~~~~~~~~~ +!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" + }); + + const target2 = new Uint8Array(10); + const r4 = target2.setFromHex("000000"); + ~~~~~~~~~~ +!!! error TS2550: Property 'setFromHex' does not exist on type 'Uint8Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. + + const totalWritten = r1.written + r2.written + r3.written + r4.written; + const totalRead = r1.read + r2.read + r3.read + r4.read; + \ No newline at end of file diff --git a/tests/baselines/reference/toFromHexBase64(target=es2024).js b/tests/baselines/reference/toFromHexBase64(target=es2024).js new file mode 100644 index 0000000000000..b6085d185ae45 --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=es2024).js @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +//// [toFromHexBase64.ts] +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +const arr3 = Uint8Array.fromHex("000000"); + +const encodedBase64_1 = arr1.toBase64(); +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); + +const encodedHex_1 = arr1.toHex(); + +const target1 = new Uint8Array(10); +const r1 = target1.setFromBase64("AAAAAA=="); +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +const r3 = target1.setFromBase64("AAAAAA", { + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" +}); + +const target2 = new Uint8Array(10); +const r4 = target2.setFromHex("000000"); + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +const totalRead = r1.read + r2.read + r3.read + r4.read; + + +//// [toFromHexBase64.js] +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +const arr3 = Uint8Array.fromHex("000000"); +const encodedBase64_1 = arr1.toBase64(); +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +const encodedHex_1 = arr1.toHex(); +const target1 = new Uint8Array(10); +const r1 = target1.setFromBase64("AAAAAA=="); +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +const r3 = target1.setFromBase64("AAAAAA", { + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" +}); +const target2 = new Uint8Array(10); +const r4 = target2.setFromHex("000000"); +const totalWritten = r1.written + r2.written + r3.written + r4.written; +const totalRead = r1.read + r2.read + r3.read + r4.read; diff --git a/tests/baselines/reference/toFromHexBase64(target=es2024).symbols b/tests/baselines/reference/toFromHexBase64(target=es2024).symbols new file mode 100644 index 0000000000000..f94803c978c82 --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=es2024).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +=== toFromHexBase64.ts === +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) + +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +>arr2 : Symbol(arr2, Decl(toFromHexBase64.ts, 1, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 1, 46)) + +const arr3 = Uint8Array.fromHex("000000"); +>arr3 : Symbol(arr3, Decl(toFromHexBase64.ts, 2, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) + +const encodedBase64_1 = arr1.toBase64(); +>encodedBase64_1 : Symbol(encodedBase64_1, Decl(toFromHexBase64.ts, 4, 5)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) + +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +>encodedBase64_2 : Symbol(encodedBase64_2, Decl(toFromHexBase64.ts, 5, 5)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 5, 39)) + +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +>encodedBase64_3 : Symbol(encodedBase64_3, Decl(toFromHexBase64.ts, 6, 5)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 6, 39)) +>omitPadding : Symbol(omitPadding, Decl(toFromHexBase64.ts, 6, 62)) + +const encodedHex_1 = arr1.toHex(); +>encodedHex_1 : Symbol(encodedHex_1, Decl(toFromHexBase64.ts, 8, 5)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) + +const target1 = new Uint8Array(10); +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) + +const r1 = target1.setFromBase64("AAAAAA=="); +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) + +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 12, 46)) + +const r3 = target1.setFromBase64("AAAAAA", { +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) + + alphabet: "base64url", +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 13, 44)) + + lastChunkHandling: "stop-before-partial" +>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 14, 24)) + +}); + +const target2 = new Uint8Array(10); +>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) + +const r4 = target2.setFromHex("000000"); +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) +>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +>totalWritten : Symbol(totalWritten, Decl(toFromHexBase64.ts, 21, 5)) +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) + +const totalRead = r1.read + r2.read + r3.read + r4.read; +>totalRead : Symbol(totalRead, Decl(toFromHexBase64.ts, 22, 5)) +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) + diff --git a/tests/baselines/reference/toFromHexBase64(target=es2024).types b/tests/baselines/reference/toFromHexBase64(target=es2024).types new file mode 100644 index 0000000000000..30ef4e6dd71ae --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=es2024).types @@ -0,0 +1,281 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +=== toFromHexBase64.ts === +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +>arr1 : any +> : ^^^ +>Uint8Array.fromBase64("AAAAAA==") : any +> : ^^^ +>Uint8Array.fromBase64 : any +> : ^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromBase64 : any +> : ^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ + +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +>arr2 : any +> : ^^^ +>Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }) : any +> : ^^^ +>Uint8Array.fromBase64 : any +> : ^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromBase64 : any +> : ^^^ +>"AAAAAA" : "AAAAAA" +> : ^^^^^^^^ +>{ alphabet: "base64url" } : { alphabet: string; } +> : ^^^^^^^^^^^^^^^^^^^^^ +>alphabet : string +> : ^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ + +const arr3 = Uint8Array.fromHex("000000"); +>arr3 : any +> : ^^^ +>Uint8Array.fromHex("000000") : any +> : ^^^ +>Uint8Array.fromHex : any +> : ^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromHex : any +> : ^^^ +>"000000" : "000000" +> : ^^^^^^^^ + +const encodedBase64_1 = arr1.toBase64(); +>encodedBase64_1 : any +> : ^^^ +>arr1.toBase64() : any +> : ^^^ +>arr1.toBase64 : any +> : ^^^ +>arr1 : any +> : ^^^ +>toBase64 : any +> : ^^^ + +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +>encodedBase64_2 : any +> : ^^^ +>arr1.toBase64({ alphabet: "base64" }) : any +> : ^^^ +>arr1.toBase64 : any +> : ^^^ +>arr1 : any +> : ^^^ +>toBase64 : any +> : ^^^ +>{ alphabet: "base64" } : { alphabet: string; } +> : ^^^^^^^^^^^^^^^^^^^^^ +>alphabet : string +> : ^^^^^^ +>"base64" : "base64" +> : ^^^^^^^^ + +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +>encodedBase64_3 : any +> : ^^^ +>arr1.toBase64({ alphabet: "base64url", omitPadding: true }) : any +> : ^^^ +>arr1.toBase64 : any +> : ^^^ +>arr1 : any +> : ^^^ +>toBase64 : any +> : ^^^ +>{ alphabet: "base64url", omitPadding: true } : { alphabet: string; omitPadding: boolean; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>alphabet : string +> : ^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ +>omitPadding : boolean +> : ^^^^^^^ +>true : true +> : ^^^^ + +const encodedHex_1 = arr1.toHex(); +>encodedHex_1 : any +> : ^^^ +>arr1.toHex() : any +> : ^^^ +>arr1.toHex : any +> : ^^^ +>arr1 : any +> : ^^^ +>toHex : any +> : ^^^ + +const target1 = new Uint8Array(10); +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>new Uint8Array(10) : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + +const r1 = target1.setFromBase64("AAAAAA=="); +>r1 : any +> : ^^^ +>target1.setFromBase64("AAAAAA==") : any +> : ^^^ +>target1.setFromBase64 : any +> : ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : any +> : ^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ + +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +>r2 : any +> : ^^^ +>target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }) : any +> : ^^^ +>target1.setFromBase64 : any +> : ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : any +> : ^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ +>{ lastChunkHandling: "strict" } : { lastChunkHandling: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>lastChunkHandling : string +> : ^^^^^^ +>"strict" : "strict" +> : ^^^^^^^^ + +const r3 = target1.setFromBase64("AAAAAA", { +>r3 : any +> : ^^^ +>target1.setFromBase64("AAAAAA", { alphabet: "base64url", lastChunkHandling: "stop-before-partial"}) : any +> : ^^^ +>target1.setFromBase64 : any +> : ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : any +> : ^^^ +>"AAAAAA" : "AAAAAA" +> : ^^^^^^^^ +>{ alphabet: "base64url", lastChunkHandling: "stop-before-partial"} : { alphabet: string; lastChunkHandling: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + alphabet: "base64url", +>alphabet : string +> : ^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ + + lastChunkHandling: "stop-before-partial" +>lastChunkHandling : string +> : ^^^^^^ +>"stop-before-partial" : "stop-before-partial" +> : ^^^^^^^^^^^^^^^^^^^^^ + +}); + +const target2 = new Uint8Array(10); +>target2 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>new Uint8Array(10) : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + +const r4 = target2.setFromHex("000000"); +>r4 : any +> : ^^^ +>target2.setFromHex("000000") : any +> : ^^^ +>target2.setFromHex : any +> : ^^^ +>target2 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromHex : any +> : ^^^ +>"000000" : "000000" +> : ^^^^^^^^ + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +>totalWritten : any +> : ^^^ +>r1.written + r2.written + r3.written + r4.written : any +> : ^^^ +>r1.written + r2.written + r3.written : any +> : ^^^ +>r1.written + r2.written : any +> : ^^^ +>r1.written : any +> : ^^^ +>r1 : any +> : ^^^ +>written : any +> : ^^^ +>r2.written : any +> : ^^^ +>r2 : any +> : ^^^ +>written : any +> : ^^^ +>r3.written : any +> : ^^^ +>r3 : any +> : ^^^ +>written : any +> : ^^^ +>r4.written : any +> : ^^^ +>r4 : any +> : ^^^ +>written : any +> : ^^^ + +const totalRead = r1.read + r2.read + r3.read + r4.read; +>totalRead : any +> : ^^^ +>r1.read + r2.read + r3.read + r4.read : any +> : ^^^ +>r1.read + r2.read + r3.read : any +> : ^^^ +>r1.read + r2.read : any +> : ^^^ +>r1.read : any +> : ^^^ +>r1 : any +> : ^^^ +>read : any +> : ^^^ +>r2.read : any +> : ^^^ +>r2 : any +> : ^^^ +>read : any +> : ^^^ +>r3.read : any +> : ^^^ +>r3 : any +> : ^^^ +>read : any +> : ^^^ +>r4.read : any +> : ^^^ +>r4 : any +> : ^^^ +>read : any +> : ^^^ + diff --git a/tests/baselines/reference/toFromHexBase64(target=esnext).js b/tests/baselines/reference/toFromHexBase64(target=esnext).js new file mode 100644 index 0000000000000..b6085d185ae45 --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=esnext).js @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +//// [toFromHexBase64.ts] +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +const arr3 = Uint8Array.fromHex("000000"); + +const encodedBase64_1 = arr1.toBase64(); +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); + +const encodedHex_1 = arr1.toHex(); + +const target1 = new Uint8Array(10); +const r1 = target1.setFromBase64("AAAAAA=="); +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +const r3 = target1.setFromBase64("AAAAAA", { + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" +}); + +const target2 = new Uint8Array(10); +const r4 = target2.setFromHex("000000"); + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +const totalRead = r1.read + r2.read + r3.read + r4.read; + + +//// [toFromHexBase64.js] +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +const arr3 = Uint8Array.fromHex("000000"); +const encodedBase64_1 = arr1.toBase64(); +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +const encodedHex_1 = arr1.toHex(); +const target1 = new Uint8Array(10); +const r1 = target1.setFromBase64("AAAAAA=="); +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +const r3 = target1.setFromBase64("AAAAAA", { + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" +}); +const target2 = new Uint8Array(10); +const r4 = target2.setFromHex("000000"); +const totalWritten = r1.written + r2.written + r3.written + r4.written; +const totalRead = r1.read + r2.read + r3.read + r4.read; diff --git a/tests/baselines/reference/toFromHexBase64(target=esnext).symbols b/tests/baselines/reference/toFromHexBase64(target=esnext).symbols new file mode 100644 index 0000000000000..01881795bad4b --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=esnext).symbols @@ -0,0 +1,120 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +=== toFromHexBase64.ts === +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>Uint8Array.fromBase64 : Symbol(Uint8ArrayConstructor.fromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) +>fromBase64 : Symbol(Uint8ArrayConstructor.fromBase64, Decl(lib.esnext.array.d.ts, --, --)) + +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +>arr2 : Symbol(arr2, Decl(toFromHexBase64.ts, 1, 5)) +>Uint8Array.fromBase64 : Symbol(Uint8ArrayConstructor.fromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) +>fromBase64 : Symbol(Uint8ArrayConstructor.fromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 1, 46)) + +const arr3 = Uint8Array.fromHex("000000"); +>arr3 : Symbol(arr3, Decl(toFromHexBase64.ts, 2, 5)) +>Uint8Array.fromHex : Symbol(Uint8ArrayConstructor.fromHex, Decl(lib.esnext.array.d.ts, --, --)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) +>fromHex : Symbol(Uint8ArrayConstructor.fromHex, Decl(lib.esnext.array.d.ts, --, --)) + +const encodedBase64_1 = arr1.toBase64(); +>encodedBase64_1 : Symbol(encodedBase64_1, Decl(toFromHexBase64.ts, 4, 5)) +>arr1.toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) + +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +>encodedBase64_2 : Symbol(encodedBase64_2, Decl(toFromHexBase64.ts, 5, 5)) +>arr1.toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 5, 39)) + +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +>encodedBase64_3 : Symbol(encodedBase64_3, Decl(toFromHexBase64.ts, 6, 5)) +>arr1.toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>toBase64 : Symbol(Uint8Array.toBase64, Decl(lib.esnext.array.d.ts, --, --)) +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 6, 39)) +>omitPadding : Symbol(omitPadding, Decl(toFromHexBase64.ts, 6, 62)) + +const encodedHex_1 = arr1.toHex(); +>encodedHex_1 : Symbol(encodedHex_1, Decl(toFromHexBase64.ts, 8, 5)) +>arr1.toHex : Symbol(Uint8Array.toHex, Decl(lib.esnext.array.d.ts, --, --)) +>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) +>toHex : Symbol(Uint8Array.toHex, Decl(lib.esnext.array.d.ts, --, --)) + +const target1 = new Uint8Array(10); +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) + +const r1 = target1.setFromBase64("AAAAAA=="); +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>target1.setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) + +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>target1.setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 12, 46)) + +const r3 = target1.setFromBase64("AAAAAA", { +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>target1.setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) +>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) +>setFromBase64 : Symbol(Uint8Array.setFromBase64, Decl(lib.esnext.array.d.ts, --, --)) + + alphabet: "base64url", +>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 13, 44)) + + lastChunkHandling: "stop-before-partial" +>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 14, 24)) + +}); + +const target2 = new Uint8Array(10); +>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) + +const r4 = target2.setFromHex("000000"); +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) +>target2.setFromHex : Symbol(Uint8Array.setFromHex, Decl(lib.esnext.array.d.ts, --, --)) +>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) +>setFromHex : Symbol(Uint8Array.setFromHex, Decl(lib.esnext.array.d.ts, --, --)) + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +>totalWritten : Symbol(totalWritten, Decl(toFromHexBase64.ts, 21, 5)) +>r1.written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r2.written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r3.written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r4.written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) +>written : Symbol(written, Decl(lib.esnext.array.d.ts, --, --)) + +const totalRead = r1.read + r2.read + r3.read + r4.read; +>totalRead : Symbol(totalRead, Decl(toFromHexBase64.ts, 22, 5)) +>r1.read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) +>read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r2.read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) +>read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r3.read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) +>read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r4.read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) +>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) +>read : Symbol(read, Decl(lib.esnext.array.d.ts, --, --)) + diff --git a/tests/baselines/reference/toFromHexBase64(target=esnext).types b/tests/baselines/reference/toFromHexBase64(target=esnext).types new file mode 100644 index 0000000000000..9f4e664272c27 --- /dev/null +++ b/tests/baselines/reference/toFromHexBase64(target=esnext).types @@ -0,0 +1,281 @@ +//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// + +=== toFromHexBase64.ts === +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +>arr1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromBase64("AAAAAA==") : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => Uint8Array +> : ^ ^^ ^^ ^^^ ^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => Uint8Array +> : ^ ^^ ^^ ^^^ ^^^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ + +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +>arr2 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }) : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => Uint8Array +> : ^ ^^ ^^ ^^^ ^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => Uint8Array +> : ^ ^^ ^^ ^^^ ^^^^^ +>"AAAAAA" : "AAAAAA" +> : ^^^^^^^^ +>{ alphabet: "base64url" } : { alphabet: "base64url"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>alphabet : "base64url" +> : ^^^^^^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ + +const arr3 = Uint8Array.fromHex("000000"); +>arr3 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromHex("000000") : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array.fromHex : (string: string) => Uint8Array +> : ^ ^^ ^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>fromHex : (string: string) => Uint8Array +> : ^ ^^ ^^^^^ +>"000000" : "000000" +> : ^^^^^^^^ + +const encodedBase64_1 = arr1.toBase64(); +>encodedBase64_1 : string +> : ^^^^^^ +>arr1.toBase64() : string +> : ^^^^^^ +>arr1.toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ +>arr1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ + +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +>encodedBase64_2 : string +> : ^^^^^^ +>arr1.toBase64({ alphabet: "base64" }) : string +> : ^^^^^^ +>arr1.toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ +>arr1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ +>{ alphabet: "base64" } : { alphabet: "base64"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>alphabet : "base64" +> : ^^^^^^^^ +>"base64" : "base64" +> : ^^^^^^^^ + +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); +>encodedBase64_3 : string +> : ^^^^^^ +>arr1.toBase64({ alphabet: "base64url", omitPadding: true }) : string +> : ^^^^^^ +>arr1.toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ +>arr1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>toBase64 : (options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }) => string +> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^ +>{ alphabet: "base64url", omitPadding: true } : { alphabet: "base64url"; omitPadding: true; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>alphabet : "base64url" +> : ^^^^^^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ +>omitPadding : true +> : ^^^^ +>true : true +> : ^^^^ + +const encodedHex_1 = arr1.toHex(); +>encodedHex_1 : string +> : ^^^^^^ +>arr1.toHex() : string +> : ^^^^^^ +>arr1.toHex : () => string +> : ^^^^^^ +>arr1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>toHex : () => string +> : ^^^^^^ + +const target1 = new Uint8Array(10); +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>new Uint8Array(10) : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + +const r1 = target1.setFromBase64("AAAAAA=="); +>r1 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64("AAAAAA==") : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ + +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +>r2 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }) : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>"AAAAAA==" : "AAAAAA==" +> : ^^^^^^^^^^ +>{ lastChunkHandling: "strict" } : { lastChunkHandling: "strict"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>lastChunkHandling : "strict" +> : ^^^^^^^^ +>"strict" : "strict" +> : ^^^^^^^^ + +const r3 = target1.setFromBase64("AAAAAA", { +>r3 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64("AAAAAA", { alphabet: "base64url", lastChunkHandling: "stop-before-partial"}) : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1.setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target1 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromBase64 : (string: string, options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose" | "strict" | "stop-before-partial"; }) => { read: number; written: number; } +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>"AAAAAA" : "AAAAAA" +> : ^^^^^^^^ +>{ alphabet: "base64url", lastChunkHandling: "stop-before-partial"} : { alphabet: "base64url"; lastChunkHandling: "stop-before-partial"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + alphabet: "base64url", +>alphabet : "base64url" +> : ^^^^^^^^^^^ +>"base64url" : "base64url" +> : ^^^^^^^^^^^ + + lastChunkHandling: "stop-before-partial" +>lastChunkHandling : "stop-before-partial" +> : ^^^^^^^^^^^^^^^^^^^^^ +>"stop-before-partial" : "stop-before-partial" +> : ^^^^^^^^^^^^^^^^^^^^^ + +}); + +const target2 = new Uint8Array(10); +>target2 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>new Uint8Array(10) : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>Uint8Array : Uint8ArrayConstructor +> : ^^^^^^^^^^^^^^^^^^^^^ +>10 : 10 +> : ^^ + +const r4 = target2.setFromHex("000000"); +>r4 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target2.setFromHex("000000") : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target2.setFromHex : (string: string) => { read: number; written: number; } +> : ^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>target2 : Uint8Array +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>setFromHex : (string: string) => { read: number; written: number; } +> : ^ ^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^ +>"000000" : "000000" +> : ^^^^^^^^ + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +>totalWritten : number +> : ^^^^^^ +>r1.written + r2.written + r3.written + r4.written : number +> : ^^^^^^ +>r1.written + r2.written + r3.written : number +> : ^^^^^^ +>r1.written + r2.written : number +> : ^^^^^^ +>r1.written : number +> : ^^^^^^ +>r1 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>written : number +> : ^^^^^^ +>r2.written : number +> : ^^^^^^ +>r2 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>written : number +> : ^^^^^^ +>r3.written : number +> : ^^^^^^ +>r3 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>written : number +> : ^^^^^^ +>r4.written : number +> : ^^^^^^ +>r4 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>written : number +> : ^^^^^^ + +const totalRead = r1.read + r2.read + r3.read + r4.read; +>totalRead : number +> : ^^^^^^ +>r1.read + r2.read + r3.read + r4.read : number +> : ^^^^^^ +>r1.read + r2.read + r3.read : number +> : ^^^^^^ +>r1.read + r2.read : number +> : ^^^^^^ +>r1.read : number +> : ^^^^^^ +>r1 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>read : number +> : ^^^^^^ +>r2.read : number +> : ^^^^^^ +>r2 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>read : number +> : ^^^^^^ +>r3.read : number +> : ^^^^^^ +>r3 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>read : number +> : ^^^^^^ +>r4.read : number +> : ^^^^^^ +>r4 : { read: number; written: number; } +> : ^^^^^^^^ ^^^^^^^^^^^ ^^^ +>read : number +> : ^^^^^^ + diff --git a/tests/cases/conformance/esnext/toFromHexBase64.ts b/tests/cases/conformance/esnext/toFromHexBase64.ts new file mode 100644 index 0000000000000..fa3f6b0f4724d --- /dev/null +++ b/tests/cases/conformance/esnext/toFromHexBase64.ts @@ -0,0 +1,25 @@ +// @target: esnext, es2024 + +const arr1 = Uint8Array.fromBase64("AAAAAA=="); +const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); +const arr3 = Uint8Array.fromHex("000000"); + +const encodedBase64_1 = arr1.toBase64(); +const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); +const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); + +const encodedHex_1 = arr1.toHex(); + +const target1 = new Uint8Array(10); +const r1 = target1.setFromBase64("AAAAAA=="); +const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); +const r3 = target1.setFromBase64("AAAAAA", { + alphabet: "base64url", + lastChunkHandling: "stop-before-partial" +}); + +const target2 = new Uint8Array(10); +const r4 = target2.setFromHex("000000"); + +const totalWritten = r1.written + r2.written + r3.written + r4.written; +const totalRead = r1.read + r2.read + r3.read + r4.read;