compatibility.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. "use strict";
  23. var _is_node = require("./is_node.js");
  24. (function checkNodeBtoa() {
  25. if (globalThis.btoa || !_is_node.isNodeJS) {
  26. return;
  27. }
  28. globalThis.btoa = function (chars) {
  29. return Buffer.from(chars, "binary").toString("base64");
  30. };
  31. })();
  32. (function checkNodeAtob() {
  33. if (globalThis.atob || !_is_node.isNodeJS) {
  34. return;
  35. }
  36. globalThis.atob = function (input) {
  37. return Buffer.from(input, "base64").toString("binary");
  38. };
  39. })();
  40. (function checkDOMMatrix() {
  41. if (globalThis.DOMMatrix || !_is_node.isNodeJS) {
  42. return;
  43. }
  44. globalThis.DOMMatrix = require("canvas").DOMMatrix;
  45. })();
  46. (function checkReadableStream() {
  47. if (globalThis.ReadableStream || !_is_node.isNodeJS) {
  48. return;
  49. }
  50. globalThis.ReadableStream = require("web-streams-polyfill/dist/ponyfill.js").ReadableStream;
  51. })();
  52. (function checkArrayAt() {
  53. if (Array.prototype.at) {
  54. return;
  55. }
  56. require("core-js/es/array/at.js");
  57. })();
  58. (function checkTypedArrayAt() {
  59. if (Uint8Array.prototype.at) {
  60. return;
  61. }
  62. require("core-js/es/typed-array/at.js");
  63. })();
  64. (function checkStructuredClone() {
  65. if (globalThis.structuredClone) {
  66. return;
  67. }
  68. require("core-js/web/structured-clone.js");
  69. })();