securityos/node_modules/byte-data/dist/byte-data.js

18 lines
7.0 KiB
JavaScript

/*! https://github.com/rochars/byte-data
Copyright (c) 2019 Rafael da Silva Rocha */
!function(){if(!Object.defineProperty||!function(){try{return Object.defineProperty({},"x",{}),!0}catch(e){return!1}}()){var e=Object.defineProperty;Object.defineProperty=function(t,r,o){if(e)try{return e(t,r,o)}catch(e){}if(t!==Object(t))throw TypeError("Object.defineProperty called on non-object");return Object.prototype.__defineGetter__&&"get"in o&&Object.prototype.__defineGetter__.call(t,r,o.get),Object.prototype.__defineSetter__&&"set"in o&&Object.prototype.__defineSetter__.call(t,r,o.set),"value"in o&&(t[r]=o.value),t}}}();try{Object.getOwnPropertyDescriptor({t:"o"},"t")}catch(e){Object.getOwnPropertyDescriptor=function(e,t){return null!=("function"==typeof e.__lookupGetter__&&"function"==typeof e.__lookupSetter__?e.__lookupGetter__(t)||e.__lookupSetter__(t):null)?{configurable:!0,enumerable:!0,get:e.__lookupGetter__(t),set:e.__lookupSetter__(t)}:{configurable:!0,writable:!0,enumerable:!0,value:e[t]}}};var byteData=(function(exports){var exports=exports||{};var l="function"==typeof Object.defineProperties?Object.defineProperty:function(b,a,d){b!=Array.prototype&&b!=Object.prototype&&(b[a]=d.value)},n="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function p(b,a){if(a){for(var d=n,c=b.split("."),e=0;e<c.length-1;e++){var f=c[e];f in d||(d[f]={});d=d[f]}c=c[c.length-1];e=d[c];f=a(e);f!=e&&null!=f&&l(d,c,{configurable:!0,writable:!0,value:f})}}
p("String.prototype.codePointAt",function(b){return b?b:function(a){if(null==this)throw new TypeError("The 'this' value for String.prototype.codePointAt must not be null or undefined");var d=this.length;a=Number(a)||0;if(0<=a&&a<d){a|=0;var c=this.charCodeAt(a);if(55296>c||56319<c||a+1===d)return c;a=this.charCodeAt(a+1);return 56320>a||57343<a?c:1024*(c-55296)+a+9216}}});Object.defineProperty(exports,"__esModule",{value:!0});
function q(b,a,d,c){c=void 0===c?b.length:c;if(c%a)throw Error("Bad buffer length.");for(d=void 0===d?0:d;d<c;d+=a){var e=b,f=a,h=d;f--;for(var g=0;g<f;g++){var k=e[h+g];e[h+g]=e[h+f];e[h+f]=k;f--}}}function r(b,a,d){d=void 0===d?0:d;for(var c=0,e=b.length;c<e;c++){var f=b.codePointAt(c);if(128>f)a[d]=f,d++;else{var h=0,g=0;2047>=f?(h=1,g=192):65535>=f?(h=2,g=224):1114111>=f&&(h=3,g=240,c++);a[d]=(f>>6*h)+g;for(d++;0<h;)a[d]=128|f>>6*(h-1)&63,d++,h--}}return d}
function t(b,a,d){this.bits=b;this.b=8>b?1:Math.ceil(b/8);this.max=Math.pow(2,b)-1;this.min=0;var c=8-((b-1|7)+1-b);this.c=Math.pow(2,0<c?c:8)-1;this.unpack=this.h;if(void 0===a?0:a)this.max=Math.pow(2,b)/2-1,this.min=-this.max-1,this.unpack=this.g;if(void 0===d?0:d)this.a=this.f}
t.prototype.pack=function(b,a,d){d=void 0===d?0:d;if(a!==a||a.constructor!=Number)throw new TypeError;a=this.a(a);b[d]=(0>a?a+Math.pow(2,this.bits):a)&255;d++;for(var c=2,e=this.b;c<e;c++)b[d]=Math.floor(a/Math.pow(2,8*(c-1)))&255,d++;8<this.bits&&(b[d]=Math.floor(a/Math.pow(2,8*(this.b-1)))&this.c,d++);return d};function u(b,a,d){d=void 0===d?0:d;for(var c=0,e=0;e<b.b;e++)c+=a[d+e]*Math.pow(256,e);return c}t.prototype.h=function(b,a){return this.a(u(this,b,void 0===a?0:a))};
t.prototype.g=function(b,a){var d=u(this,b,void 0===a?0:a);d>this.max&&(d-=2*this.max+2);return this.a(d)};t.prototype.a=function(b){if(b>this.max||b<this.min)throw new RangeError;return b};t.prototype.f=function(b){return b>this.max?this.max:b<this.min?this.min:b};function v(b,a){this.b=b;this.c=a;this.a=(1<<b-1)-1;this.f=Math.ceil((b+a)/8);this.g=Math.pow(2,this.a+1);this.h=b+a;this.i=Math.pow(2,-(8*this.f-1-b))}
v.prototype.pack=function(b,a,d){if("number"!=typeof a)throw new TypeError;Math.abs(a)>this.g-2*this.h&&(a=0>a?-Infinity:Infinity);var c=0>((a=+a)||1/a)?1:0>a?1:0;a=Math.abs(a);var e=Math.min(Math.floor(Math.log(a)/Math.LN2),1023),f=w(a/Math.pow(2,e)*Math.pow(2,this.c));a!==a?(f=Math.pow(2,this.c-1),e=(1<<this.b)-1):0!==a&&(a>=Math.pow(2,1-this.a)?(2<=f/Math.pow(2,this.c)&&(e+=1,f=1),e>this.a?(e=(1<<this.b)-1,f=0):(e+=this.a,f=w(f)-Math.pow(2,this.c))):(f=w(a/Math.pow(2,1-this.a-this.c)),e=0));a=
[];a.push(c);for(c=this.b;0<c;--c)a[c]=e%2?1:0,e=Math.floor(e/2);c=a.length;for(e=this.c;0<e;--e)a[c+e]=f%2?1:0,f=Math.floor(f/2);c=a.join("");f=this.f+d-1;for(a=d;f>=d;)b[f]=parseInt(c.substring(0,8),2),c=c.substring(8),f--,a++;return a};
v.prototype.unpack=function(b,a){for(var d=(1<<this.b)-1,c="",e=this.f-1;0<=e;e--){var f=b[e+a].toString(2);c+="00000000".substring(f.length)+f}e="1"==c.charAt(0)?-1:1;c=c.substring(1);f=parseInt(c.substring(0,this.b),2);c=c.substring(this.b);if(f==d)return 0!==parseInt(c,2)?NaN:Infinity*e;0===f?(f+=1,d=parseInt(c,2)):d=parseInt("1"+c,2);return e*d*this.i*Math.pow(2,f-this.a)};function w(b){var a=Math.floor(b);b-=a;return.5>b?a:.5<b?a+1:a%2?a+1:a}
function x(b,a,d,c,e){c=void 0===c?0:c;a=a||{};e=y(a.bits,a.fp,a.signed,void 0===e?!1:e);var f=Math.ceil(a.bits/8),h=0,g=c;try{for(var k=b.length;h<k;h++)c=e.pack(d,b[h],c);a.be&&q(d,f,g,c)}catch(m){z(m,b[h],h)}return c}
function A(b,a,d,c,e,f,h){c=void 0===c?0:c;e=void 0===e?b.length:e;f=void 0===f?!1:f;a=a||{};h=y(a.bits,a.fp,a.signed,void 0===h?!1:h);var g=Math.ceil(a.bits/8),k=(e-c)%g;if(f&&(k||b.length<g))throw Error("Bad buffer length");e-=k;f=0;k=c;try{for(a.be&&q(b,g,c,e);k<e;k+=g,f++)d[f]=h.unpack(b,k);a.be&&q(b,g,c,e)}catch(m){z(m,b.slice(k,k+g),k)}}function B(b,a,d,c,e){return x([b],a,d,void 0===c?0:c,void 0===e?!1:e)}
function C(b,a,d,c,e,f){c=void 0===c?b.length:c;var h=[];A(b,a,h,void 0===d?0:d,c,void 0===e?!1:e,void 0===f?!1:f);return h}function z(b,a,d){b.message=b.constructor.name+" at index "+d+": "+a;throw b;}function y(b,a,d,c){if(a){if(!b||16!==b&&32!==b&&64!==b)throw Error("Unsupported type: float, bits: "+b);}else if(!b||1>b||53<b)throw Error("Unsupported type: int, bits: "+b);return a&&16===b?new v(5,11):a&&32==b?new v(8,23):a&&64==b?new v(11,52):new t(b,d,c)}
exports.pack=function(b,a,d){var c=[];B(b,a,c,0,void 0===d?!1:d);return c};exports.packArray=function(b,a,d){var c=[];x(b,a,c,0,void 0===d?!1:d);return c};exports.packArrayTo=x;exports.packString=function(b){var a=[];r(b,a,0);return a};exports.packStringTo=function(b,a,d){return r(b,a,void 0===d?0:d)};exports.packTo=B;exports.unpack=function(b,a,d,c){d=void 0===d?0:d;return C(b,a,d,d+Math.ceil(a.bits/8),!0,void 0===c?!1:c)[0]};exports.unpackArray=C;exports.unpackArrayTo=A;
exports.unpackString=function(b,a,d){d=void 0===d?b.length:d;var c=void 0===a?0:a;d=void 0===d?b.length:d;a="";for(c=void 0===c?0:c;c<d;){var e=128,f=191,h=!1,g=b[c++];if(0<=g&&127>=g)a+=String.fromCharCode(g);else{var k=0;194<=g&&223>=g?k=1:224<=g&&239>=g?(k=2,224===b[c]&&(e=160),237===b[c]&&(f=159)):240<=g&&244>=g?(k=3,240===b[c]&&(e=144),244===b[c]&&(f=143)):h=!0;g&=(1<<8-k-1)-1;for(var m=0;m<k;m++){if(b[c]<e||b[c]>f)h=!0;g=g<<6|b[c]&63;c++}h?a+=String.fromCharCode(65533):65535>=g?a+=String.fromCharCode(g):
(g-=65536,a+=String.fromCharCode((g>>10&1023)+55296,(g&1023)+56320))}}return a};typeof module!=='undefined'?module.exports=exports :typeof define==='function'&&define.amd?define(['exports'],exports) :typeof global!=='undefined'?global.byteData=exports:null;return exports;})();