-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring-encode.min.js
2 lines (2 loc) · 2.56 KB
/
string-encode.min.js
1
2
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).stringEncode={})}(this,(function(n){"use strict";var t=String.fromCharCode;function e(n){return n=o(n),t.apply(String,n)}function r(n){var t=n.BYTES_PER_ELEMENT<<1;return n.reduce((function(n,e){return n+(e>>>0).toString(16).padStart(t,"0")}),"")}function i(n,t){if("string"==typeof n)return n;if(n=e(n),!1!==t&&!l(n))if(t)n=g(n);else if(null==t)try{n=g(n)}catch(n){}return n}var u,f=/[^0-9a-f]/g;function o(n,t,e){return!t&&!e&&n instanceof Uint8Array&&!n.copy?n:(t>>>=0,null==e&&(e=n.byteLength-t),new Uint8Array(n.buffer,n.byteOffset+t,e))}function c(){return void 0!==u||(u=!!new Uint8Array(new Uint16Array([1]).buffer)[0],c=function(){return u}),u}var a=/([^\x00-\xFF])/,s=/^[0-9a-f\s]*$/i,x=/^[\x00-\x7F]*$/,d=/^(?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF][\x80-\xBF]|[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])*$/;function h(n){var t=a.exec(n);return!!t&&t[1]}function l(n){return x.test(n)}function y(n){return s.test(n)}function b(n,t){for(var e,r=n.length,i=0,u=0,f=-1,o=+!!t;i<r;)if(!((e=n.charCodeAt(i++))<128)){if(255<=e)return!1;if(128==(192&e)){if(o==i){++u,++o;continue}return!1}if(!(f=192!=(224&e)?224!=(240&e)?240==(248&e)&&3:2:1))return!1;for(;(u+=1)&&f--&&i<r;)if(128!=(192&(e=n.charCodeAt(i++))))return!1}return!(~f&&!t)&&u}function p(n){return unescape(encodeURI(n))}function g(n){return decodeURIComponent(escape(n))}n.buffer2bin=e,n.buffer2hex=r,n.buffer2str=i,n.chr=t,n.guessEncoding=function(n){if(h(n))return"mb";if(y(n))return"hex";var t=b(n);return t?"utf8":0===t?"ascii":!1===t&&(t=b(n,!0))?"~utf8":"binary"},n.hasMultibyte=h,n.hex2buffer=function(n){for(var t=(n=n.replace(f,"")).length,e=new Uint8Array(t+1>>>1),r=0;r<t;r+=2)e[r>>>1]=parseInt(n.slice(r,r+2),16);return e},n.isASCII=l,n.isBinary=function(n){return!h(n)},n.isHEX=y,n.isLittleEndian=c,n.isUTF8=function(n){return d.test(n)},n.ord=function(n){return n.charCodeAt(0)},n.str2buffer=function(n,t){n=String(n),null==t&&(t=h(n)),t&&(n=p(n));for(var e=n.length,r=new Uint8Array(e);e--;)r[e]=n.charCodeAt(e);return r},n.switchEndianness32=function(n){return(255&n)<<24|(65280&n)<<8|n>>8&65280|n>>24&255},n.toString=function(n){switch(n){case!1:case"binary":return e(this);case"hex":return r(this);case"base64":return btoa(e(this));case"utf8":n=!0}return i(this,n)},n.utf8Decode=g,n.utf8Encode=p,n.utf8bytes=b,n.view8=o,Object.defineProperty(n,"__esModule",{value:!0})}));
//# sourceMappingURL=string-encode.min.js.map