jbase62/dist/jbase62.js

11 lines
34 KiB
JavaScript
Raw Normal View History

2023-04-20 11:14:04 +08:00
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("_")):"function"==typeof define&&define.amd?define(["_"],r):"object"==typeof exports?exports.JBase62=r(require("_")):t.JBase62=r(t._)}(window,(function(t){return function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)e.d(n,o,function(r){return t[r]}.bind(null,o));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=4)}([function(r,e){r.exports=t},function(t,r,e){var n;e(10),void 0===(n=function(){var t=function(t){return"string"!=typeof t?t:t.replace(/[\+ \|\^\%]/g,(function(t){return{" ":"+","+":"%2B","|":"%7C","^":"%5E","%":"%25"}[t]}))},r=function(t){return"string"!=typeof t?t:t.replace(/\+|%2B|%7C|%5E|%25/g,(function(t){return{"+":" ","%2B":"+","%7C":"|","%5E":"^","%25":"%"}[t]}))},e=function(t){return Number.prototype.toString.call(t,36).toUpperCase()},n=function(t){return parseInt(t,36)},o=Array.prototype.indexOf||function(t,r){for(var e=r||0,n=this.length;e<n;e++)if(this[e]===t)return e;return-1};return{JSON:JSON,pack:function(r,n){var i=(n=n||{}).verbose||!1;i&&console.log("Normalize the JSON Object"),r="string"==typeof r?this.JSON.parse(r):r,i&&console.log("Creating a empty dictionary");var u={strings:[],integers:[],floats:[]};i&&console.log("Creating the AST");var f=function r(n){i&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(n));var f,a=typeof n;if(null===n)return{type:"null",index:-3};if(void 0===n)return{type:"undefined",index:-5};if(n instanceof Array){var s=["@"];for(var h in n)n.hasOwnProperty(h)&&s.push(r(n[h]));return s}if("object"===a){for(var c in s=["$"],n)n.hasOwnProperty(c)&&(s.push(r(c)),s.push(r(n[c])));return s}if(""===n)return{type:"empty",index:-4};if("string"===a)return-1==(f=o.call(u.strings,n))&&(u.strings.push(t(n)),f=u.strings.length-1),{type:"strings",index:f};if("number"===a&&n%1==0)return-1==(f=o.call(u.integers,n))&&(u.integers.push(e(n)),f=u.integers.length-1),{type:"integers",index:f};if("number"===a)return-1==(f=o.call(u.floats,n))&&(u.floats.push(n),f=u.floats.length-1),{type:"floats",index:f};if("boolean"===a)return{type:"boolean",index:n?-1:-2};throw new Error("Unexpected argument of type "+typeof n)}(r),a=u.strings.length,s=u.integers.length;u.floats.length,i&&console.log("Parsing the dictionary");var h=u.strings.join("|");return h+="^"+u.integers.join("|"),h+="^"+u.floats.join("|"),i&&console.log("Parsing the structure"),h+="^"+function t(r){if(i&&console.log("Calling a recursiveParser with "+this.JSON.stringify(r)),r instanceof Array){var n=r.shift();for(var o in r)r.hasOwnProperty(o)&&(n+=t(r[o])+"|");return("|"===n[n.length-1]?n.slice(0,-1):n)+"]"}var u=r.type,f=r.index;if("strings"===u)return e(f);if("integers"===u)return e(a+f);if("floats"===u)return e(a+s+f);if("boolean"===u)return r.index;if("null"===u)return-3;if("undefined"===u)return-5;if("empty"===u)return-4;throw new TypeError("The item is alien!")}(f),i&&console.log("Ending parser"),n.debug?{dictionary:u,ast:f,packed:h}:h},unpack:function(t,e){e=e||{};var o=t.split("^");e.verbose&&console.log("Building dictionary");var i=[],u=o[0];if(""!==u){u=u.split("|"),e.verbose&&console.log("Parse the strings dictionary");for(var f=0,a=u.length;f<a;f++)i.push(r(u[f]))}if(""!==(u=o[1]))for(u=u.split("|"),e.verbose&&console.log("Parse the integers dictionary"),f=0,a=u.len
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/
var n=e(7),o=e(8),i=e(9);function u(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,r){if(u()<r)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(r)).__proto__=a.prototype:(null===t&&(t=new a(r)),t.length=r),t}function a(t,r,e){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(t,r,e);if("number"==typeof t){if("string"==typeof r)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return s(this,t,r,e)}function s(t,r,e,n){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&r instanceof ArrayBuffer?function(t,r,e,n){if(r.byteLength,e<0||r.byteLength<e)throw new RangeError("'offset' is out of bounds");if(r.byteLength<e+(n||0))throw new RangeError("'length' is out of bounds");r=void 0===e&&void 0===n?new Uint8Array(r):void 0===n?new Uint8Array(r,e):new Uint8Array(r,e,n);a.TYPED_ARRAY_SUPPORT?(t=r).__proto__=a.prototype:t=l(t,r);return t}(t,r,e,n):"string"==typeof r?function(t,r,e){"string"==typeof e&&""!==e||(e="utf8");if(!a.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var n=0|g(r,e),o=(t=f(t,n)).write(r,e);o!==n&&(t=t.slice(0,o));return t}(t,r,e):function(t,r){if(a.isBuffer(r)){var e=0|p(r.length);return 0===(t=f(t,e)).length||r.copy(t,0,0,e),t}if(r){if("undefined"!=typeof ArrayBuffer&&r.buffer instanceof ArrayBuffer||"length"in r)return"number"!=typeof r.length||(n=r.length)!=n?f(t,0):l(t,r);if("Buffer"===r.type&&i(r.data))return l(t,r.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,r)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,r){if(h(r),t=f(t,r<0?0:0|p(r)),!a.TYPED_ARRAY_SUPPORT)for(var e=0;e<r;++e)t[e]=0;return t}function l(t,r){var e=r.length<0?0:0|p(r.length);t=f(t,e);for(var n=0;n<e;n+=1)t[n]=255&r[n];return t}function p(t){if(t>=u())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u().toString(16)+" bytes");return 0|t}function g(t,r){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return J(t).length;default:if(n)return D(t).length;r=(""+r).toLowerCase(),n=!0}}function y(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return O(this,r,e);case"utf8":case"utf-8":return S(this,r,e);case"ascii":return T(this,r,e);case"latin1":case"binary":return B(this,r,e);case"base64":return R(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function d(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function v(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=a.from(r,n)),a.isBuffer(r))return 0===r.length?-1:w(t,r,e,n,o);if("number"==typeof r)return r&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):w(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function w(t,r,e,n,o){var i,u=1,f=t.length,a=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
r.read=function(t,r,e,n,o){var i,u,f=8*o-n-1,a=(1<<f)-1,s=a>>1,h=-7,c=e?o-1:0,l=e?-1:1,p=t[r+c];for(c+=l,i=p&(1<<-h)-1,p>>=-h,h+=f;h>0;i=256*i+t[r+c],c+=l,h-=8);for(u=i&(1<<-h)-1,i>>=-h,h+=n;h>0;u=256*u+t[r+c],c+=l,h-=8);if(0===i)i=1-s;else{if(i===a)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=s}return(p?-1:1)*u*Math.pow(2,i-n)},r.write=function(t,r,e,n,o,i){var u,f,a,s=8*i-o-1,h=(1<<s)-1,c=h>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,y=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(f=isNaN(r)?1:0,u=h):(u=Math.floor(Math.log(r)/Math.LN2),r*(a=Math.pow(2,-u))<1&&(u--,a*=2),(r+=u+c>=1?l/a:l*Math.pow(2,1-c))*a>=2&&(u++,a/=2),u+c>=h?(f=0,u=h):u+c>=1?(f=(r*a-1)*Math.pow(2,o),u+=c):(f=r*Math.pow(2,c-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&f,p+=g,f/=256,o-=8);for(u=u<<o|f,s+=o;s>0;t[e+p]=255&u,p+=g,u/=256,s-=8);t[e+p-g]|=128*y}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r){t.exports=function(){throw new Error("define cannot be used indirect")}}]).default}));
//# sourceMappingURL=jbase62.js.map