source: imaps-frontend/node_modules/core-js/modules/esnext.uint8-array.to-base64.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var globalThis = require('../internals/global-this');
4var uncurryThis = require('../internals/function-uncurry-this');
5var anObjectOrUndefined = require('../internals/an-object-or-undefined');
6var anUint8Array = require('../internals/an-uint8-array');
7var notDetached = require('../internals/array-buffer-not-detached');
8var base64Map = require('../internals/base64-map');
9var getAlphabetOption = require('../internals/get-alphabet-option');
10
11var base64Alphabet = base64Map.i2c;
12var base64UrlAlphabet = base64Map.i2cUrl;
13
14var charAt = uncurryThis(''.charAt);
15
16// `Uint8Array.prototype.toBase64` method
17// https://github.com/tc39/proposal-arraybuffer-base64
18if (globalThis.Uint8Array) $({ target: 'Uint8Array', proto: true }, {
19 toBase64: function toBase64(/* options */) {
20 var array = anUint8Array(this);
21 var options = arguments.length ? anObjectOrUndefined(arguments[0]) : undefined;
22 var alphabet = getAlphabetOption(options) === 'base64' ? base64Alphabet : base64UrlAlphabet;
23 var omitPadding = !!options && !!options.omitPadding;
24 notDetached(this.buffer);
25
26 var result = '';
27 var i = 0;
28 var length = array.length;
29 var triplet;
30
31 var at = function (shift) {
32 return charAt(alphabet, (triplet >> (6 * shift)) & 63);
33 };
34
35 for (; i + 2 < length; i += 3) {
36 triplet = (array[i] << 16) + (array[i + 1] << 8) + array[i + 2];
37 result += at(3) + at(2) + at(1) + at(0);
38 }
39 if (i + 2 === length) {
40 triplet = (array[i] << 16) + (array[i + 1] << 8);
41 result += at(3) + at(2) + at(1) + (omitPadding ? '' : '=');
42 } else if (i + 1 === length) {
43 triplet = array[i] << 16;
44 result += at(3) + at(2) + (omitPadding ? '' : '==');
45 }
46
47 return result;
48 }
49});
Note: See TracBrowser for help on using the repository browser.