Files
lmbtfy/js/base64.min.js

10 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

/*
* base64.js
*
* Licensed under the BSD 3-Clause License.
* http://opensource.org/licenses/BSD-3-Clause
*
* References:
* http://en.wikipedia.org/wiki/Base64
*/
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b(a):"function"==typeof define&&define.amd?define(b):b(a)}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this,function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;return a=a||{},b=a.Base64,c="2.6.1",d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=function(a){var c,d,b={};for(c=0,d=a.length;d>c;c++)b[a.charAt(c)]=c;return b}(d),f=String.fromCharCode,g=function(a){var b;return a.length<2?(b=a.charCodeAt(0),128>b?a:2048>b?f(192|b>>>6)+f(128|63&b):f(224|15&b>>>12)+f(128|63&b>>>6)+f(128|63&b)):(b=65536+1024*(a.charCodeAt(0)-55296)+(a.charCodeAt(1)-56320),f(240|7&b>>>18)+f(128|63&b>>>12)+f(128|63&b>>>6)+f(128|63&b))},h=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,i=function(a){return a.replace(h,g)},j=function(a){var b=[0,2,1][a.length%3],c=a.charCodeAt(0)<<16|(a.length>1?a.charCodeAt(1):0)<<8|(a.length>2?a.charCodeAt(2):0),e=[d.charAt(c>>>18),d.charAt(63&c>>>12),b>=2?"=":d.charAt(63&c>>>6),b>=1?"=":d.charAt(63&c)];return e.join("")},k=a.btoa&&"function"==typeof a.btoa?function(b){return a.btoa(b)}:function(a){if(a.match(/[^\x00-\xFF]/))throw new RangeError("The string contains invalid characters.");return a.replace(/[\s\S]{1,3}/g,j)},l=function(a){return k(i(String(a)))},m=function(a,b){return b?l(String(a)).replace(/[+\/]/g,function(a){return"+"==a?"-":"_"}).replace(/=/g,""):l(String(a))},n=function(a){return m(a,!0)},o=function(a){return k(Array.from(a,function(a){return String.fromCharCode(a)}).join(""))},p=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,q=function(a){switch(a.length){case 4:var b=(7&a.charCodeAt(0))<<18|(63&a.charCodeAt(1))<<12|(63&a.charCodeAt(2))<<6|63&a.charCodeAt(3),c=b-65536;return f((c>>>10)+55296)+f((1023&c)+56320);case 3:return f((15&a.charCodeAt(0))<<12|(63&a.charCodeAt(1))<<6|63&a.charCodeAt(2));default:return f((31&a.charCodeAt(0))<<6|63&a.charCodeAt(1))}},r=function(a){return a.replace(p,q)},s=function(a){var b=a.length,c=b%4,d=(b>0?e[a.charAt(0)]<<18:0)|(b>1?e[a.charAt(1)]<<12:0)|(b>2?e[a.charAt(2)]<<6:0)|(b>3?e[a.charAt(3)]:0),g=[f(d>>>16),f(255&d>>>8),f(255&d)];return g.length-=[0,0,2,1][c],g.join("")},t=a.atob&&"function"==typeof a.atob?function(b){return a.atob(b)}:function(a){return a.replace(/\S{1,4}/g,s)},u=function(a){return t(String(a).replace(/[^A-Za-z0-9\+\/]/g,""))},v=function(a){return r(t(a))},w=function(a){return v(String(a).replace(/[-_]/g,function(a){return"-"==a?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))},x=function(a){return Uint8Array.from(u(a),function(a){return a.charCodeAt(0)})},y=function(){var c=a.Base64;return a.Base64=b,c},a.Base64={VERSION:c,atob:u,btoa:k,fromBase64:w,toBase64:m,utob:i,encode:m,encodeURI:n,btou:r,decode:w,noConflict:y,fromUint8Array:o,toUint8Array:x},"function"==typeof Object.defineProperty&&(z=function(a){return{value:a,enumerable:!1,writable:!0,configurable:!0}},a.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",z(function(){return w(this)})),Object.defineProperty(String.prototype,"toBase64",z(function(a){return m(this,a)})),Object.defineProperty(String.prototype,"toBase64URI",z(function(){return m(this,!0)}))}),a["Meteor"]&&(Base64=a.Base64),"undefined"!=typeof module&&module.exports?module.exports.Base64=a.Base64:"function"==typeof define&&define.amd&&define([],function(){return a.Base64}),{Base64:a.Base64}});