UNPKG

utf8-buffer

Version:

ES6 module to encode and decode UTF-8 strings.

8 lines (7 loc) 2.44 kB
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,b,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1; $jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this); $jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var h=a[d];h in c||(c[h]={});c=c[h]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}}; $jscomp.polyfill("String.prototype.codePointAt",function(a){return a?a:function(b){var c=$jscomp.checkStringArgs(this,null,"codePointAt"),a=c.length;b=Number(b)||0;if(0<=b&&b<a){b|=0;var h=c.charCodeAt(b);if(55296>h||56319<h||b+1===a)return h;b=c.charCodeAt(b+1);return 56320>b||57343<b?h:1024*(h-55296)+b+9216}}},"es6","es3"); (function(a,b){"object"===typeof exports&&"undefined"!==typeof module?b(exports):"function"===typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.UTF8Buffer={}))})(this,function(a){a.pack=function(b,a,d){d=void 0===d?0:d;for(var c=0,k=b.length;c<k;c++){var f=b.codePointAt(c);if(128>f)a[d]=f,d++;else{var g=0,e=0;2047>=f?(g=1,e=192):65535>=f?(g=2,e=224):1114111>=f&&(g=3,e=240,c++);a[d]=(f>>6*g)+e;for(d++;0<g;)a[d]=128|f>>6*(g-1)&63,d++,g--}}return d};a.unpack=function(b,a,d){d=void 0===d? b.length:d;var c="";for(a=void 0===a?0:a;a<d;){var k=128,f=191,g=!1,e=b[a++];if(0<=e&&127>=e)c+=String.fromCharCode(e);else{var l=0;194<=e&&223>=e?l=1:224<=e&&239>=e?(l=2,224===b[a]&&(k=160),237===b[a]&&(f=159)):240<=e&&244>=e?(l=3,240===b[a]&&(k=144),244===b[a]&&(f=143)):g=!0;e&=(1<<8-l-1)-1;for(var m=0;m<l;m++){if(b[a]<k||b[a]>f)g=!0;e=e<<6|b[a]&63;a++}g?c+=String.fromCharCode(65533):65535>=e?c+=String.fromCharCode(e):(e-=65536,c+=String.fromCharCode((e>>10&1023)+55296,(e&1023)+56320))}}return c}; Object.defineProperty(a,"__esModule",{value:!0})});