source: frontend/node_modules/core-js-pure/modules/web.atob.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.7 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 c2i = require('../internals/base64-map').c2i;
11
12var disallowed = /[^\d+/a-z]/i;
13var whitespaces = /[\t\n\f\r ]+/g;
14var finalEq = /[=]{1,2}$/;
15
16var $atob = getBuiltIn('atob');
17var $Array = Array;
18var fromCharCode = String.fromCharCode;
19var charAt = uncurryThis(''.charAt);
20var replace = uncurryThis(''.replace);
21var join = uncurryThis([].join);
22var exec = uncurryThis(disallowed.exec);
23
24var BASIC = !!$atob && !fails(function () {
25 return $atob('aGk=') !== 'hi';
26});
27
28var NO_SPACES_IGNORE = BASIC && fails(function () {
29 return $atob(' ') !== '';
30});
31
32var NO_ENCODING_CHECK = BASIC && !fails(function () {
33 $atob('a');
34});
35
36var NO_ARG_RECEIVING_CHECK = BASIC && !fails(function () {
37 $atob();
38});
39
40var WRONG_ARITY = BASIC && $atob.length !== 1;
41
42var FORCED = !BASIC || NO_SPACES_IGNORE || NO_ENCODING_CHECK || NO_ARG_RECEIVING_CHECK || WRONG_ARITY;
43
44// `atob` method
45// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
46$({ global: true, bind: true, enumerable: true, forced: FORCED }, {
47 atob: function atob(data) {
48 validateArgumentsLength(arguments.length, 1);
49 // `webpack` dev server bug on IE global methods - use call(fn, global, ...)
50 if (BASIC && !NO_SPACES_IGNORE && !NO_ENCODING_CHECK) return call($atob, globalThis, data);
51 var string = replace(toString(data), whitespaces, '');
52 var position = 0;
53 var bc = 0;
54 var length, chr, bs;
55 if (!(string.length & 3)) {
56 string = replace(string, finalEq, '');
57 }
58 length = string.length;
59 var lenmod = length & 3;
60 if (lenmod === 1 || exec(disallowed, string)) {
61 throw new (getBuiltIn('DOMException'))('The string is not correctly encoded', 'InvalidCharacterError');
62 }
63 // (length >> 2) is equivalent for length / 4 floored; * 3 then multiplies the
64 // number of bytes for full quanta
65 // lenmod is length % 4; if there's 2 or 3 bytes it's 1 or 2 bytes of extra output
66 // respectively, so -1, however use a ternary to ensure 0 does not get -1 onto length
67 var output = new $Array((length >> 2) * 3 + (lenmod ? lenmod - 1 : 0));
68 var outputIndex = 0;
69 while (position < length) {
70 chr = charAt(string, position++);
71 bs = bc & 3 ? (bs << 6) + c2i[chr] : c2i[chr];
72 if (bc++ & 3) output[outputIndex++] = fromCharCode(255 & bs >> (-2 * bc & 6));
73 }
74 return join(output, '');
75 }
76});
Note: See TracBrowser for help on using the repository browser.