Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

web.btoa.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var globalThis = require('../internals/global-this');
  4. var getBuiltIn = require('../internals/get-built-in');
  5. var uncurryThis = require('../internals/function-uncurry-this');
  6. var call = require('../internals/function-call');
  7. var fails = require('../internals/fails');
  8. var toString = require('../internals/to-string');
  9. var validateArgumentsLength = require('../internals/validate-arguments-length');
  10. var i2c = require('../internals/base64-map').i2c;
  11. var $btoa = getBuiltIn('btoa');
  12. var charAt = uncurryThis(''.charAt);
  13. var charCodeAt = uncurryThis(''.charCodeAt);
  14. var BASIC = !!$btoa && !fails(function () {
  15. return $btoa('hi') !== 'aGk=';
  16. });
  17. var NO_ARG_RECEIVING_CHECK = BASIC && !fails(function () {
  18. $btoa();
  19. });
  20. var WRONG_ARG_CONVERSION = BASIC && fails(function () {
  21. return $btoa(null) !== 'bnVsbA==';
  22. });
  23. var WRONG_ARITY = BASIC && $btoa.length !== 1;
  24. // `btoa` method
  25. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa
  26. $({ global: true, bind: true, enumerable: true, forced: !BASIC || NO_ARG_RECEIVING_CHECK || WRONG_ARG_CONVERSION || WRONG_ARITY }, {
  27. btoa: function btoa(data) {
  28. validateArgumentsLength(arguments.length, 1);
  29. // `webpack` dev server bug on IE global methods - use call(fn, global, ...)
  30. if (BASIC) return call($btoa, globalThis, toString(data));
  31. var string = toString(data);
  32. var output = '';
  33. var position = 0;
  34. var map = i2c;
  35. var block, charCode;
  36. while (charAt(string, position) || (map = '=', position % 1)) {
  37. charCode = charCodeAt(string, position += 3 / 4);
  38. if (charCode > 0xFF) {
  39. throw new (getBuiltIn('DOMException'))('The string contains characters outside of the Latin1 range', 'InvalidCharacterError');
  40. }
  41. block = block << 8 | charCode;
  42. output += charAt(map, 63 & block >> 8 - position % 1 * 8);
  43. } return output;
  44. }
  45. });