source: frontend/node_modules/core-js-pure/modules/web.btoa.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.2 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var globalThis = require('../internals/global-this');
4var getBuiltIn = require('../internals/get-built-in');
5var uncurryThis = require('../internals/function-uncurry-this');
6var call = require('../internals/function-call');
7var fails = require('../internals/fails');
8var toString = require('../internals/to-string');
9var validateArgumentsLength = require('../internals/validate-arguments-length');
10var i2c = require('../internals/base64-map').i2c;
11
12var $btoa = getBuiltIn('btoa');
13var $Array = Array;
14var join = uncurryThis([].join);
15var charAt = uncurryThis(''.charAt);
16var charCodeAt = uncurryThis(''.charCodeAt);
17
18var BASIC = !!$btoa && !fails(function () {
19 return $btoa('hi') !== 'aGk=';
20});
21
22var NO_ARG_RECEIVING_CHECK = BASIC && !fails(function () {
23 $btoa();
24});
25
26var WRONG_ARG_CONVERSION = BASIC && fails(function () {
27 return $btoa(null) !== 'bnVsbA==';
28});
29
30var WRONG_ARITY = BASIC && $btoa.length !== 1;
31
32// `btoa` method
33// https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa
34$({ global: true, bind: true, enumerable: true, forced: !BASIC || NO_ARG_RECEIVING_CHECK || WRONG_ARG_CONVERSION || WRONG_ARITY }, {
35 btoa: function btoa(data) {
36 validateArgumentsLength(arguments.length, 1);
37 // `webpack` dev server bug on IE global methods - use call(fn, global, ...)
38 if (BASIC) return call($btoa, globalThis, toString(data));
39 var string = toString(data);
40 // (string.length + 2) / 3) and then truncating to integer
41 // does the ceil automatically. << 2 will truncate the integer
42 // while also doing *4. ceil(length / 3) quanta, 4 bytes output
43 // per quanta for base64.
44 var output = new $Array((string.length + 2) / 3 << 2);
45 var outputIndex = 0;
46 var position = 0;
47 var map = i2c;
48 var block, charCode;
49 while (charAt(string, position) || (map = '=', position % 1)) {
50 charCode = charCodeAt(string, position += 3 / 4);
51 if (charCode > 0xFF) {
52 throw new (getBuiltIn('DOMException'))('The string contains characters outside of the Latin1 range', 'InvalidCharacterError');
53 }
54 block = block << 8 | charCode;
55 output[outputIndex++] = charAt(map, 63 & block >> 8 - position % 1 * 8);
56 } return join(output, '');
57 }
58});
Note: See TracBrowser for help on using the repository browser.