MCPcopy Create free account
hub / github.com/denoland/std / encodeBase64Url

Function encodeBase64Url

encoding/base64url.ts:39–56  ·  view source on GitHub ↗
(
  data: ArrayBuffer | Uint8Array | string,
)

Source from the content-addressed store, hash-verified

37 * ```
38 */
39export function encodeBase64Url(
40 data: ArrayBuffer | Uint8Array | string,
41): string {
42 if (typeof data === "string") {
43 data = new TextEncoder().encode(data) as Uint8Array_;
44 } else if (data instanceof ArrayBuffer) data = new Uint8Array(data).slice();
45 else data = data.slice();
46 const [output, i] = detach(
47 data as Uint8Array_,
48 calcSizeBase64((data as Uint8Array_).length),
49 );
50 let o = encode(output, i, 0, alphabet, padding);
51 o = output.indexOf(padding, o - 2);
52 return new TextDecoder().decode(
53 // deno-lint-ignore no-explicit-any
54 o > 0 ? new Uint8Array((output.buffer as any).transfer(o)) : output,
55 );
56}
57
58/**
59 * Decodes a given base64url-encoded string.

Callers 1

base64url_test.tsFile · 0.90

Calls 4

detachFunction · 0.90
calcSizeBase64Function · 0.90
encodeFunction · 0.90
sliceMethod · 0.45

Tested by

no test coverage detected