summaryrefslogtreecommitdiff
path: root/extensions/web/05_base64.js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2021-08-11 12:27:05 +0200
committerGitHub <noreply@github.com>2021-08-11 12:27:05 +0200
commita0285e2eb88f6254f6494b0ecd1878db3a3b2a58 (patch)
tree90671b004537e20f9493fd3277ffd21d30b39a0e /extensions/web/05_base64.js
parent3a6994115176781b3a93d70794b1b81bc95e42b4 (diff)
Rename extensions/ directory to ext/ (#11643)
Diffstat (limited to 'extensions/web/05_base64.js')
-rw-r--r--extensions/web/05_base64.js73
1 files changed, 0 insertions, 73 deletions
diff --git a/extensions/web/05_base64.js b/extensions/web/05_base64.js
deleted file mode 100644
index 9c9c23b0f..000000000
--- a/extensions/web/05_base64.js
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-
-// @ts-check
-/// <reference path="../../core/internal.d.ts" />
-/// <reference path="../webidl/internal.d.ts" />
-/// <reference path="../web/internal.d.ts" />
-/// <reference lib="esnext" />
-
-"use strict";
-
-((window) => {
- const webidl = window.__bootstrap.webidl;
- const {
- forgivingBase64Encode,
- forgivingBase64Decode,
- } = window.__bootstrap.infra;
- const { DOMException } = window.__bootstrap.domException;
- const {
- ArrayPrototypeMap,
- StringPrototypeCharCodeAt,
- ArrayPrototypeJoin,
- StringFromCharCode,
- TypedArrayFrom,
- Uint8Array,
- } = window.__bootstrap.primordials;
-
- /**
- * @param {string} data
- * @returns {string}
- */
- function atob(data) {
- data = webidl.converters.DOMString(data, {
- prefix: "Failed to execute 'atob'",
- context: "Argument 1",
- });
-
- const uint8Array = forgivingBase64Decode(data);
- const result = ArrayPrototypeMap(
- [...uint8Array],
- (byte) => StringFromCharCode(byte),
- );
- return ArrayPrototypeJoin(result, "");
- }
-
- /**
- * @param {string} data
- * @returns {string}
- */
- function btoa(data) {
- const prefix = "Failed to execute 'btoa'";
- webidl.requiredArguments(arguments.length, 1, { prefix });
- data = webidl.converters.DOMString(data, {
- prefix,
- context: "Argument 1",
- });
- const byteArray = ArrayPrototypeMap([...data], (char) => {
- const charCode = StringPrototypeCharCodeAt(char, 0);
- if (charCode > 0xff) {
- throw new DOMException(
- "The string to be encoded contains characters outside of the Latin1 range.",
- "InvalidCharacterError",
- );
- }
- return charCode;
- });
- return forgivingBase64Encode(TypedArrayFrom(Uint8Array, byteArray));
- }
-
- window.__bootstrap.base64 = {
- atob,
- btoa,
- };
-})(globalThis);