a-calc 0.0.54 → 0.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/browser/index.core.js +1 -1
- package/browser/index.html +9 -22
- package/browser/index.js +1 -1
- package/cjs/index.js +1 -1
- package/es/index.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -43,8 +43,6 @@ const {calc, fmt} = a_calc
|
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
45
|
calc("0.1 + 0.2") // 0.3
|
|
46
|
-
calc`0.1 + 0.2` // 0.3
|
|
47
|
-
// 以上方式等价
|
|
48
46
|
|
|
49
47
|
// 复杂一点的计算
|
|
50
48
|
calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // 0.265
|
|
@@ -56,6 +54,19 @@ calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // 0.265
|
|
|
56
54
|
let a = 0.000001
|
|
57
55
|
let b = 888.789
|
|
58
56
|
calc("a + b", {a,b}) // 0.000001 + 888.789 = 888.789001
|
|
57
|
+
|
|
58
|
+
calc("a * (b + c) % d + 7.123", [
|
|
59
|
+
{a: 1, b: 2},
|
|
60
|
+
{c: 3, d: 4}
|
|
61
|
+
]) // 8.123
|
|
62
|
+
|
|
63
|
+
// 复杂一点的
|
|
64
|
+
calc("1 + o.a / arr[0].d",
|
|
65
|
+
{
|
|
66
|
+
o: { a: 2 },
|
|
67
|
+
arr: [{ d: 8 }]
|
|
68
|
+
}
|
|
69
|
+
) // 1.25
|
|
59
70
|
```
|
|
60
71
|
|
|
61
72
|
## Calculate & Format (计算并格式化)
|
package/browser/index.core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a_calc=function(r){"use strict";function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var u=t(BigNumber);function o(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function n(r,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function i(r,t,e){return t&&n(r.prototype,t),e&&n(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function a(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&f(r,t)}function l(r){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function f(r,t){return(f=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function s(r,t,e){return(s=c()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);t=new(Function.bind.apply(r,n));return e&&f(t,e.prototype),t}).apply(null,arguments)}function p(r){var e="function"==typeof Map?new Map:void 0;return(p=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return s(r,arguments,l(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),f(t,r)})(r)}function h(r,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");t=r;if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(e){var n=c();return function(){var r,t=l(e);return h(this,n?(r=l(this).constructor,Reflect.construct(t,arguments,r)):t.apply(this,arguments))}}function y(r){return function(r){if(Array.isArray(r))return v(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||function(r,t){if(r){if("string"==typeof r)return v(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(e="Object"===e&&r.constructor?r.constructor.name:e)||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?v(r,t):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function g(r){return-1<"+-*/%()".indexOf(r)}function w(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function b(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return t.some(function(r){return void 0!==r})}function _(r){var t={expr:"",fmt:null,data:null},e="",n=r[0];if(1===r.length)"string"==typeof n?e=n:"number"==typeof n?e=n.toString():Array.isArray(n)&&(e=n[0]);else if(1<r.length){n=r[r.length-1];if(l=n,"[object Object]"!==Object.prototype.toString.call(l)||Array.isArray(l))for(var o=y(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),e=e+i+(a="number"==typeof a?a.toString():a);else e=r[0],t.data=n}var l=e.split("|");return 1===l.length?t.expr=l[0]:(t.expr=l[0],""!==(n=l[1]).trim()&&(t.fmt=n)),t}function m(r,t){var e="",n=(e=u.default.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=t.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),t.includes(",")&&(o=!0),null!==n){var i=e.split("."),t=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}e=""===a?t:"".concat(t,".").concat(a)}return e=null!==o?1<(i=e.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(t=i[0]).includes("-")?t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):t.replace(/(?=(?!^)(?:\d{3})+$)/g,","):e}function A(r){for(var t=[],e=0,n=null,o=r.length;e<o;)if(n=r[e],/\s/.test(n))e++;else if("+-".includes(n)){var i=t[t.length-1];if(0===t.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++e];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++e];t.push(a)}else t.push(n),e++}else if("*/%()".includes(n))t.push(n),e++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++e>=o));)n=r[e];t.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++e>=o));)n=r[e];t.push(u)}return t}var E=function(){a(n,p(Error));var e=d(n);function n(r){var t;return o(this,n),(t=e.call(this,r)).name="CalculatorError",t.message=r,t}return i(n)}(),O=function(){a(n,p(Error));var e=d(n);function n(r){var t;return o(this,n),(t=e.call(this,r)).name="TokensFillError",t.message=r,t}return i(n)}();function j(r,t){for(var e=t._fillData,n=(void 0===t._fillData&&(e=t),Array.isArray(e)||(e=[e]),[]),o=0;o<r.length;o++){var i=r[o];if(/^[a-zA-z_][\w_]*$/.test(i)){if("undefined"===i||"NaN"===i)throw new O("key不应该为:".concat(i));for(var a=null,l=0;l<e.length;l++){var u=e[l];if(void 0!==u[i]){a=u[i];break}}if(null===a)throw new O("token填充失败,请确认".concat(i,"存在"));if("string"==typeof a){if(""===a.trim())throw new O("token填充失败,".concat(i,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(a))throw new O("token填充失败,".concat(i,"值:").concat(a,"为非法数字"))}a="string"!=typeof a?a.toString():a,n.push(a)}else n.push(i)}return n}function x(r){for(var t,e=[],n=[],o=r;0<o.length;){var i=o.shift();if(g(i))if("("===i)e.push(i);else if(")"===i){for(var a=e.pop();"("!==a&&0<e.length;)n.push(a),a=e.pop();if("("!==a)throw"error: unmatched ()"}else{for(;t=e[e.length-1],w(i)<=w(t)&&0<e.length;)n.push(e.pop());e.push(i)}else n.push(i)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)n.push(e.pop())}return n}function k(r){for(var t=[];0<r.length;){var e=r.shift();if(g(e)){if(t.length<2)throw new E("错误的栈长度, 可能是无法计算的表达式");var n=t.pop(),o=t.pop();if("string"==typeof n&&!u.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new E("".concat(n,"不是一个合法的数字"));n=new u.default(n)}if("string"==typeof o&&!u.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new E("".concat(o,"不是一个合法的数字"));o=new u.default(o)}switch(e){case"+":t.push(o.plus(n));break;case"-":t.push(o.minus(n));break;case"*":t.push(o.times(n));break;case"/":t.push(o.div(n));break;case"%":t.push(o.mod(n))}}else t.push(e)}if(1!==t.length)throw"unvalid expression";return t[0]}return r.calc=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=_(t),o=A(n.expr),i=null;if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&b(a._fillData,a._error,a._fillError,a._calcError)?a:i)&&void 0!==a._fillData&&b(i._fillError,i._error))try{o=j(o,a._fillData)}catch(r){if(r instanceof O)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=j(o,a)}if(a=x(o),(o=null)!==i){if(void 0!==i._calcError||void 0!==i._error)try{o=k(a)}catch(r){if(r instanceof E)return void 0!==i._warn&&!0===i._warn&&console.warn(r),void 0!==i._calcError?i._calcError:i._error;throw r}}else o=k(a);return o=null!==n.fmt?m(o,n.fmt):null!==o?o.toFixed():null},r.fmt=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];var n=_(t),o=A(n.expr),i=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&b(a._fillData,a._error,a._fillError)?a:i)&&void 0!==a._fillData&&b(i._fillError,i._error))try{o=j(o,a._fillData)}catch(r){if(r instanceof O)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=j(o,a)}if(null===n.fmt)throw"表达式没有格式化部分";if(i=o[0],/^[+-]*[\d.]+$/.test(i))return m(o[0],n.fmt);throw new O("待格式化对象: ".concat(i," 不是数字"))},r.version="0.0.53",Object.defineProperty(r,"__esModule",{value:!0}),r}({});
|
|
1
|
+
var a_calc=function(t){"use strict";function R(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var l=R(BigNumber);function u(t){return-1<"+-*/%()".indexOf(t)}function c(t){switch(t){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function f(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return r.some(function(t){return void 0!==t})}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function i(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function r(t,r,e){return r&&i(t.prototype,r),e&&i(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function a(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&p(t,r)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function p(t,r){return(p=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function v(t,r,e){return(v=h()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);r=new(Function.bind.apply(t,n));return e&&p(r,e.prototype),r}).apply(null,arguments)}function d(t){var e="function"==typeof Map?new Map:void 0;return(d=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return v(t,arguments,s(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),p(r,t)})(t)}function B(t,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");r=t;if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function y(e){var n=h();return function(){var t,r=s(e);return B(this,n?(t=s(this).constructor,Reflect.construct(r,arguments,t)):r.apply(this,arguments))}}var _=function(){a(n,d(Error));var e=y(n);function n(t){var r;return o(this,n),(r=e.call(this,t)).name="CalculatorError",r.message=t,r}return r(n)}(),g=function(){a(n,d(Error));var e=y(n);function n(t){var r;return o(this,n),(r=e.call(this,t)).name="TokensFillError",r.message=t,r}return r(n)}();function b(t){var r={expr:"",fmt:null,data:null},e="",n=t[0];if(1===t.length)"string"==typeof n?e=n:"number"==typeof n?e=n.toString():Array.isArray(n)&&(e=n[0]);else if(1<t.length){n=t[t.length-1];if(o=n,("[object Object]"!==Object.prototype.toString.call(o)||Array.isArray(o))&&!Array.isArray(n))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(e=t[0])){if(""===e.trim())throw new g("参数不可为空字符串")}else if("number"==typeof e)e=e.toString();else if(void 0===e||Number.isNaN(e))throw new g("非法参数:".concat(e));r.data=n}var o=e.split("|");return 1===o.length?r.expr=o[0]:(r.expr=o[0],""!==(t=o[1]).trim()&&(r.fmt=t)),null!==r.data&&null===r.fmt&&r.data._fmt&&(r.fmt=r.data._fmt),r}function w(t,r){var e="",n=(e=l.default.isBigNumber(t)?t.toFixed():"string"!=typeof t?t.toString():t,null),t=null,o=null,i=r.match(/(<=|>=|=)\s*(\d+)/);if(i&&(t=i[1],n=Number(i[2])),r.includes(",")&&(o=!0),null!==n){var i=e.split("."),r=i[0],a=1===i.length?"":i[1],u=a.length;switch(t){case"<=":a=u<=n?a:a.slice(0,n);break;case"=":u<n?a+="0".repeat(n-u):n<u&&(a=a.slice(0,n));break;case">=":a=n<=u?a:a+"0".repeat(n-u)}e=""===a?r:"".concat(r,".").concat(a)}return e=null!==o?1<(i=e.split(".")).length?((t=i[0]).includes("-")?i[0]=t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=t.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(r=i[0]).includes("-")?r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):r.replace(/(?=(?!^)(?:\d{3})+$)/g,","):e}function m(t){for(var r=[],e=0,n=null,o=t.length;e<o;)if(n=t[e],/\s/.test(n))e++;else if("+-".includes(n)){var i=r[r.length-1];if(0===r.length||"+-".includes(i)||"("===i){for(var a=n,n=t[++e];/[a-zA-Z\d._]/.test(n);)a+=n,n=t[++e];r.push(a)}else r.push(n),e++}else if("*/%()".includes(n))r.push(n),e++;else if(/[\w_.\[\]"']/.test(n)){for(var u="";/[\w_.\[\]"']/.test(n)&&(u+=n,!(++e>=o));)n=t[e];r.push(u)}else if(/\d/.test(n)){for(var l="";/[\d.]/.test(n)&&(l+=n,!(++e>=o));)n=t[e];r.push(l)}return r}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},j=Array.isArray,e="object"==n(e)&&e&&e.Object===Object&&e,O="object"==("undefined"==typeof self?"undefined":n(self))&&self&&self.Object===Object&&self,e=e||O||Function("return this")(),O=e.Symbol,E=Object.prototype,C=E.hasOwnProperty,M=E.toString,A=O?O.toStringTag:void 0;var G=Object.prototype.toString;var I=function(t){var r=C.call(t,A),e=t[A];try{var n=!(t[A]=void 0)}catch(t){}var o=M.call(t);return n&&(r?t[A]=e:delete t[A]),o},U=function(t){return G.call(t)},S=O?O.toStringTag:void 0;function Z(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":(S&&S in Object(t)?I:U)(t)}var q=Z,H=function(t){return null!=t&&"object"==n(t)};function x(t){return"symbol"==n(t)||H(t)&&"[object Symbol]"==q(t)}var J=j,K=x,L=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Q=/^\w*$/;function V(t,r){if(J(t))return!1;var e=n(t);return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!K(t))||(Q.test(t)||!L.test(t)||null!=r&&t in Object(r))}function W(t){var r=n(t);return null!=t&&("object"==r||"function"==r)}var X=Z,Y=W;function tt(t){return!!Y(t)&&("[object Function]"==(t=X(t))||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t)}var E=e["__core-js_shared__"],rt=(E=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+E:"";var et=Function.prototype.toString;var nt=tt,ot=function(t){return!!rt&&rt in t},it=W,at=function(t){if(null!=t){try{return et.call(t)}catch(t){}try{return t+""}catch(t){}}return""},ut=/^\[object .+?Constructor\]$/,E=Function.prototype,$=Object.prototype,E=E.toString,$=$.hasOwnProperty,lt=RegExp("^"+E.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var ct=function(t){return!(!it(t)||ot(t))&&(nt(t)?lt:ut).test(at(t))},ft=function(t,r){return null==t?void 0:t[r]};function st(t,r){return t=ft(t,r),ct(t)?t:void 0}var E=st(Object,"create"),pt=E;var ht=E,vt=Object.prototype.hasOwnProperty;var dt=E,yt=Object.prototype.hasOwnProperty;var _t=E;function gt(t){return t=this.has(t)&&delete this.__data__[t],this.size-=t?1:0,t}function bt(t){var r,e=this.__data__;return ht?"__lodash_hash_undefined__"===(r=e[t])?void 0:r:vt.call(e,t)?e[t]:void 0}function wt(t){var r=this.__data__;return dt?void 0!==r[t]:yt.call(r,t)}function mt(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=_t&&void 0===r?"__lodash_hash_undefined__":r,this}function k(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}k.prototype.clear=function(){this.__data__=pt?pt(null):{},this.size=0},k.prototype.delete=gt,k.prototype.get=bt,k.prototype.has=wt,k.prototype.set=mt;$=k;var jt=function(t,r){return t===r||t!=t&&r!=r};function z(t,r){for(var e=t.length;e--;)if(jt(t[e][0],r))return e;return-1}var Ot=z,Et=Array.prototype.splice;var At=z;var St=z;var xt=z;function $t(t){var r=this.__data__;return!((t=Ot(r,t))<0)&&(t==r.length-1?r.pop():Et.call(r,t,1),--this.size,!0)}function kt(t){var r=this.__data__;return(t=At(r,t))<0?void 0:r[t][1]}function zt(t){return-1<St(this.__data__,t)}function Pt(t,r){var e=this.__data__,n=xt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this}function P(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}P.prototype.clear=function(){this.__data__=[],this.size=0},P.prototype.delete=$t,P.prototype.get=kt,P.prototype.has=zt,P.prototype.set=Pt;var E=P,e=st(e,"Map"),Ft=$,Nt=E,Tt=e;var Dt=function(t){var r=n(t);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};function F(t,r){return t=t.__data__,Dt(r)?t["string"==typeof r?"string":"hash"]:t.map}var Rt=F;var Bt=F;var Ct=F;var Mt=F;function Gt(t){return t=Rt(this,t).delete(t),this.size-=t?1:0,t}function It(t){return Bt(this,t).get(t)}function Ut(t){return Ct(this,t).has(t)}function Zt(t,r){var e=Mt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this}function N(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}N.prototype.clear=function(){this.size=0,this.__data__={hash:new Ft,map:new(Tt||Nt),string:new Ft}},N.prototype.delete=Gt,N.prototype.get=It,N.prototype.has=Ut,N.prototype.set=Zt;var qt=N;function T(n,o){if("function"!=typeof n||null!=o&&"function"!=typeof o)throw new TypeError("Expected a function");function i(){var t=arguments,r=o?o.apply(this,t):t[0],e=i.cache;return e.has(r)?e.get(r):(t=n.apply(this,t),i.cache=e.set(r,t)||e,t)}return i.cache=new(T.Cache||qt),i}T.Cache=qt;var Ht=T;var Jt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Kt=/\\(\\)?/g,$=function(t){var r=(t=Ht(t,function(t){return 500===r.size&&r.clear(),t})).cache;return t}(function(t){var o=[];return 46===t.charCodeAt(0)&&o.push(""),t.replace(Jt,function(t,r,e,n){o.push(e?n.replace(Kt,"$1"):r||t)}),o});var Lt=function(t,r){for(var e=-1,n=null==t?0:t.length,o=Array(n);++e<n;)o[e]=r(t[e],e,t);return o},Qt=j,Vt=x,E=O?O.prototype:void 0,Wt=E?E.toString:void 0;var Xt=function t(r){if("string"==typeof r)return r;if(Qt(r))return Lt(r,t)+"";if(Vt(r))return Wt?Wt.call(r):"";var e=r+"";return"0"==e&&1/r==-1/0?"-0":e};var Yt=j,tr=V,rr=$,er=function(t){return null==t?"":Xt(t)};var nr=x;var or=function(t,r){return Yt(t)?t:tr(t,r)?[t]:rr(er(t))},ir=function(t){if("string"==typeof t||nr(t))return t;var r=t+"";return"0"==r&&1/t==-1/0?"-0":r};var ar=function(t,r){for(var e=0,n=(r=or(r,t)).length;null!=t&&e<n;)t=t[ir(r[e++])];return e&&e==n?t:void 0};var ur=function(t,r,e){return void 0===(t=null==t?void 0:ar(t,r))?e:t};function D(t,r){for(var e=r._fillData,n=(void 0===r._fillData&&(e=r),Array.isArray(e)||(e=[e]),[]),o=0;o<t.length;o++){var i=t[o];if(/^[a-zA-z_][\w\[\]"'_.]*$/.test(i)){if("undefined"===i||"NaN"===i)throw new g("key不应该为:".concat(i));for(var a=null,u=0;u<e.length;u++){var l=e[u],l=ur(l,i);if(void 0!==l){a=l;break}}if(null===a)throw new g("token填充失败,请确认".concat(i,"存在"));if("string"==typeof a){if(""===a.trim())throw new g("token填充失败,".concat(i,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(a))throw new g("token填充失败,".concat(i,"值:").concat(a,"为非法数字"))}a="string"!=typeof a?a.toString():a,n.push(a)}else n.push(i)}return n}function lr(t){for(var r,e=[],n=[],o=t;0<o.length;){var i=o.shift();if(u(i))if("("===i)e.push(i);else if(")"===i){for(var a=e.pop();"("!==a&&0<e.length;)n.push(a),a=e.pop();if("("!==a)throw"error: unmatched ()"}else{for(;r=e[e.length-1],c(i)<=c(r)&&0<e.length;)n.push(e.pop());e.push(i)}else n.push(i)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)n.push(e.pop())}return n}function cr(t){for(var r=[];0<t.length;){var e=t.shift();if(u(e)){if(r.length<2)throw new _("错误的栈长度, 可能是无法计算的表达式");var n=r.pop(),o=r.pop();if("string"==typeof n&&!l.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new _("".concat(n,"不是一个合法的数字"));n=new l.default(n)}if("string"==typeof o&&!l.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new _("".concat(o,"不是一个合法的数字"));o=new l.default(o)}switch(e){case"+":r.push(o.plus(n));break;case"-":r.push(o.minus(n));break;case"*":r.push(o.times(n));break;case"/":r.push(o.div(n));break;case"%":r.push(o.mod(n))}}else r.push(e)}if(1!==r.length)throw"unvalid expression";return r[0]}return t.calc=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];var n=b(r),o=m(n.expr),i=null;if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&f(a._fillData,a._error,a._fillError,a._calcError)?a:i)&&void 0!==a._fillData&&f(i._fillError,i._error))try{o=D(o,a._fillData)}catch(t){if(t instanceof g)return void 0!==i._warn&&!0===i._warn&&console.warn(t),i._fillError||i._error;throw t}else o=D(o,a)}if(a=lr(o),(o=null)===i||void 0===i._calcError&&void 0===i._error)o=cr(a);else try{o=cr(a)}catch(t){if(t instanceof _)return void 0!==i._warn&&!0===i._warn&&console.warn(t),void 0!==i._calcError?i._calcError:i._error;throw t}return o=null!==n.fmt?w(o,n.fmt):null!==o?o.toFixed():null},t.fmt=function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];var n=b(r),o=m(n.expr),i=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&f(a._fillData,a._error,a._fillError)?a:i)&&void 0!==a._fillData&&f(i._fillError,i._error))try{o=D(o,a._fillData)}catch(t){if(t instanceof g)return void 0!==i._warn&&!0===i._warn&&console.warn(t),i._fillError||i._error;throw t}else o=D(o,a)}if(null===n.fmt)throw"表达式没有格式化部分";if(i=o[0],/^[+-]*[\d.]+$/.test(i))return w(o[0],n.fmt);throw new g("待格式化对象: ".concat(i," 不是数字"))},t.tokenizer=m,t.version="0.0.56",Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
package/browser/index.html
CHANGED
|
@@ -7,31 +7,18 @@
|
|
|
7
7
|
<body>
|
|
8
8
|
<script src="./index.js"></script>
|
|
9
9
|
<script>
|
|
10
|
-
const {calc, fmt} = a_calc
|
|
10
|
+
const { calc, fmt, tokenizer } = a_calc;
|
|
11
11
|
|
|
12
|
-
// console.log(calc("1 * 2 - sfsd"))
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
console.log(
|
|
14
|
+
calc("1 + o.a / arr[0].d",
|
|
15
|
+
{
|
|
16
|
+
o: { a: 2 },
|
|
17
|
+
arr: [{ d: 8 }]
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
);
|
|
16
21
|
|
|
17
|
-
// console.log(fmt("n|,",{n:"----"}))
|
|
18
|
-
|
|
19
|
-
// console.log(calc("1 * 2 / *8 + a9 - 8 % 7",{_fillData:{a9: 10},error:"-"}))
|
|
20
|
-
// console.log(calc("a + b",{a: 1, b: 3}))
|
|
21
|
-
// console.log(fmt("100|=5"))
|
|
22
|
-
// let a = 0.000001
|
|
23
|
-
// let b = 888.789
|
|
24
|
-
// console.log(calc("a + b", {a,b}))
|
|
25
|
-
//
|
|
26
|
-
// console.log(calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)"))
|
|
27
|
-
// console.log(calc("0.11111 + 0.11111 | <=4"))
|
|
28
|
-
//
|
|
29
|
-
// // console.log(fmt("123"))
|
|
30
|
-
//
|
|
31
|
-
// a = 0.1
|
|
32
|
-
// b = 0.2
|
|
33
|
-
// let c = calc("a + b + 1 |= 2",{a,b})
|
|
34
|
-
// console.log(c)
|
|
35
22
|
</script>
|
|
36
23
|
</body>
|
|
37
24
|
</html>
|
package/browser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a_calc=function(e){"use strict";function U(e){return(U="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function n(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,t){return r&&n(e.prototype,r),t&&n(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&u(e,r)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,r){return(u=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function s(e,r,t){return(s=f()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);r=new(Function.bind.apply(e,n));return t&&u(r,t.prototype),r}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,e)})(e)}function b(e,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");r=e;if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function a(t){var n=f();return function(){var e,r=l(t);return b(this,n?(e=l(this).constructor,Reflect.construct(r,arguments,e)):r.apply(this,arguments))}}function O(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return h(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(t="Object"===t&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?h(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function p(e){return-1<"+-*/%()".indexOf(e)}function g(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function w(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];return r.some(function(e){return void 0!==e})}function _(e){var r={expr:"",fmt:null,data:null},t="",n=e[0];if(1===e.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<e.length){n=e[e.length-1];if(u=n,"[object Object]"!==Object.prototype.toString.call(u)||Array.isArray(u))for(var i=O(e.shift());i.length||e.length;)var o=0===i.length?"":i.shift(),l=0===e.length?"":e.shift(),t=t+o+(l="number"==typeof l?l.toString():l);else t=e[0],r.data=n}var u=t.split("|");return 1===u.length?r.expr=u[0]:(r.expr=u[0],""!==(n=u[1]).trim()&&(r.fmt=n)),r}var ee=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,C=Math.ceil,M=Math.floor,$="[BigNumber Error] ",re=$+"Number primitive has more than 15 significant digits: ",F=1e14,G=14,z=9007199254740991,q=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],H=1e7,V=1e9;function W(e){var r=0|e;return 0<e||e===r?r:r-1}function Z(e){for(var r,t,n=1,i=e.length,o=e[0]+"";n<i;){for(r=e[n++]+"",t=G-r.length;t--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function X(e,r){var t,n,i=e.c,o=r.c,l=e.s,u=r.s,e=e.e,r=r.e;if(!l||!u)return null;if(t=i&&!i[0],n=o&&!o[0],t||n)return t?n?0:-u:l;if(l!=u)return l;if(t=l<0,n=e==r,!i||!o)return n?0:!i^t?1:-1;if(!n)return r<e^t?1:-1;for(u=(e=i.length)<(r=o.length)?e:r,l=0;l<u;l++)if(i[l]!=o[l])return i[l]>o[l]^t?1:-1;return e==r?0:r<e^t?1:-1}function Y(e,r,t,n){if(e<r||t<e||e!==M(e))throw Error($+(n||"Argument")+("number"==typeof e?e<r||t<e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function J(e){var r=e.c.length-1;return W(e.e/G)==r&&e.c[r]%2!=0}function K(e,r){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function Q(e,r,t){var n,i;if(r<0){for(i=t+".";++r;i+=t);e=i+e}else if(++r>(n=e.length)){for(i=t,r-=n;--r;i+=t);e+=i}else r<n&&(e=e.slice(0,r)+"."+e.slice(r));return e}var d=function L(e){var d,a,h,r,s,m,l,u,f,c,p,t=D.prototype={constructor:D,toString:null,valueOf:null},g=new D(1),v=20,y=4,w=-7,b=21,O=-1e7,_=1e7,E=!1,i=1,A=0,N={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},S="0123456789abcdefghijklmnopqrstuvwxyz",x=!0;function D(e,r){var t,n,i,o,l,u,f,s,c=this;if(!(c instanceof D))return new D(e,r);if(null==r){if(e&&!0===e._isBigNumber)return c.s=e.s,void(!e.c||e.e>_?c.c=c.e=null:e.e<O?c.c=[c.e=0]:(c.e=e.e,c.c=e.c.slice()));if((u="number"==typeof e)&&0*e==0){if(c.s=1/e<0?(e=-e,-1):1,e===~~e){for(o=0,l=e;10<=l;l/=10,o++);return void(_<o?c.c=c.e=null:(c.e=o,c.c=[e]))}s=String(e)}else{if(!ee.test(s=String(e)))return h(c,s,u);c.s=45==s.charCodeAt(0)?(s=s.slice(1),-1):1}0<(l=(s=-1<(o=s.indexOf("."))?s.replace(".",""):s).search(/e/i))?(o<0&&(o=l),o+=+s.slice(l+1),s=s.substring(0,l)):o<0&&(o=s.length)}else{if(Y(r,2,S.length,"Base"),10==r&&x)return k(c=new D(e),v+c.e+1,y);if(s=String(e),u="number"==typeof e){if(0*e!=0)return h(c,s,u,r);if(c.s=1/e<0?(s=s.slice(1),-1):1,D.DEBUG&&15<s.replace(/^0\.0*|\./,"").length)throw Error(re+e)}else c.s=45===s.charCodeAt(0)?(s=s.slice(1),-1):1;for(t=S.slice(0,r),o=l=0,f=s.length;l<f;l++)if(t.indexOf(n=s.charAt(l))<0){if("."==n){if(o<l){o=f;continue}}else if(!i&&(s==s.toUpperCase()&&(s=s.toLowerCase())||s==s.toLowerCase()&&(s=s.toUpperCase()))){i=!0,l=-1,o=0;continue}return h(c,String(e),u,r)}u=!1,-1<(o=(s=a(s,r,10,c.s)).indexOf("."))?s=s.replace(".",""):o=s.length}for(l=0;48===s.charCodeAt(l);l++);for(f=s.length;48===s.charCodeAt(--f););if(s=s.slice(l,++f)){if(f-=l,u&&D.DEBUG&&15<f&&(z<e||e!==M(e)))throw Error(re+c.s*e);if((o=o-l-1)>_)c.c=c.e=null;else if(o<O)c.c=[c.e=0];else{if(c.e=o,c.c=[],l=(o+1)%G,o<0&&(l+=G),l<f){for(l&&c.c.push(+s.slice(0,l)),f-=G;l<f;)c.c.push(+s.slice(l,l+=G));l=G-(s=s.slice(l)).length}else l-=f;for(;l--;s+="0");c.c.push(+s)}}else c.c=[c.e=0]}function P(e,r,t,n){for(var i,o,l=[0],u=0,f=e.length;u<f;){for(o=l.length;o--;l[o]*=r);for(l[0]+=n.indexOf(e.charAt(u++)),i=0;i<l.length;i++)l[i]>t-1&&(null==l[i+1]&&(l[i+1]=0),l[i+1]+=l[i]/t|0,l[i]%=t)}return l.reverse()}function R(e,r,t){var n,i,o,l=0,u=e.length,f=r%H,s=r/H|0;for(e=e.slice();u--;)l=((i=f*(o=e[u]%H)+(n=s*o+(o=e[u]/H|0)*f)%H*H+l)/t|0)+(n/H|0)+s*o,e[u]=i%t;return e=l?[l].concat(e):e}function j(e,r,t,n){var i,o;if(t!=n)o=n<t?1:-1;else for(i=o=0;i<t;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function B(e,r,t,n){for(var i=0;t--;)e[t]-=i,i=e[t]<r[t]?1:0,e[t]=i*n+e[t]-r[t];for(;!e[0]&&1<e.length;e.splice(0,1));}function n(e,r,t,n){var i,o,l,u;if(null==t?t=y:Y(t,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==r)u=Z(e.c),u=1==n||2==n&&(o<=w||b<=o)?K(u,o):Q(u,o,"0");else if(t=(e=k(new D(e),r,t)).e,l=(u=Z(e.c)).length,1==n||2==n&&(r<=t||t<=w)){for(;l<r;u+="0",l++);u=K(u,t)}else if(r-=o,u=Q(u,t,"0"),l<t+1){if(0<--r)for(u+=".";r--;u+="0");}else if(0<(r+=t-l))for(t+1==l&&(u+=".");r--;u+="0");return e.s<0&&i?"-"+u:u}function o(e,r){for(var t,n=1,i=new D(e[0]);n<e.length;n++){if(!(t=new D(e[n])).s){i=t;break}r.call(i,t)&&(i=t)}return i}function T(e,r,t){for(var n=1,i=r.length;!r[--i];r.pop());for(i=r[0];10<=i;i/=10,n++);return(t=n+t*G-1)>_?e.c=e.e=null:t<O?e.c=[e.e=0]:(e.e=t,e.c=r),e}function k(e,r,t,n){var i,o,l,u,f,s,c,a=e.c,h=q;if(a){e:{for(i=1,u=a[0];10<=u;u/=10,i++);if((o=r-i)<0)o+=G,l=r,c=(f=a[s=0])/h[i-l-1]%10|0;else if((s=C((o+1)/G))>=a.length){if(!n)break e;for(;a.length<=s;a.push(0));f=c=0,l=(o%=G)-G+(i=1)}else{for(f=u=a[s],i=1;10<=u;u/=10,i++);c=(l=(o%=G)-G+i)<0?0:f/h[i-l-1]%10|0}if(n=n||r<0||null!=a[s+1]||(l<0?f:f%h[i-l-1]),n=t<4?(c||n)&&(0==t||t==(e.s<0?3:2)):5<c||5==c&&(4==t||n||6==t&&(0<o?0<l?f/h[i-l]:0:a[s-1])%10&1||t==(e.s<0?8:7)),r<1||!a[0])return a.length=0,n?(r-=e.e+1,a[0]=h[(G-r%G)%G],e.e=-r||0):a[0]=e.e=0,e;if(0==o?(a.length=s,u=1,s--):(a.length=s+1,u=h[G-o],a[s]=0<l?M(f/h[i-l]%h[l])*u:0),n)for(;;){if(0==s){for(o=1,l=a[0];10<=l;l/=10,o++);for(l=a[0]+=u,u=1;10<=l;l/=10,u++);o!=u&&(e.e++,a[0]==F&&(a[0]=1));break}if(a[s]+=u,a[s]!=F)break;a[s--]=0,u=1}for(o=a.length;0===a[--o];a.pop());}e.e>_?e.c=e.e=null:e.e<O&&(e.c=[e.e=0])}return e}function I(e){var r,t=e.e;return null===t?e.toString():(r=Z(e.c),r=t<=w||b<=t?K(r,t):Q(r,t,"0"),e.s<0?"-"+r:r)}return D.clone=L,D.ROUND_UP=0,D.ROUND_DOWN=1,D.ROUND_CEIL=2,D.ROUND_FLOOR=3,D.ROUND_HALF_UP=4,D.ROUND_HALF_DOWN=5,D.ROUND_HALF_EVEN=6,D.ROUND_HALF_CEIL=7,D.ROUND_HALF_FLOOR=8,D.EUCLID=9,D.config=D.set=function(e){var r,t;if(null!=e){if("object"!=U(e))throw Error($+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(Y(t=e[r],0,V,r),v=t),e.hasOwnProperty(r="ROUNDING_MODE")&&(Y(t=e[r],0,8,r),y=t),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((t=e[r])&&t.pop?(Y(t[0],-V,0,r),Y(t[1],0,V,r),w=t[0],b=t[1]):(Y(t,-V,V,r),w=-(b=t<0?-t:t))),e.hasOwnProperty(r="RANGE"))if((t=e[r])&&t.pop)Y(t[0],-V,-1,r),Y(t[1],1,V,r),O=t[0],_=t[1];else{if(Y(t,-V,V,r),!t)throw Error($+r+" cannot be zero: "+t);O=-(_=t<0?-t:t)}if(e.hasOwnProperty(r="CRYPTO")){if((t=e[r])!==!!t)throw Error($+r+" not true or false: "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw E=!t,Error($+"crypto unavailable");E=t}else E=t}if(e.hasOwnProperty(r="MODULO_MODE")&&(Y(t=e[r],0,9,r),i=t),e.hasOwnProperty(r="POW_PRECISION")&&(Y(t=e[r],0,V,r),A=t),e.hasOwnProperty(r="FORMAT")){if("object"!=U(t=e[r]))throw Error($+r+" not an object: "+t);N=t}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(t=e[r])||/^.?$|[+\-.\s]|(.).*\1/.test(t))throw Error($+r+" invalid: "+t);x="0123456789"==t.slice(0,10),S=t}}return{DECIMAL_PLACES:v,ROUNDING_MODE:y,EXPONENTIAL_AT:[w,b],RANGE:[O,_],CRYPTO:E,MODULO_MODE:i,POW_PRECISION:A,FORMAT:N,ALPHABET:S}},D.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!D.DEBUG)return!0;var r,t,n=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===o||-1===o)&&-V<=i&&i<=V&&i===M(i))if(0===n[0]){if(0===i&&1===n.length)return!0}else if((r=(i+1)%G)<1&&(r+=G),String(n[0]).length==r){for(r=0;r<n.length;r++)if((t=n[r])<0||F<=t||t!==M(t))break e;if(0!==t)return!0}}else if(null===n&&null===i&&(null===o||1===o||-1===o))return!0;throw Error($+"Invalid BigNumber: "+e)},D.maximum=D.max=function(){return o(arguments,t.lt)},D.minimum=D.min=function(){return o(arguments,t.gt)},D.random=(r=9007199254740992,s=Math.random()*r&2097151?function(){return M(Math.random()*r)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,t,n,i,o,l=0,u=[],f=new D(g);if(null==e?e=v:Y(e,0,V),i=C(e/G),E)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));l<i;)9e15<=(o=131072*r[l]+(r[l+1]>>>11))?(t=crypto.getRandomValues(new Uint32Array(2)),r[l]=t[0],r[l+1]=t[1]):(u.push(o%1e14),l+=2);l=i/2}else{if(!crypto.randomBytes)throw E=!1,Error($+"crypto unavailable");for(r=crypto.randomBytes(i*=7);l<i;)9e15<=(o=281474976710656*(31&r[l])+1099511627776*r[l+1]+4294967296*r[l+2]+16777216*r[l+3]+(r[l+4]<<16)+(r[l+5]<<8)+r[l+6])?crypto.randomBytes(7).copy(r,l):(u.push(o%1e14),l+=7);l=i/7}if(!E)for(;l<i;)(o=s())<9e15&&(u[l++]=o%1e14);for(i=u[--l],e%=G,i&&e&&(u[l]=M(i/(o=q[G-e]))*o);0===u[l];u.pop(),l--);if(l<0)u=[n=0];else{for(n=-1;0===u[0];u.splice(0,1),n-=G);for(l=1,o=u[0];10<=o;o/=10,l++);l<G&&(n-=G-l)}return f.e=n,f.c=u,f}),D.sum=function(){for(var e=1,r=arguments,t=new D(r[0]);e<r.length;)t=t.plus(r[e++]);return t},m="0123456789",a=function(e,r,t,n,i){var o,l,u,f,s,c,a,h,p=e.indexOf("."),g=v,w=y;for(0<=p&&(f=A,A=0,e=e.replace(".",""),c=(h=new D(r)).pow(e.length-p),A=f,h.c=P(Q(Z(c.c),c.e,"0"),10,t,m),h.e=h.c.length),u=f=(a=P(e,r,t,i?(o=S,m):(o=m,S))).length;0==a[--f];a.pop());if(!a[0])return o.charAt(0);if(p<0?--u:(c.c=a,c.e=u,c.s=n,a=(c=d(c,h,g,w,t)).c,s=c.r,u=c.e),p=a[l=u+g+1],f=t/2,s=s||l<0||null!=a[l+1],s=w<4?(null!=p||s)&&(0==w||w==(c.s<0?3:2)):f<p||p==f&&(4==w||s||6==w&&1&a[l-1]||w==(c.s<0?8:7)),l<1||!a[0])e=s?Q(o.charAt(1),-g,o.charAt(0)):o.charAt(0);else{if(a.length=l,s)for(--t;++a[--l]>t;)a[l]=0,l||(++u,a=[1].concat(a));for(f=a.length;!a[--f];);for(p=0,e="";p<=f;e+=o.charAt(a[p++]));e=Q(e,u,o.charAt(0))}return e},d=function(e,r,t,n,i){var o,l,u,f,s,c,a,h,p,g,w,d,m,v,y,b,O,_=e.s==r.s?1:-1,E=e.c,A=r.c;if(!(E&&E[0]&&A&&A[0]))return new D(e.s&&r.s&&(E?!A||E[0]!=A[0]:A)?E&&0==E[0]||!A?0*_:_/0:NaN);for(p=(h=new D(_)).c=[],_=t+(l=e.e-r.e)+1,i||(i=F,l=W(e.e/G)-W(r.e/G),_=_/G|0),u=0;A[u]==(E[u]||0);u++);if(A[u]>(E[u]||0)&&l--,_<0)p.push(1),f=!0;else{for(v=E.length,b=A.length,_+=2,1<(s=M(i/(A[u=0]+1)))&&(A=R(A,s,i),E=R(E,s,i),b=A.length,v=E.length),m=b,w=(g=E.slice(0,b)).length;w<b;g[w++]=0);O=A.slice(),O=[0].concat(O),y=A[0],A[1]>=i/2&&y++;do{if(s=0,(o=j(A,g,b,w))<0){if(d=g[0],b!=w&&(d=d*i+(g[1]||0)),1<(s=M(d/y)))for(a=(c=R(A,s=i<=s?i-1:s,i)).length,w=g.length;1==j(c,g,a,w);)s--,B(c,b<a?O:A,a,i),a=c.length,o=1;else 0==s&&(o=s=1),a=(c=A.slice()).length;if(B(g,c=a<w?[0].concat(c):c,w,i),w=g.length,-1==o)for(;j(A,g,b,w)<1;)s++,B(g,b<w?O:A,w,i),w=g.length}else 0===o&&(s++,g=[0])}while(p[u++]=s,g[0]?g[w++]=E[m]||0:(g=[E[m]],w=1),(m++<v||null!=g[0])&&_--);f=null!=g[0],p[0]||p.splice(0,1)}if(i==F){for(u=1,_=p[0];10<=_;_/=10,u++);k(h,t+(h.e=u+l*G-1)+1,n,f)}else h.e=l,h.r=+f;return h},l=/^(-?)0([xbo])(?=\w[\w.]*$)/i,u=/^([^.]+)\.$/,f=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,p=/^\s*\+(?=[\w.])|^\s+|\s+$/g,h=function(e,r,t,n){var i,o=t?r:r.replace(p,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!t&&(o=o.replace(l,function(e,r,t){return i="x"==(t=t.toLowerCase())?16:"b"==t?2:8,n&&n!=i?e:r}),n&&(i=n,o=o.replace(u,"$1").replace(f,"0.$1")),r!=o))return new D(o,i);if(D.DEBUG)throw Error($+"Not a"+(n?" base "+n:"")+" number: "+r);e.s=null}e.c=e.e=null},t.absoluteValue=t.abs=function(){var e=new D(this);return e.s<0&&(e.s=1),e},t.comparedTo=function(e,r){return X(this,new D(e,r))},t.decimalPlaces=t.dp=function(e,r){var t,n;if(null!=e)return Y(e,0,V),null==r?r=y:Y(r,0,8),k(new D(this),e+this.e+1,r);if(!(e=this.c))return null;if(t=((n=e.length-1)-W(this.e/G))*G,n=e[n])for(;n%10==0;n/=10,t--);return t=t<0?0:t},t.dividedBy=t.div=function(e,r){return d(this,new D(e,r),v,y)},t.dividedToIntegerBy=t.idiv=function(e,r){return d(this,new D(e,r),0,1)},t.exponentiatedBy=t.pow=function(e,r){var t,n,i,o,l,u,f,s,c=this;if((e=new D(e)).c&&!e.isInteger())throw Error($+"Exponent not an integer: "+I(e));if(null!=r&&(r=new D(r)),l=14<e.e,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return s=new D(Math.pow(+I(c),l?2-J(e):+I(e))),r?s.mod(r):s;if(u=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new D(NaN);(n=!u&&c.isInteger()&&r.isInteger())&&(c=c.mod(r))}else{if(9<e.e&&(0<c.e||c.e<-1||(0==c.e?1<c.c[0]||l&&24e7<=c.c[1]:c.c[0]<8e13||l&&c.c[0]<=9999975e7)))return o=c.s<0&&J(e)?-0:0,-1<c.e&&(o=1/o),new D(u?1/o:o);A&&(o=C(A/G+2))}for(f=l?(t=new D(.5),u&&(e.s=1),J(e)):(i=Math.abs(+I(e)))%2,s=new D(g);;){if(f){if(!(s=s.times(c)).c)break;o?s.c.length>o&&(s.c.length=o):n&&(s=s.mod(r))}if(i){if(0===(i=M(i/2)))break;f=i%2}else if(k(e=e.times(t),e.e+1,1),14<e.e)f=J(e);else{if(0==(i=+I(e)))break;f=i%2}c=c.times(c),o?c.c&&c.c.length>o&&(c.c.length=o):n&&(c=c.mod(r))}return n?s:(u&&(s=g.div(s)),r?s.mod(r):o?k(s,A,y,void 0):s)},t.integerValue=function(e){var r=new D(this);return null==e?e=y:Y(e,0,8),k(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===X(this,new D(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0<X(this,new D(e,r))},t.isGreaterThanOrEqualTo=t.gte=function(e,r){return 1===(r=X(this,new D(e,r)))||0===r},t.isInteger=function(){return!!this.c&&W(this.e/G)>this.c.length-2},t.isLessThan=t.lt=function(e,r){return X(this,new D(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=X(this,new D(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0<this.s},t.isZero=function(){return!!this.c&&0==this.c[0]},t.minus=function(e,r){var t,n,i,o,l=this,u=l.s;if(r=(e=new D(e,r)).s,!u||!r)return new D(NaN);if(u!=r)return e.s=-r,l.plus(e);var f=l.e/G,s=e.e/G,c=l.c,a=e.c;if(!f||!s){if(!c||!a)return c?(e.s=-r,e):new D(a?l:NaN);if(!c[0]||!a[0])return a[0]?(e.s=-r,e):new D(c[0]?l:3==y?-0:0)}if(f=W(f),s=W(s),c=c.slice(),u=f-s){for((i=(o=u<0)?(u=-u,c):(s=f,a)).reverse(),r=u;r--;i.push(0));i.reverse()}else for(n=(o=(u=c.length)<(r=a.length))?u:r,u=r=0;r<n;r++)if(c[r]!=a[r]){o=c[r]<a[r];break}if(o&&(i=c,c=a,a=i,e.s=-e.s),0<(r=(n=a.length)-(t=c.length)))for(;r--;c[t++]=0);for(r=F-1;u<n;){if(c[--n]<a[n]){for(t=n;t&&!c[--t];c[t]=r);--c[t],c[n]+=F}c[n]-=a[n]}for(;0==c[0];c.splice(0,1),--s);return c[0]?T(e,c,s):(e.s=3==y?-1:1,e.c=[e.e=0],e)},t.modulo=t.mod=function(e,r){var t,n=this;return e=new D(e,r),!n.c||!e.s||e.c&&!e.c[0]?new D(NaN):!e.c||n.c&&!n.c[0]?new D(n):(9==i?(r=e.s,e.s=1,t=d(n,e,0,3),e.s=r,t.s*=r):t=d(n,e,0,i),(e=n.minus(t.times(e))).c[0]||1!=i||(e.s=n.s),e)},t.multipliedBy=t.times=function(e,r){var t,n,i,o,l,u,f,s,c,a,h,p=this,g=p.c,w=(e=new D(e,r)).c;if(!(g&&w&&g[0]&&w[0]))return!p.s||!e.s||g&&!g[0]&&!w||w&&!w[0]&&!g?e.c=e.e=e.s=null:(e.s*=p.s,g&&w?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=W(p.e/G)+W(e.e/G),e.s*=p.s,(u=g.length)<(p=w.length)&&(h=g,g=w,w=h,n=u,u=p,p=n),n=u+p,h=[];n--;h.push(0));for(n=p;0<=--n;){for(c=w[n]%1e7,a=w[n]/1e7|(t=0),i=n+(o=u);n<i;)t=((f=c*(f=g[--o]%1e7)+(l=a*f+(s=g[o]/1e7|0)*c)%1e7*1e7+h[i]+t)/1e14|0)+(l/1e7|0)+a*s,h[i--]=f%1e14;h[i]=t}return t?++r:h.splice(0,1),T(e,h,r)},t.negated=function(){var e=new D(this);return e.s=-e.s||null,e},t.plus=function(e,r){var t,n=this,i=n.s;if(r=(e=new D(e,r)).s,!i||!r)return new D(NaN);if(i!=r)return e.s=-r,n.minus(e);var o=n.e/G,l=e.e/G,u=n.c,f=e.c;if(!o||!l){if(!u||!f)return new D(i/0);if(!u[0]||!f[0])return f[0]?e:new D(u[0]?n:0*i)}if(o=W(o),l=W(l),u=u.slice(),i=o-l){for((t=0<i?(l=o,f):(i=-i,u)).reverse();i--;t.push(0));t.reverse()}for((i=u.length)-(r=f.length)<0&&(t=f,f=u,u=t,r=i),i=0;r;)i=(u[--r]=u[r]+f[r]+i)/F|0,u[r]=F===u[r]?0:u[r]%F;return i&&(u=[i].concat(u),++l),T(e,u,l)},t.precision=t.sd=function(e,r){var t,n;if(null!=e&&e!==!!e)return Y(e,1,V),null==r?r=y:Y(r,0,8),k(new D(this),e,r);if(!(r=this.c))return null;if(t=(n=r.length-1)*G+1,n=r[n]){for(;n%10==0;n/=10,t--);for(n=r[0];10<=n;n/=10,t++);}return t=e&&this.e+1>t?this.e+1:t},t.shiftedBy=function(e){return Y(e,-z,z),this.times("1e"+e)},t.squareRoot=t.sqrt=function(){var e,r,t,n,i,o=this,l=o.c,u=o.s,f=o.e,s=v+4,c=new D("0.5");if(1!==u||!l||!l[0])return new D(!u||u<0&&(!l||l[0])?NaN:l?o:1/0);if((t=0==(u=Math.sqrt(+I(o)))||u==1/0?(((r=Z(l)).length+f)%2==0&&(r+="0"),u=Math.sqrt(+r),f=W((f+1)/2)-(f<0||f%2),new D(r=u==1/0?"5e"+f:(r=u.toExponential()).slice(0,r.indexOf("e")+1)+f)):new D(u+"")).c[0])for((u=(f=t.e)+s)<3&&(u=0);;)if(i=t,t=c.times(i.plus(d(o,i,s,1))),Z(i.c).slice(0,u)===(r=Z(t.c)).slice(0,u)){if(t.e<f&&--u,"9999"!=(r=r.slice(u-3,u+1))&&(n||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(k(t,t.e+v+2,1),e=!t.times(t).eq(o));break}if(!n&&(k(i,i.e+v+2,0),i.times(i).eq(o))){t=i;break}s+=4,u+=4,n=1}return k(t,t.e+v+1,y,e)},t.toExponential=function(e,r){return null!=e&&(Y(e,0,V),e++),n(this,e,r,1)},t.toFixed=function(e,r){return null!=e&&(Y(e,0,V),e=e+this.e+1),n(this,e,r)},t.toFormat=function(e,r,t){if(null==t)null!=e&&r&&"object"==U(r)?(t=r,r=null):e&&"object"==U(e)?(t=e,e=r=null):t=N;else if("object"!=U(t))throw Error($+"Argument not an object: "+t);if(e=this.toFixed(e,r),this.c){var n,r=e.split("."),i=+t.groupSize,o=+t.secondaryGroupSize,l=t.groupSeparator||"",u=r[0],r=r[1],f=this.s<0,s=f?u.slice(1):u,c=s.length;if(o&&(n=i,i=o,c-=o=n),0<i&&0<c){for(u=s.substr(0,n=c%i||i);n<c;n+=i)u+=l+s.substr(n,i);0<o&&(u+=l+s.slice(n)),f&&(u="-"+u)}e=r?u+(t.decimalSeparator||"")+((o=+t.fractionGroupSize)?r.replace(new RegExp("\\d{"+o+"}\\B","g"),"$&"+(t.fractionGroupSeparator||"")):r):u}return(t.prefix||"")+e+(t.suffix||"")},t.toFraction=function(e){var r,t,n,i,o,l,u,f,s,c,a=this,h=a.c;if(null!=e&&(!(u=new D(e)).isInteger()&&(u.c||1!==u.s)||u.lt(g)))throw Error($+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+I(u));if(!h)return new D(a);for(r=new D(g),s=t=new D(g),n=f=new D(g),h=Z(h),o=r.e=h.length-a.e-1,r.c[0]=q[(l=o%G)<0?G+l:l],e=!e||0<u.comparedTo(r)?0<o?r:s:u,l=_,_=1/0,u=new D(h),f.c[0]=0;c=d(u,r,0,1),1!=(i=t.plus(c.times(n))).comparedTo(e);)t=n,n=i,s=f.plus(c.times(i=s)),f=i,r=u.minus(c.times(i=r)),u=i;return i=d(e.minus(t),n,0,1),f=f.plus(i.times(s)),t=t.plus(i.times(n)),f.s=s.s=a.s,h=d(s,n,o*=2,y).minus(a).abs().comparedTo(d(f,t,o,y).minus(a).abs())<1?[s,n]:[f,t],_=l,h},t.toNumber=function(){return+I(this)},t.toPrecision=function(e,r){return null!=e&&Y(e,1,V),n(this,e,r,2)},t.toString=function(e){var r,t=this,n=t.s,i=t.e;return null===i?n?(r="Infinity",n<0&&(r="-"+r)):r="NaN":(r=null==e?i<=w||b<=i?K(Z(t.c),i):Q(Z(t.c),i,"0"):10===e&&x?Q(Z((t=k(new D(t),v+i+1,y)).c),t.e,"0"):(Y(e,2,S.length,"Base"),a(Q(Z(t.c),i,"0"),10,e,n,!0)),n<0&&t.c[0]&&(r="-"+r)),r},t.valueOf=t.toJSON=function(){return I(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,null!=e&&D.set(e),D}();function E(e,r){var t="",n=(t=d.isBigNumber(e)?e.toFixed():"string"!=typeof e?e.toString():e,null),e=null,i=null,o=r.match(/(<=|>=|=)\s*(\d+)/);if(o&&(e=o[1],n=Number(o[2])),r.includes(",")&&(i=!0),null!==n){var o=t.split("."),r=o[0],l=1===o.length?"":o[1],u=l.length;switch(e){case"<=":l=u<=n?l:l.slice(0,n);break;case"=":u<n?l+="0".repeat(n-u):n<u&&(l=l.slice(0,n));break;case">=":l=n<=u?l:l+"0".repeat(n-u)}t=""===l?r:"".concat(r,".").concat(l)}return t=null!==i?1<(o=t.split(".")).length?((e=o[0]).includes("-")?o[0]=e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):o[0]=e.replace(/(?=(?!^)(?:\d{3})+$)/g,","),o.join(".")):(r=o[0]).includes("-")?r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):r.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function A(e){for(var r=[],t=0,n=null,i=e.length;t<i;)if(n=e[t],/\s/.test(n))t++;else if("+-".includes(n)){var o=r[r.length-1];if(0===r.length||"+-".includes(o)||"("===o){for(var l=n,n=e[++t];/[a-zA-Z\d._]/.test(n);)l+=n,n=e[++t];r.push(l)}else r.push(n),t++}else if("*/%()".includes(n))r.push(n),t++;else if(/[a-zA-Z_]/.test(n)){for(var u="";/[a-zA-Z0-9_]/.test(n)&&(u+=n,!(++t>=i));)n=e[t];r.push(u)}else if(/\d/.test(n)){for(var f="";/[\d.]/.test(n)&&(f+=n,!(++t>=i));)n=e[t];r.push(f)}return r}var m=function(){o(n,c(Error));var t=a(n);function n(e){var r;return i(this,n),(r=t.call(this,e)).name="CalculatorError",r.message=e,r}return r(n)}(),v=function(){o(n,c(Error));var t=a(n);function n(e){var r;return i(this,n),(r=t.call(this,e)).name="TokensFillError",r.message=e,r}return r(n)}();function y(e,r){for(var t=r._fillData,n=(void 0===r._fillData&&(t=r),Array.isArray(t)||(t=[t]),[]),i=0;i<e.length;i++){var o=e[i];if(/^[a-zA-z_][\w_]*$/.test(o)){if("undefined"===o||"NaN"===o)throw new v("key不应该为:".concat(o));for(var l=null,u=0;u<t.length;u++){var f=t[u];if(void 0!==f[o]){l=f[o];break}}if(null===l)throw new v("token填充失败,请确认".concat(o,"存在"));if("string"==typeof l){if(""===l.trim())throw new v("token填充失败,".concat(o,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(l))throw new v("token填充失败,".concat(o,"值:").concat(l,"为非法数字"))}l="string"!=typeof l?l.toString():l,n.push(l)}else n.push(o)}return n}function N(e){for(var r,t=[],n=[],i=e;0<i.length;){var o=i.shift();if(p(o))if("("===o)t.push(o);else if(")"===o){for(var l=t.pop();"("!==l&&0<t.length;)n.push(l),l=t.pop();if("("!==l)throw"error: unmatched ()"}else{for(;r=t[t.length-1],g(o)<=g(r)&&0<t.length;)n.push(t.pop());t.push(o)}else n.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)n.push(t.pop())}return n}function S(e){for(var r=[];0<e.length;){var t=e.shift();if(p(t)){if(r.length<2)throw new m("错误的栈长度, 可能是无法计算的表达式");var n=r.pop(),i=r.pop();if("string"==typeof n&&!d.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new m("".concat(n,"不是一个合法的数字"));n=new d(n)}if("string"==typeof i&&!d.isBigNumber(i)){if(!/^[+-]*[\d.]+$/.test(i))throw new m("".concat(i,"不是一个合法的数字"));i=new d(i)}switch(t){case"+":r.push(i.plus(n));break;case"-":r.push(i.minus(n));break;case"*":r.push(i.times(n));break;case"/":r.push(i.div(n));break;case"%":r.push(i.mod(n))}}else r.push(t)}if(1!==r.length)throw"unvalid expression";return r[0]}return e.calc=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=_(r),i=A(n.expr),o=null;if(null!==n.data){var l=n.data;if(null!==(o=!Array.isArray(l)&&w(l._fillData,l._error,l._fillError,l._calcError)?l:o)&&void 0!==l._fillData&&w(o._fillError,o._error))try{i=y(i,l._fillData)}catch(e){if(e instanceof v)return void 0!==o._warn&&!0===o._warn&&console.warn(e),o._fillError||o._error;throw e}else i=y(i,l)}if(l=N(i),(i=null)!==o){if(void 0!==o._calcError||void 0!==o._error)try{i=S(l)}catch(e){if(e instanceof m)return void 0!==o._warn&&!0===o._warn&&console.warn(e),void 0!==o._calcError?o._calcError:o._error;throw e}}else i=S(l);return i=null!==n.fmt?E(i,n.fmt):null!==i?i.toFixed():null},e.fmt=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=_(r),i=A(n.expr),o=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<i.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==i.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var l=n.data;if(null!==(o=!Array.isArray(l)&&w(l._fillData,l._error,l._fillError)?l:o)&&void 0!==l._fillData&&w(o._fillError,o._error))try{i=y(i,l._fillData)}catch(e){if(e instanceof v)return void 0!==o._warn&&!0===o._warn&&console.warn(e),o._fillError||o._error;throw e}else i=y(i,l)}if(null===n.fmt)throw"表达式没有格式化部分";if(o=i[0],/^[+-]*[\d.]+$/.test(o))return E(i[0],n.fmt);throw new v("待格式化对象: ".concat(o," 不是数字"))},e.version="0.0.53",Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
1
|
+
var a_calc=function(e){"use strict";function _(e){return-1<"+-*/%()".indexOf(e)}function b(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function l(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];return r.some(function(e){return void 0!==e})}function F(e){return(F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function m(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function O(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function E(e,r,t){return r&&O(e.prototype,r),t&&O(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function N(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&o(e,r)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,r){return(o=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function A(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function S(e,r,t){return(S=A()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);r=new(Function.bind.apply(e,n));return t&&o(r,t.prototype),r}).apply(null,arguments)}function r(e){var t="function"==typeof Map?new Map:void 0;return(r=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return S(e,arguments,i(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,e)})(e)}function j(e,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");r=e;if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function x(t){var n=A();return function(){var e,r=i(t);return j(this,n?(e=i(this).constructor,Reflect.construct(r,arguments,e)):r.apply(this,arguments))}}var c=function(){N(n,r(Error));var t=x(n);function n(e){var r;return m(this,n),(r=t.call(this,e)).name="CalculatorError",r.message=e,r}return E(n)}(),a=function(){N(n,r(Error));var t=x(n);function n(e){var r;return m(this,n),(r=t.call(this,e)).name="TokensFillError",r.message=e,r}return E(n)}();function P(e){var r={expr:"",fmt:null,data:null},t="",n=e[0];if(1===e.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<e.length){n=e[e.length-1];if(i=n,("[object Object]"!==Object.prototype.toString.call(i)||Array.isArray(i))&&!Array.isArray(n))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(t=e[0])){if(""===t.trim())throw new a("参数不可为空字符串")}else if("number"==typeof t)t=t.toString();else if(void 0===t||Number.isNaN(t))throw new a("非法参数:".concat(t));r.data=n}var i=t.split("|");return 1===i.length?r.expr=i[0]:(r.expr=i[0],""!==(e=i[1]).trim()&&(r.fmt=e)),null!==r.data&&null===r.fmt&&r.data._fmt&&(r.fmt=r.data._fmt),r}var ee=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,L=Math.ceil,U=Math.floor,z="[BigNumber Error] ",re=z+"Number primitive has more than 15 significant digits: ",I=1e14,M=14,G=9007199254740991,q=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],H=1e7,V=1e9;function W(e){var r=0|e;return 0<e||e===r?r:r-1}function X(e){for(var r,t,n=1,i=e.length,o=e[0]+"";n<i;){for(r=e[n++]+"",t=M-r.length;t--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function Y(e,r){var t,n,i=e.c,o=r.c,u=e.s,l=r.s,e=e.e,r=r.e;if(!u||!l)return null;if(t=i&&!i[0],n=o&&!o[0],t||n)return t?n?0:-l:u;if(u!=l)return u;if(t=u<0,n=e==r,!i||!o)return n?0:!i^t?1:-1;if(!n)return r<e^t?1:-1;for(l=(e=i.length)<(r=o.length)?e:r,u=0;u<l;u++)if(i[u]!=o[u])return i[u]>o[u]^t?1:-1;return e==r?0:r<e^t?1:-1}function Z(e,r,t,n){if(e<r||t<e||e!==U(e))throw Error(z+(n||"Argument")+("number"==typeof e?e<r||t<e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function J(e){var r=e.c.length-1;return W(e.e/M)==r&&e.c[r]%2!=0}function K(e,r){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function Q(e,r,t){var n,i;if(r<0){for(i=t+".";++r;i+=t);e=i+e}else if(++r>(n=e.length)){for(i=t,r-=n;--r;i+=t);e+=i}else r<n&&(e=e.slice(0,r)+"."+e.slice(r));return e}var f=function C(e){var d,s,h,r,a,y,u,l,c,f,p,t=x.prototype={constructor:x,toString:null,valueOf:null},g=new x(1),w=20,_=4,v=-7,b=21,m=-1e7,O=1e7,E=!1,i=1,N=0,A={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},S="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function x(e,r){var t,n,i,o,u,l,c,a,f=this;if(!(f instanceof x))return new x(e,r);if(null==r){if(e&&!0===e._isBigNumber)return f.s=e.s,void(!e.c||e.e>O?f.c=f.e=null:e.e<m?f.c=[f.e=0]:(f.e=e.e,f.c=e.c.slice()));if((l="number"==typeof e)&&0*e==0){if(f.s=1/e<0?(e=-e,-1):1,e===~~e){for(o=0,u=e;10<=u;u/=10,o++);return void(O<o?f.c=f.e=null:(f.e=o,f.c=[e]))}a=String(e)}else{if(!ee.test(a=String(e)))return h(f,a,l);f.s=45==a.charCodeAt(0)?(a=a.slice(1),-1):1}0<(u=(a=-1<(o=a.indexOf("."))?a.replace(".",""):a).search(/e/i))?(o<0&&(o=u),o+=+a.slice(u+1),a=a.substring(0,u)):o<0&&(o=a.length)}else{if(Z(r,2,S.length,"Base"),10==r&&j)return k(f=new x(e),w+f.e+1,_);if(a=String(e),l="number"==typeof e){if(0*e!=0)return h(f,a,l,r);if(f.s=1/e<0?(a=a.slice(1),-1):1,x.DEBUG&&15<a.replace(/^0\.0*|\./,"").length)throw Error(re+e)}else f.s=45===a.charCodeAt(0)?(a=a.slice(1),-1):1;for(t=S.slice(0,r),o=u=0,c=a.length;u<c;u++)if(t.indexOf(n=a.charAt(u))<0){if("."==n){if(o<u){o=c;continue}}else if(!i&&(a==a.toUpperCase()&&(a=a.toLowerCase())||a==a.toLowerCase()&&(a=a.toUpperCase()))){i=!0,u=-1,o=0;continue}return h(f,String(e),l,r)}l=!1,-1<(o=(a=s(a,r,10,f.s)).indexOf("."))?a=a.replace(".",""):o=a.length}for(u=0;48===a.charCodeAt(u);u++);for(c=a.length;48===a.charCodeAt(--c););if(a=a.slice(u,++c)){if(c-=u,l&&x.DEBUG&&15<c&&(G<e||e!==U(e)))throw Error(re+f.s*e);if((o=o-u-1)>O)f.c=f.e=null;else if(o<m)f.c=[f.e=0];else{if(f.e=o,f.c=[],u=(o+1)%M,o<0&&(u+=M),u<c){for(u&&f.c.push(+a.slice(0,u)),c-=M;u<c;)f.c.push(+a.slice(u,u+=M));u=M-(a=a.slice(u)).length}else u-=c;for(;u--;a+="0");f.c.push(+a)}}else f.c=[f.e=0]}function P(e,r,t,n){for(var i,o,u=[0],l=0,c=e.length;l<c;){for(o=u.length;o--;u[o]*=r);for(u[0]+=n.indexOf(e.charAt(l++)),i=0;i<u.length;i++)u[i]>t-1&&(null==u[i+1]&&(u[i+1]=0),u[i+1]+=u[i]/t|0,u[i]%=t)}return u.reverse()}function R(e,r,t){var n,i,o,u=0,l=e.length,c=r%H,a=r/H|0;for(e=e.slice();l--;)u=((i=c*(o=e[l]%H)+(n=a*o+(o=e[l]/H|0)*c)%H*H+u)/t|0)+(n/H|0)+a*o,e[l]=i%t;return e=u?[u].concat(e):e}function D(e,r,t,n){var i,o;if(t!=n)o=n<t?1:-1;else for(i=o=0;i<t;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function T(e,r,t,n){for(var i=0;t--;)e[t]-=i,i=e[t]<r[t]?1:0,e[t]=i*n+e[t]-r[t];for(;!e[0]&&1<e.length;e.splice(0,1));}function n(e,r,t,n){var i,o,u,l;if(null==t?t=_:Z(t,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==r)l=X(e.c),l=1==n||2==n&&(o<=v||b<=o)?K(l,o):Q(l,o,"0");else if(t=(e=k(new x(e),r,t)).e,u=(l=X(e.c)).length,1==n||2==n&&(r<=t||t<=v)){for(;u<r;l+="0",u++);l=K(l,t)}else if(r-=o,l=Q(l,t,"0"),u<t+1){if(0<--r)for(l+=".";r--;l+="0");}else if(0<(r+=t-u))for(t+1==u&&(l+=".");r--;l+="0");return e.s<0&&i?"-"+l:l}function o(e,r){for(var t,n=1,i=new x(e[0]);n<e.length;n++){if(!(t=new x(e[n])).s){i=t;break}r.call(i,t)&&(i=t)}return i}function B(e,r,t){for(var n=1,i=r.length;!r[--i];r.pop());for(i=r[0];10<=i;i/=10,n++);return(t=n+t*M-1)>O?e.c=e.e=null:t<m?e.c=[e.e=0]:(e.e=t,e.c=r),e}function k(e,r,t,n){var i,o,u,l,c,a,f,s=e.c,h=q;if(s){e:{for(i=1,l=s[0];10<=l;l/=10,i++);if((o=r-i)<0)o+=M,u=r,f=(c=s[a=0])/h[i-u-1]%10|0;else if((a=L((o+1)/M))>=s.length){if(!n)break e;for(;s.length<=a;s.push(0));c=f=0,u=(o%=M)-M+(i=1)}else{for(c=l=s[a],i=1;10<=l;l/=10,i++);f=(u=(o%=M)-M+i)<0?0:c/h[i-u-1]%10|0}if(n=n||r<0||null!=s[a+1]||(u<0?c:c%h[i-u-1]),n=t<4?(f||n)&&(0==t||t==(e.s<0?3:2)):5<f||5==f&&(4==t||n||6==t&&(0<o?0<u?c/h[i-u]:0:s[a-1])%10&1||t==(e.s<0?8:7)),r<1||!s[0])return s.length=0,n?(r-=e.e+1,s[0]=h[(M-r%M)%M],e.e=-r||0):s[0]=e.e=0,e;if(0==o?(s.length=a,l=1,a--):(s.length=a+1,l=h[M-o],s[a]=0<u?U(c/h[i-u]%h[u])*l:0),n)for(;;){if(0==a){for(o=1,u=s[0];10<=u;u/=10,o++);for(u=s[0]+=l,l=1;10<=u;u/=10,l++);o!=l&&(e.e++,s[0]==I&&(s[0]=1));break}if(s[a]+=l,s[a]!=I)break;s[a--]=0,l=1}for(o=s.length;0===s[--o];s.pop());}e.e>O?e.c=e.e=null:e.e<m&&(e.c=[e.e=0])}return e}function $(e){var r,t=e.e;return null===t?e.toString():(r=X(e.c),r=t<=v||b<=t?K(r,t):Q(r,t,"0"),e.s<0?"-"+r:r)}return x.clone=C,x.ROUND_UP=0,x.ROUND_DOWN=1,x.ROUND_CEIL=2,x.ROUND_FLOOR=3,x.ROUND_HALF_UP=4,x.ROUND_HALF_DOWN=5,x.ROUND_HALF_EVEN=6,x.ROUND_HALF_CEIL=7,x.ROUND_HALF_FLOOR=8,x.EUCLID=9,x.config=x.set=function(e){var r,t;if(null!=e){if("object"!=F(e))throw Error(z+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(Z(t=e[r],0,V,r),w=t),e.hasOwnProperty(r="ROUNDING_MODE")&&(Z(t=e[r],0,8,r),_=t),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((t=e[r])&&t.pop?(Z(t[0],-V,0,r),Z(t[1],0,V,r),v=t[0],b=t[1]):(Z(t,-V,V,r),v=-(b=t<0?-t:t))),e.hasOwnProperty(r="RANGE"))if((t=e[r])&&t.pop)Z(t[0],-V,-1,r),Z(t[1],1,V,r),m=t[0],O=t[1];else{if(Z(t,-V,V,r),!t)throw Error(z+r+" cannot be zero: "+t);m=-(O=t<0?-t:t)}if(e.hasOwnProperty(r="CRYPTO")){if((t=e[r])!==!!t)throw Error(z+r+" not true or false: "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw E=!t,Error(z+"crypto unavailable");E=t}else E=t}if(e.hasOwnProperty(r="MODULO_MODE")&&(Z(t=e[r],0,9,r),i=t),e.hasOwnProperty(r="POW_PRECISION")&&(Z(t=e[r],0,V,r),N=t),e.hasOwnProperty(r="FORMAT")){if("object"!=F(t=e[r]))throw Error(z+r+" not an object: "+t);A=t}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(t=e[r])||/^.?$|[+\-.\s]|(.).*\1/.test(t))throw Error(z+r+" invalid: "+t);j="0123456789"==t.slice(0,10),S=t}}return{DECIMAL_PLACES:w,ROUNDING_MODE:_,EXPONENTIAL_AT:[v,b],RANGE:[m,O],CRYPTO:E,MODULO_MODE:i,POW_PRECISION:N,FORMAT:A,ALPHABET:S}},x.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!x.DEBUG)return!0;var r,t,n=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===o||-1===o)&&-V<=i&&i<=V&&i===U(i))if(0===n[0]){if(0===i&&1===n.length)return!0}else if((r=(i+1)%M)<1&&(r+=M),String(n[0]).length==r){for(r=0;r<n.length;r++)if((t=n[r])<0||I<=t||t!==U(t))break e;if(0!==t)return!0}}else if(null===n&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(z+"Invalid BigNumber: "+e)},x.maximum=x.max=function(){return o(arguments,t.lt)},x.minimum=x.min=function(){return o(arguments,t.gt)},x.random=(r=9007199254740992,a=Math.random()*r&2097151?function(){return U(Math.random()*r)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,t,n,i,o,u=0,l=[],c=new x(g);if(null==e?e=w:Z(e,0,V),i=L(e/M),E)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));u<i;)9e15<=(o=131072*r[u]+(r[u+1]>>>11))?(t=crypto.getRandomValues(new Uint32Array(2)),r[u]=t[0],r[u+1]=t[1]):(l.push(o%1e14),u+=2);u=i/2}else{if(!crypto.randomBytes)throw E=!1,Error(z+"crypto unavailable");for(r=crypto.randomBytes(i*=7);u<i;)9e15<=(o=281474976710656*(31&r[u])+1099511627776*r[u+1]+4294967296*r[u+2]+16777216*r[u+3]+(r[u+4]<<16)+(r[u+5]<<8)+r[u+6])?crypto.randomBytes(7).copy(r,u):(l.push(o%1e14),u+=7);u=i/7}if(!E)for(;u<i;)(o=a())<9e15&&(l[u++]=o%1e14);for(i=l[--u],e%=M,i&&e&&(l[u]=U(i/(o=q[M-e]))*o);0===l[u];l.pop(),u--);if(u<0)l=[n=0];else{for(n=-1;0===l[0];l.splice(0,1),n-=M);for(u=1,o=l[0];10<=o;o/=10,u++);u<M&&(n-=M-u)}return c.e=n,c.c=l,c}),x.sum=function(){for(var e=1,r=arguments,t=new x(r[0]);e<r.length;)t=t.plus(r[e++]);return t},y="0123456789",s=function(e,r,t,n,i){var o,u,l,c,a,f,s,h,p=e.indexOf("."),g=w,v=_;for(0<=p&&(c=N,N=0,e=e.replace(".",""),f=(h=new x(r)).pow(e.length-p),N=c,h.c=P(Q(X(f.c),f.e,"0"),10,t,y),h.e=h.c.length),l=c=(s=P(e,r,t,i?(o=S,y):(o=y,S))).length;0==s[--c];s.pop());if(!s[0])return o.charAt(0);if(p<0?--l:(f.c=s,f.e=l,f.s=n,s=(f=d(f,h,g,v,t)).c,a=f.r,l=f.e),p=s[u=l+g+1],c=t/2,a=a||u<0||null!=s[u+1],a=v<4?(null!=p||a)&&(0==v||v==(f.s<0?3:2)):c<p||p==c&&(4==v||a||6==v&&1&s[u-1]||v==(f.s<0?8:7)),u<1||!s[0])e=a?Q(o.charAt(1),-g,o.charAt(0)):o.charAt(0);else{if(s.length=u,a)for(--t;++s[--u]>t;)s[u]=0,u||(++l,s=[1].concat(s));for(c=s.length;!s[--c];);for(p=0,e="";p<=c;e+=o.charAt(s[p++]));e=Q(e,l,o.charAt(0))}return e},d=function(e,r,t,n,i){var o,u,l,c,a,f,s,h,p,g,v,d,y,w,_,b,m,O=e.s==r.s?1:-1,E=e.c,N=r.c;if(!(E&&E[0]&&N&&N[0]))return new x(e.s&&r.s&&(E?!N||E[0]!=N[0]:N)?E&&0==E[0]||!N?0*O:O/0:NaN);for(p=(h=new x(O)).c=[],O=t+(u=e.e-r.e)+1,i||(i=I,u=W(e.e/M)-W(r.e/M),O=O/M|0),l=0;N[l]==(E[l]||0);l++);if(N[l]>(E[l]||0)&&u--,O<0)p.push(1),c=!0;else{for(w=E.length,b=N.length,O+=2,1<(a=U(i/(N[l=0]+1)))&&(N=R(N,a,i),E=R(E,a,i),b=N.length,w=E.length),y=b,v=(g=E.slice(0,b)).length;v<b;g[v++]=0);m=N.slice(),m=[0].concat(m),_=N[0],N[1]>=i/2&&_++;do{if(a=0,(o=D(N,g,b,v))<0){if(d=g[0],b!=v&&(d=d*i+(g[1]||0)),1<(a=U(d/_)))for(s=(f=R(N,a=i<=a?i-1:a,i)).length,v=g.length;1==D(f,g,s,v);)a--,T(f,b<s?m:N,s,i),s=f.length,o=1;else 0==a&&(o=a=1),s=(f=N.slice()).length;if(T(g,f=s<v?[0].concat(f):f,v,i),v=g.length,-1==o)for(;D(N,g,b,v)<1;)a++,T(g,b<v?m:N,v,i),v=g.length}else 0===o&&(a++,g=[0])}while(p[l++]=a,g[0]?g[v++]=E[y]||0:(g=[E[y]],v=1),(y++<w||null!=g[0])&&O--);c=null!=g[0],p[0]||p.splice(0,1)}if(i==I){for(l=1,O=p[0];10<=O;O/=10,l++);k(h,t+(h.e=l+u*M-1)+1,n,c)}else h.e=u,h.r=+c;return h},u=/^(-?)0([xbo])(?=\w[\w.]*$)/i,l=/^([^.]+)\.$/,c=/^\.([^.]+)$/,f=/^-?(Infinity|NaN)$/,p=/^\s*\+(?=[\w.])|^\s+|\s+$/g,h=function(e,r,t,n){var i,o=t?r:r.replace(p,"");if(f.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!t&&(o=o.replace(u,function(e,r,t){return i="x"==(t=t.toLowerCase())?16:"b"==t?2:8,n&&n!=i?e:r}),n&&(i=n,o=o.replace(l,"$1").replace(c,"0.$1")),r!=o))return new x(o,i);if(x.DEBUG)throw Error(z+"Not a"+(n?" base "+n:"")+" number: "+r);e.s=null}e.c=e.e=null},t.absoluteValue=t.abs=function(){var e=new x(this);return e.s<0&&(e.s=1),e},t.comparedTo=function(e,r){return Y(this,new x(e,r))},t.decimalPlaces=t.dp=function(e,r){var t,n;if(null!=e)return Z(e,0,V),null==r?r=_:Z(r,0,8),k(new x(this),e+this.e+1,r);if(!(e=this.c))return null;if(t=((n=e.length-1)-W(this.e/M))*M,n=e[n])for(;n%10==0;n/=10,t--);return t=t<0?0:t},t.dividedBy=t.div=function(e,r){return d(this,new x(e,r),w,_)},t.dividedToIntegerBy=t.idiv=function(e,r){return d(this,new x(e,r),0,1)},t.exponentiatedBy=t.pow=function(e,r){var t,n,i,o,u,l,c,a,f=this;if((e=new x(e)).c&&!e.isInteger())throw Error(z+"Exponent not an integer: "+$(e));if(null!=r&&(r=new x(r)),u=14<e.e,!f.c||!f.c[0]||1==f.c[0]&&!f.e&&1==f.c.length||!e.c||!e.c[0])return a=new x(Math.pow(+$(f),u?2-J(e):+$(e))),r?a.mod(r):a;if(l=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new x(NaN);(n=!l&&f.isInteger()&&r.isInteger())&&(f=f.mod(r))}else{if(9<e.e&&(0<f.e||f.e<-1||(0==f.e?1<f.c[0]||u&&24e7<=f.c[1]:f.c[0]<8e13||u&&f.c[0]<=9999975e7)))return o=f.s<0&&J(e)?-0:0,-1<f.e&&(o=1/o),new x(l?1/o:o);N&&(o=L(N/M+2))}for(c=u?(t=new x(.5),l&&(e.s=1),J(e)):(i=Math.abs(+$(e)))%2,a=new x(g);;){if(c){if(!(a=a.times(f)).c)break;o?a.c.length>o&&(a.c.length=o):n&&(a=a.mod(r))}if(i){if(0===(i=U(i/2)))break;c=i%2}else if(k(e=e.times(t),e.e+1,1),14<e.e)c=J(e);else{if(0==(i=+$(e)))break;c=i%2}f=f.times(f),o?f.c&&f.c.length>o&&(f.c.length=o):n&&(f=f.mod(r))}return n?a:(l&&(a=g.div(a)),r?a.mod(r):o?k(a,N,_,void 0):a)},t.integerValue=function(e){var r=new x(this);return null==e?e=_:Z(e,0,8),k(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===Y(this,new x(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0<Y(this,new x(e,r))},t.isGreaterThanOrEqualTo=t.gte=function(e,r){return 1===(r=Y(this,new x(e,r)))||0===r},t.isInteger=function(){return!!this.c&&W(this.e/M)>this.c.length-2},t.isLessThan=t.lt=function(e,r){return Y(this,new x(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=Y(this,new x(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0<this.s},t.isZero=function(){return!!this.c&&0==this.c[0]},t.minus=function(e,r){var t,n,i,o,u=this,l=u.s;if(r=(e=new x(e,r)).s,!l||!r)return new x(NaN);if(l!=r)return e.s=-r,u.plus(e);var c=u.e/M,a=e.e/M,f=u.c,s=e.c;if(!c||!a){if(!f||!s)return f?(e.s=-r,e):new x(s?u:NaN);if(!f[0]||!s[0])return s[0]?(e.s=-r,e):new x(f[0]?u:3==_?-0:0)}if(c=W(c),a=W(a),f=f.slice(),l=c-a){for((i=(o=l<0)?(l=-l,f):(a=c,s)).reverse(),r=l;r--;i.push(0));i.reverse()}else for(n=(o=(l=f.length)<(r=s.length))?l:r,l=r=0;r<n;r++)if(f[r]!=s[r]){o=f[r]<s[r];break}if(o&&(i=f,f=s,s=i,e.s=-e.s),0<(r=(n=s.length)-(t=f.length)))for(;r--;f[t++]=0);for(r=I-1;l<n;){if(f[--n]<s[n]){for(t=n;t&&!f[--t];f[t]=r);--f[t],f[n]+=I}f[n]-=s[n]}for(;0==f[0];f.splice(0,1),--a);return f[0]?B(e,f,a):(e.s=3==_?-1:1,e.c=[e.e=0],e)},t.modulo=t.mod=function(e,r){var t,n=this;return e=new x(e,r),!n.c||!e.s||e.c&&!e.c[0]?new x(NaN):!e.c||n.c&&!n.c[0]?new x(n):(9==i?(r=e.s,e.s=1,t=d(n,e,0,3),e.s=r,t.s*=r):t=d(n,e,0,i),(e=n.minus(t.times(e))).c[0]||1!=i||(e.s=n.s),e)},t.multipliedBy=t.times=function(e,r){var t,n,i,o,u,l,c,a,f,s,h,p=this,g=p.c,v=(e=new x(e,r)).c;if(!(g&&v&&g[0]&&v[0]))return!p.s||!e.s||g&&!g[0]&&!v||v&&!v[0]&&!g?e.c=e.e=e.s=null:(e.s*=p.s,g&&v?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=W(p.e/M)+W(e.e/M),e.s*=p.s,(l=g.length)<(p=v.length)&&(h=g,g=v,v=h,n=l,l=p,p=n),n=l+p,h=[];n--;h.push(0));for(n=p;0<=--n;){for(f=v[n]%1e7,s=v[n]/1e7|(t=0),i=n+(o=l);n<i;)t=((c=f*(c=g[--o]%1e7)+(u=s*c+(a=g[o]/1e7|0)*f)%1e7*1e7+h[i]+t)/1e14|0)+(u/1e7|0)+s*a,h[i--]=c%1e14;h[i]=t}return t?++r:h.splice(0,1),B(e,h,r)},t.negated=function(){var e=new x(this);return e.s=-e.s||null,e},t.plus=function(e,r){var t,n=this,i=n.s;if(r=(e=new x(e,r)).s,!i||!r)return new x(NaN);if(i!=r)return e.s=-r,n.minus(e);var o=n.e/M,u=e.e/M,l=n.c,c=e.c;if(!o||!u){if(!l||!c)return new x(i/0);if(!l[0]||!c[0])return c[0]?e:new x(l[0]?n:0*i)}if(o=W(o),u=W(u),l=l.slice(),i=o-u){for((t=0<i?(u=o,c):(i=-i,l)).reverse();i--;t.push(0));t.reverse()}for((i=l.length)-(r=c.length)<0&&(t=c,c=l,l=t,r=i),i=0;r;)i=(l[--r]=l[r]+c[r]+i)/I|0,l[r]=I===l[r]?0:l[r]%I;return i&&(l=[i].concat(l),++u),B(e,l,u)},t.precision=t.sd=function(e,r){var t,n;if(null!=e&&e!==!!e)return Z(e,1,V),null==r?r=_:Z(r,0,8),k(new x(this),e,r);if(!(r=this.c))return null;if(t=(n=r.length-1)*M+1,n=r[n]){for(;n%10==0;n/=10,t--);for(n=r[0];10<=n;n/=10,t++);}return t=e&&this.e+1>t?this.e+1:t},t.shiftedBy=function(e){return Z(e,-G,G),this.times("1e"+e)},t.squareRoot=t.sqrt=function(){var e,r,t,n,i,o=this,u=o.c,l=o.s,c=o.e,a=w+4,f=new x("0.5");if(1!==l||!u||!u[0])return new x(!l||l<0&&(!u||u[0])?NaN:u?o:1/0);if((t=0==(l=Math.sqrt(+$(o)))||l==1/0?(((r=X(u)).length+c)%2==0&&(r+="0"),l=Math.sqrt(+r),c=W((c+1)/2)-(c<0||c%2),new x(r=l==1/0?"5e"+c:(r=l.toExponential()).slice(0,r.indexOf("e")+1)+c)):new x(l+"")).c[0])for((l=(c=t.e)+a)<3&&(l=0);;)if(i=t,t=f.times(i.plus(d(o,i,a,1))),X(i.c).slice(0,l)===(r=X(t.c)).slice(0,l)){if(t.e<c&&--l,"9999"!=(r=r.slice(l-3,l+1))&&(n||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(k(t,t.e+w+2,1),e=!t.times(t).eq(o));break}if(!n&&(k(i,i.e+w+2,0),i.times(i).eq(o))){t=i;break}a+=4,l+=4,n=1}return k(t,t.e+w+1,_,e)},t.toExponential=function(e,r){return null!=e&&(Z(e,0,V),e++),n(this,e,r,1)},t.toFixed=function(e,r){return null!=e&&(Z(e,0,V),e=e+this.e+1),n(this,e,r)},t.toFormat=function(e,r,t){if(null==t)null!=e&&r&&"object"==F(r)?(t=r,r=null):e&&"object"==F(e)?(t=e,e=r=null):t=A;else if("object"!=F(t))throw Error(z+"Argument not an object: "+t);if(e=this.toFixed(e,r),this.c){var n,r=e.split("."),i=+t.groupSize,o=+t.secondaryGroupSize,u=t.groupSeparator||"",l=r[0],r=r[1],c=this.s<0,a=c?l.slice(1):l,f=a.length;if(o&&(n=i,i=o,f-=o=n),0<i&&0<f){for(l=a.substr(0,n=f%i||i);n<f;n+=i)l+=u+a.substr(n,i);0<o&&(l+=u+a.slice(n)),c&&(l="-"+l)}e=r?l+(t.decimalSeparator||"")+((o=+t.fractionGroupSize)?r.replace(new RegExp("\\d{"+o+"}\\B","g"),"$&"+(t.fractionGroupSeparator||"")):r):l}return(t.prefix||"")+e+(t.suffix||"")},t.toFraction=function(e){var r,t,n,i,o,u,l,c,a,f,s=this,h=s.c;if(null!=e&&(!(l=new x(e)).isInteger()&&(l.c||1!==l.s)||l.lt(g)))throw Error(z+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+$(l));if(!h)return new x(s);for(r=new x(g),a=t=new x(g),n=c=new x(g),h=X(h),o=r.e=h.length-s.e-1,r.c[0]=q[(u=o%M)<0?M+u:u],e=!e||0<l.comparedTo(r)?0<o?r:a:l,u=O,O=1/0,l=new x(h),c.c[0]=0;f=d(l,r,0,1),1!=(i=t.plus(f.times(n))).comparedTo(e);)t=n,n=i,a=c.plus(f.times(i=a)),c=i,r=l.minus(f.times(i=r)),l=i;return i=d(e.minus(t),n,0,1),c=c.plus(i.times(a)),t=t.plus(i.times(n)),c.s=a.s=s.s,h=d(a,n,o*=2,_).minus(s).abs().comparedTo(d(c,t,o,_).minus(s).abs())<1?[a,n]:[c,t],O=u,h},t.toNumber=function(){return+$(this)},t.toPrecision=function(e,r){return null!=e&&Z(e,1,V),n(this,e,r,2)},t.toString=function(e){var r,t=this,n=t.s,i=t.e;return null===i?n?(r="Infinity",n<0&&(r="-"+r)):r="NaN":(r=null==e?i<=v||b<=i?K(X(t.c),i):Q(X(t.c),i,"0"):10===e&&j?Q(X((t=k(new x(t),w+i+1,_)).c),t.e,"0"):(Z(e,2,S.length,"Base"),s(Q(X(t.c),i,"0"),10,e,n,!0)),n<0&&t.c[0]&&(r="-"+r)),r},t.valueOf=t.toJSON=function(){return $(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,null!=e&&x.set(e),x}();function R(e,r){var t="",n=(t=f.isBigNumber(e)?e.toFixed():"string"!=typeof e?e.toString():e,null),e=null,i=null,o=r.match(/(<=|>=|=)\s*(\d+)/);if(o&&(e=o[1],n=Number(o[2])),r.includes(",")&&(i=!0),null!==n){var o=t.split("."),r=o[0],u=1===o.length?"":o[1],l=u.length;switch(e){case"<=":u=l<=n?u:u.slice(0,n);break;case"=":l<n?u+="0".repeat(n-l):n<l&&(u=u.slice(0,n));break;case">=":u=n<=l?u:u+"0".repeat(n-l)}t=""===u?r:"".concat(r,".").concat(u)}return t=null!==i?1<(o=t.split(".")).length?((e=o[0]).includes("-")?o[0]=e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):o[0]=e.replace(/(?=(?!^)(?:\d{3})+$)/g,","),o.join(".")):(r=o[0]).includes("-")?r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):r.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function D(e){for(var r=[],t=0,n=null,i=e.length;t<i;)if(n=e[t],/\s/.test(n))t++;else if("+-".includes(n)){var o=r[r.length-1];if(0===r.length||"+-".includes(o)||"("===o){for(var u=n,n=e[++t];/[a-zA-Z\d._]/.test(n);)u+=n,n=e[++t];r.push(u)}else r.push(n),t++}else if("*/%()".includes(n))r.push(n),t++;else if(/[\w_.\[\]"']/.test(n)){for(var l="";/[\w_.\[\]"']/.test(n)&&(l+=n,!(++t>=i));)n=e[t];r.push(l)}else if(/\d/.test(n)){for(var c="";/[\d.]/.test(n)&&(c+=n,!(++t>=i));)n=e[t];r.push(c)}return r}var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},T=Array.isArray,t="object"==F(t)&&t&&t.Object===Object&&t,n="object"==("undefined"==typeof self?"undefined":F(self))&&self&&self.Object===Object&&self,t=t||n||Function("return this")(),n=t.Symbol,u=Object.prototype,B=u.hasOwnProperty,k=u.toString,s=n?n.toStringTag:void 0;var $=Object.prototype.toString;var C=function(e){var r=B.call(e,s),t=e[s];try{var n=!(e[s]=void 0)}catch(e){}var i=k.call(e);return n&&(r?e[s]=t:delete e[s]),i},te=function(e){return $.call(e)},ne=n?n.toStringTag:void 0;function ie(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":(ne&&ne in Object(e)?C:te)(e)}var oe=ie,ue=function(e){return null!=e&&"object"==F(e)};function le(e){return"symbol"==F(e)||ue(e)&&"[object Symbol]"==oe(e)}var ce=T,ae=le,fe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,se=/^\w*$/;function he(e,r){if(ce(e))return!1;var t=F(e);return!("number"!=t&&"symbol"!=t&&"boolean"!=t&&null!=e&&!ae(e))||(se.test(e)||!fe.test(e)||null!=r&&e in Object(r))}function pe(e){var r=F(e);return null!=e&&("object"==r||"function"==r)}var ge=ie,ve=pe;function de(e){return!!ve(e)&&("[object Function]"==(e=ge(e))||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e)}var u=t["__core-js_shared__"],ye=(u=/[^.]+$/.exec(u&&u.keys&&u.keys.IE_PROTO||""))?"Symbol(src)_1."+u:"";var we=Function.prototype.toString;var _e=de,be=function(e){return!!ye&&ye in e},me=pe,Oe=function(e){if(null!=e){try{return we.call(e)}catch(e){}try{return e+""}catch(e){}}return""},Ee=/^\[object .+?Constructor\]$/,u=Function.prototype,h=Object.prototype,u=u.toString,h=h.hasOwnProperty,Ne=RegExp("^"+u.call(h).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Ae=function(e){return!(!me(e)||be(e))&&(_e(e)?Ne:Ee).test(Oe(e))},Se=function(e,r){return null==e?void 0:e[r]};function je(e,r){return e=Se(e,r),Ae(e)?e:void 0}var u=je(Object,"create"),xe=u;var Pe=u,Re=Object.prototype.hasOwnProperty;var De=u,Te=Object.prototype.hasOwnProperty;var Be=u;function ke(e){return e=this.has(e)&&delete this.__data__[e],this.size-=e?1:0,e}function $e(e){var r,t=this.__data__;return Pe?"__lodash_hash_undefined__"===(r=t[e])?void 0:r:Re.call(t,e)?t[e]:void 0}function Ce(e){var r=this.__data__;return De?void 0!==r[e]:Te.call(r,e)}function Fe(e,r){var t=this.__data__;return this.size+=this.has(e)?0:1,t[e]=Be&&void 0===r?"__lodash_hash_undefined__":r,this}function p(e){var r=-1,t=null==e?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}p.prototype.clear=function(){this.__data__=xe?xe(null):{},this.size=0},p.prototype.delete=ke,p.prototype.get=$e,p.prototype.has=Ce,p.prototype.set=Fe;h=p;var Le=function(e,r){return e===r||e!=e&&r!=r};function g(e,r){for(var t=e.length;t--;)if(Le(e[t][0],r))return t;return-1}var Ue=g,ze=Array.prototype.splice;var Ie=g;var Me=g;var Ge=g;function qe(e){var r=this.__data__;return!((e=Ue(r,e))<0)&&(e==r.length-1?r.pop():ze.call(r,e,1),--this.size,!0)}function He(e){var r=this.__data__;return(e=Ie(r,e))<0?void 0:r[e][1]}function Ve(e){return-1<Me(this.__data__,e)}function We(e,r){var t=this.__data__,n=Ge(t,e);return n<0?(++this.size,t.push([e,r])):t[n][1]=r,this}function v(e){var r=-1,t=null==e?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}v.prototype.clear=function(){this.__data__=[],this.size=0},v.prototype.delete=qe,v.prototype.get=He,v.prototype.has=Ve,v.prototype.set=We;var u=v,t=je(t,"Map"),Xe=h,Ye=u,Ze=t;var Je=function(e){var r=F(e);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==e:null===e};function d(e,r){return e=e.__data__,Je(r)?e["string"==typeof r?"string":"hash"]:e.map}var Ke=d;var Qe=d;var er=d;var rr=d;function tr(e){return e=Ke(this,e).delete(e),this.size-=e?1:0,e}function nr(e){return Qe(this,e).get(e)}function ir(e){return er(this,e).has(e)}function or(e,r){var t=rr(this,e),n=t.size;return t.set(e,r),this.size+=t.size==n?0:1,this}function y(e){var r=-1,t=null==e?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}y.prototype.clear=function(){this.size=0,this.__data__={hash:new Xe,map:new(Ze||Ye),string:new Xe}},y.prototype.delete=tr,y.prototype.get=nr,y.prototype.has=ir,y.prototype.set=or;var ur=y;function lr(n,i){if("function"!=typeof n||null!=i&&"function"!=typeof i)throw new TypeError("Expected a function");function o(){var e=arguments,r=i?i.apply(this,e):e[0],t=o.cache;return t.has(r)?t.get(r):(e=n.apply(this,e),o.cache=t.set(r,e)||t,e)}return o.cache=new(lr.Cache||ur),o}lr.Cache=ur;var cr=lr;var ar=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,fr=/\\(\\)?/g,h=function(e){var r=(e=cr(e,function(e){return 500===r.size&&r.clear(),e})).cache;return e}(function(e){var i=[];return 46===e.charCodeAt(0)&&i.push(""),e.replace(ar,function(e,r,t,n){i.push(t?n.replace(fr,"$1"):r||e)}),i});var sr=function(e,r){for(var t=-1,n=null==e?0:e.length,i=Array(n);++t<n;)i[t]=r(e[t],t,e);return i},hr=T,pr=le,u=n?n.prototype:void 0,gr=u?u.toString:void 0;var vr=function e(r){if("string"==typeof r)return r;if(hr(r))return sr(r,e)+"";if(pr(r))return gr?gr.call(r):"";var t=r+"";return"0"==t&&1/r==-1/0?"-0":t};var dr=T,yr=he,wr=h,_r=function(e){return null==e?"":vr(e)};var br=le;var mr=function(e,r){return dr(e)?e:yr(e,r)?[e]:wr(_r(e))},Or=function(e){if("string"==typeof e||br(e))return e;var r=e+"";return"0"==r&&1/e==-1/0?"-0":r};var Er=function(e,r){for(var t=0,n=(r=mr(r,e)).length;null!=e&&t<n;)e=e[Or(r[t++])];return t&&t==n?e:void 0};var Nr=function(e,r,t){return void 0===(e=null==e?void 0:Er(e,r))?t:e};function w(e,r){for(var t=r._fillData,n=(void 0===r._fillData&&(t=r),Array.isArray(t)||(t=[t]),[]),i=0;i<e.length;i++){var o=e[i];if(/^[a-zA-z_][\w\[\]"'_.]*$/.test(o)){if("undefined"===o||"NaN"===o)throw new a("key不应该为:".concat(o));for(var u=null,l=0;l<t.length;l++){var c=t[l],c=Nr(c,o);if(void 0!==c){u=c;break}}if(null===u)throw new a("token填充失败,请确认".concat(o,"存在"));if("string"==typeof u){if(""===u.trim())throw new a("token填充失败,".concat(o,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(u))throw new a("token填充失败,".concat(o,"值:").concat(u,"为非法数字"))}u="string"!=typeof u?u.toString():u,n.push(u)}else n.push(o)}return n}function Ar(e){for(var r,t=[],n=[],i=e;0<i.length;){var o=i.shift();if(_(o))if("("===o)t.push(o);else if(")"===o){for(var u=t.pop();"("!==u&&0<t.length;)n.push(u),u=t.pop();if("("!==u)throw"error: unmatched ()"}else{for(;r=t[t.length-1],b(o)<=b(r)&&0<t.length;)n.push(t.pop());t.push(o)}else n.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)n.push(t.pop())}return n}function Sr(e){for(var r=[];0<e.length;){var t=e.shift();if(_(t)){if(r.length<2)throw new c("错误的栈长度, 可能是无法计算的表达式");var n=r.pop(),i=r.pop();if("string"==typeof n&&!f.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new c("".concat(n,"不是一个合法的数字"));n=new f(n)}if("string"==typeof i&&!f.isBigNumber(i)){if(!/^[+-]*[\d.]+$/.test(i))throw new c("".concat(i,"不是一个合法的数字"));i=new f(i)}switch(t){case"+":r.push(i.plus(n));break;case"-":r.push(i.minus(n));break;case"*":r.push(i.times(n));break;case"/":r.push(i.div(n));break;case"%":r.push(i.mod(n))}}else r.push(t)}if(1!==r.length)throw"unvalid expression";return r[0]}return e.calc=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=P(r),i=D(n.expr),o=null;if(null!==n.data){var u=n.data;if(null!==(o=!Array.isArray(u)&&l(u._fillData,u._error,u._fillError,u._calcError)?u:o)&&void 0!==u._fillData&&l(o._fillError,o._error))try{i=w(i,u._fillData)}catch(e){if(e instanceof a)return void 0!==o._warn&&!0===o._warn&&console.warn(e),o._fillError||o._error;throw e}else i=w(i,u)}if(u=Ar(i),(i=null)===o||void 0===o._calcError&&void 0===o._error)i=Sr(u);else try{i=Sr(u)}catch(e){if(e instanceof c)return void 0!==o._warn&&!0===o._warn&&console.warn(e),void 0!==o._calcError?o._calcError:o._error;throw e}return i=null!==n.fmt?R(i,n.fmt):null!==i?i.toFixed():null},e.fmt=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=P(r),i=D(n.expr),o=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<i.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==i.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var u=n.data;if(null!==(o=!Array.isArray(u)&&l(u._fillData,u._error,u._fillError)?u:o)&&void 0!==u._fillData&&l(o._fillError,o._error))try{i=w(i,u._fillData)}catch(e){if(e instanceof a)return void 0!==o._warn&&!0===o._warn&&console.warn(e),o._fillError||o._error;throw e}else i=w(i,u)}if(null===n.fmt)throw"表达式没有格式化部分";if(o=i[0],/^[+-]*[\d.]+$/.test(o))return R(i[0],n.fmt);throw new a("待格式化对象: ".concat(o," 不是数字"))},e.tokenizer=D,e.version="0.0.56",Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
package/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BigNumber=require("bignumber.js");function _interopDefaultLegacy(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var BigNumber__default=_interopDefaultLegacy(BigNumber);function _classCallCheck(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function _createClass(r,e,t){return e&&_defineProperties(r.prototype,e),t&&_defineProperties(r,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function _inherits(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&_setPrototypeOf(r,e)}function _getPrototypeOf(r){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function _setPrototypeOf(r,e){return(_setPrototypeOf=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function _construct(r,e,t){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);e=new(Function.bind.apply(r,n));return t&&_setPrototypeOf(e,t.prototype),e}).apply(null,arguments)}function _isNativeFunction(r){return-1!==Function.toString.call(r).indexOf("[native code]")}function _wrapNativeSuper(r){var t="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(r){if(null===r||!_isNativeFunction(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return _construct(r,arguments,_getPrototypeOf(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(e,r)})(r)}function _assertThisInitialized(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function _possibleConstructorReturn(r,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(r)}function _createSuper(t){var n=_isNativeReflectConstruct();return function(){var r,e=_getPrototypeOf(t);return _possibleConstructorReturn(this,n?(r=_getPrototypeOf(this).constructor,Reflect.construct(e,arguments,r)):e.apply(this,arguments))}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _unsupportedIterableToArray(r,e){if(r){if("string"==typeof r)return _arrayLikeToArray(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(t="Object"===t&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,e):void 0}}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function isOperator(r){return-1<"+-*/%()".indexOf(r)}function getPrioraty(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(r,e){return getPrioraty(r)<=getPrioraty(e)}function isObj(r){return"[object Object]"===Object.prototype.toString.call(r)&&!Array.isArray(r)}function anyNoUndefined(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];return e.some(function(r){return void 0!==r})}function parseArgs(r){var e={expr:"",fmt:null,data:null},t="",n=r[0];if(1===r.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<r.length){n=r[r.length-1];if(isObj(n))t=r[0],e.data=n;else for(var o=_toConsumableArray(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),t=t+i+(a="number"==typeof a?a.toString():a)}var n=t.split("|");return 1===n.length?e.expr=n[0]:(e.expr=n[0],""!==(n=n[1]).trim()&&(e.fmt=n)),e}function format(r,e){var t="",n=(t=BigNumber__default.default.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=e.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),e.includes(",")&&(o=!0),null!==n){var i=t.split("."),e=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}t=""===a?e:"".concat(e,".").concat(a)}return t=null!==o?1<(i=t.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(e=i[0]).includes("-")?e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):e.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function tokenizer(r){for(var e=[],t=0,n=null,o=r.length;t<o;)if(n=r[t],/\s/.test(n))t++;else if("+-".includes(n)){var i=e[e.length-1];if(0===e.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++t];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++t];e.push(a)}else e.push(n),t++}else if("*/%()".includes(n))e.push(n),t++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++t>=o));)n=r[t];e.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++t>=o));)n=r[t];e.push(u)}return e}var CalculatorError=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="CalculatorError",e.message=r,e}return _createClass(n)}(),TokensFillError=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="TokensFillError",e.message=r,e}return _createClass(n)}();function fillTokens(r,e){for(var t=e._fillData,n=(void 0===e._fillData&&(t=e),Array.isArray(t)||(t=[t]),[]),o=0;o<r.length;o++){var i=r[o];if(/^[a-zA-z_][\w_]*$/.test(i)){if("undefined"===i||"NaN"===i)throw new TokensFillError("key不应该为:".concat(i));for(var a=null,l=0;l<t.length;l++){var u=t[l];if(void 0!==u[i]){a=u[i];break}}if(null===a)throw new TokensFillError("token填充失败,请确认".concat(i,"存在"));if("string"==typeof a){if(""===a.trim())throw new TokensFillError("token填充失败,".concat(i,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(a))throw new TokensFillError("token填充失败,".concat(i,"值:").concat(a,"为非法数字"))}a="string"!=typeof a?a.toString():a,n.push(a)}else n.push(i)}return n}function fmt(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&anyNoUndefined(a._fillData,a._error,a._fillError)?a:i)&&void 0!==a._fillData&&anyNoUndefined(i._fillError,i._error))try{o=fillTokens(o,a._fillData)}catch(r){if(r instanceof TokensFillError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=fillTokens(o,a)}if(null===n.fmt)throw"表达式没有格式化部分";i=o[0];if(/^[+-]*[\d.]+$/.test(i))return format(o[0],n.fmt);throw new TokensFillError("待格式化对象: ".concat(i," 不是数字"))}var version="0.0.53";function token2postfix(r){for(var e=[],t=[],n=r;0<n.length;){var o=n.shift();if(isOperator(o))if("("===o)e.push(o);else if(")"===o){for(var i=e.pop();"("!==i&&0<e.length;)t.push(i),i=e.pop();if("("!==i)throw"error: unmatched ()"}else{for(;prioraty(o,e[e.length-1])&&0<e.length;)t.push(e.pop());e.push(o)}else t.push(o)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)t.push(e.pop())}return t}function evalPostfix(r){for(var e=[];0<r.length;){var t=r.shift();if(isOperator(t)){if(e.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var n=e.pop(),o=e.pop();if("string"==typeof n&&!BigNumber__default.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new CalculatorError("".concat(n,"不是一个合法的数字"));n=new BigNumber__default.default(n)}if("string"==typeof o&&!BigNumber__default.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber__default.default(o)}switch(t){case"+":e.push(o.plus(n));break;case"-":e.push(o.minus(n));break;case"*":e.push(o.times(n));break;case"/":e.push(o.div(n));break;case"%":e.push(o.mod(n))}}else e.push(t)}if(1!==e.length)throw"unvalid expression";return e[0]}function calc(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&anyNoUndefined(a._fillData,a._error,a._fillError,a._calcError)?a:i)&&void 0!==a._fillData&&anyNoUndefined(i._fillError,i._error))try{o=fillTokens(o,a._fillData)}catch(r){if(r instanceof TokensFillError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=fillTokens(o,a)}a=token2postfix(o),o=null;if(null!==i){if(void 0!==i._calcError||void 0!==i._error)try{o=evalPostfix(a)}catch(r){if(r instanceof CalculatorError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),void 0!==i._calcError?i._calcError:i._error;throw r}}else o=evalPostfix(a);return o=null!==n.fmt?format(o,n.fmt):null!==o?o.toFixed():null}exports.calc=calc,exports.fmt=fmt,exports.version=version;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BigNumber=require("bignumber.js");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var BigNumber__default=_interopDefaultLegacy(BigNumber);function isOperator(e){return-1<"+-*/%()".indexOf(e)}function getPrioraty(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(e,t){return getPrioraty(e)<=getPrioraty(t)}function isObj(e){return"[object Object]"===Object.prototype.toString.call(e)&&!Array.isArray(e)}function anyNoUndefined(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.some(function(e){return void 0!==e})}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _construct(e,t,r){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(e,t,r){var a=[null];a.push.apply(a,t);t=new(Function.bind.apply(e,a));return r&&_setPrototypeOf(t,r.prototype),t}).apply(null,arguments)}function _isNativeFunction(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function _wrapNativeSuper(e){var r="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(e){if(null===e||!_isNativeFunction(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,t)}function t(){return _construct(e,arguments,_getPrototypeOf(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(t,e)})(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _createSuper(r){var a=_isNativeReflectConstruct();return function(){var e,t=_getPrototypeOf(r);return _possibleConstructorReturn(this,a?(e=_getPrototypeOf(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}var CalculatorError=function(){_inherits(a,_wrapNativeSuper(Error));var r=_createSuper(a);function a(e){var t;return _classCallCheck(this,a),(t=r.call(this,e)).name="CalculatorError",t.message=e,t}return _createClass(a)}(),TokensFillError=function(){_inherits(a,_wrapNativeSuper(Error));var r=_createSuper(a);function a(e){var t;return _classCallCheck(this,a),(t=r.call(this,e)).name="TokensFillError",t.message=e,t}return _createClass(a)}();function parseArgs(e){var t={expr:"",fmt:null,data:null},r="",a=e[0];if(1===e.length)"string"==typeof a?r=a:"number"==typeof a?r=a.toString():Array.isArray(a)&&(r=a[0]);else if(1<e.length){a=e[e.length-1];if(!isObj(a)&&!Array.isArray(a))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(r=e[0])){if(""===r.trim())throw new TokensFillError("参数不可为空字符串")}else if("number"==typeof r)r=r.toString();else if(void 0===r||Number.isNaN(r))throw new TokensFillError("非法参数:".concat(r));t.data=a}e=r.split("|");return 1===e.length?t.expr=e[0]:(t.expr=e[0],""!==(a=e[1]).trim()&&(t.fmt=a)),null!==t.data&&null===t.fmt&&t.data._fmt&&(t.fmt=t.data._fmt),t}function format(e,t){var r="",a=(r=BigNumber__default.default.isBigNumber(e)?e.toFixed():"string"!=typeof e?e.toString():e,null),e=null,o=null,n=t.match(/(<=|>=|=)\s*(\d+)/);if(n&&(e=n[1],a=Number(n[2])),t.includes(",")&&(o=!0),null!==a){var n=r.split("."),t=n[0],i=1===n.length?"":n[1],s=i.length;switch(e){case"<=":i=s<=a?i:i.slice(0,a);break;case"=":s<a?i+="0".repeat(a-s):a<s&&(i=i.slice(0,a));break;case">=":i=a<=s?i:i+"0".repeat(a-s)}r=""===i?t:"".concat(t,".").concat(i)}return r=null!==o?1<(n=r.split(".")).length?((e=n[0]).includes("-")?n[0]=e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):n[0]=e.replace(/(?=(?!^)(?:\d{3})+$)/g,","),n.join(".")):(t=n[0]).includes("-")?t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):t.replace(/(?=(?!^)(?:\d{3})+$)/g,","):r}function tokenizer(e){for(var t=[],r=0,a=null,o=e.length;r<o;)if(a=e[r],/\s/.test(a))r++;else if("+-".includes(a)){var n=t[t.length-1];if(0===t.length||"+-".includes(n)||"("===n){for(var i=a,a=e[++r];/[a-zA-Z\d._]/.test(a);)i+=a,a=e[++r];t.push(i)}else t.push(a),r++}else if("*/%()".includes(a))t.push(a),r++;else if(/[\w_.\[\]"']/.test(a)){for(var s="";/[\w_.\[\]"']/.test(a)&&(s+=a,!(++r>=o));)a=e[r];t.push(s)}else if(/\d/.test(a)){for(var l="";/[\d.]/.test(a)&&(l+=a,!(++r>=o));)a=e[r];t.push(l)}return t}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},isArray$3=Array.isArray,isArray_1=isArray$3,freeGlobal$1="object"==_typeof(commonjsGlobal)&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_freeGlobal=freeGlobal$1,freeGlobal=freeGlobal$1,freeSelf="object"==("undefined"==typeof self?"undefined":_typeof(self))&&self&&self.Object===Object&&self,root$3=freeGlobal||freeSelf||Function("return this")(),_root=root$3,root$2=_root,_Symbol2=_root.Symbol,_Symbol$3=_Symbol2,_Symbol$2=_Symbol$3,objectProto$4=Object.prototype,hasOwnProperty$3=objectProto$4.hasOwnProperty,nativeObjectToString$1=objectProto$4.toString,symToStringTag$1=_Symbol$2?_Symbol$2.toStringTag:void 0;function getRawTag$1(e){var t=hasOwnProperty$3.call(e,symToStringTag$1),r=e[symToStringTag$1];try{var a=!(e[symToStringTag$1]=void 0)}catch(e){}var o=nativeObjectToString$1.call(e);return a&&(t?e[symToStringTag$1]=r:delete e[symToStringTag$1]),o}var _getRawTag=getRawTag$1,objectProto$3=Object.prototype,nativeObjectToString=objectProto$3.toString;function objectToString$1(e){return nativeObjectToString.call(e)}var _objectToString=objectToString$1,_Symbol$1=_Symbol$3,getRawTag=_getRawTag,objectToString=objectToString$1,nullTag="[object Null]",undefinedTag="[object Undefined]",symToStringTag=_Symbol$3?_Symbol$3.toStringTag:void 0;function baseGetTag$2(e){return null==e?void 0===e?undefinedTag:nullTag:(symToStringTag&&symToStringTag in Object(e)?getRawTag:objectToString)(e)}var _baseGetTag=baseGetTag$2;function isObjectLike$1(e){return null!=e&&"object"==_typeof(e)}var isObjectLike_1=isObjectLike$1,baseGetTag$1=baseGetTag$2,isObjectLike=isObjectLike$1,symbolTag="[object Symbol]";function isSymbol$3(e){return"symbol"==_typeof(e)||isObjectLike(e)&&baseGetTag$1(e)==symbolTag}var isSymbol_1=isSymbol$3,isArray$2=isArray_1,isSymbol$2=isSymbol_1,reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/;function isKey$1(e,t){if(isArray$2(e))return!1;var r=_typeof(e);return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!isSymbol$2(e))||(reIsPlainProp.test(e)||!reIsDeepProp.test(e)||null!=t&&e in Object(t))}var _isKey=isKey$1;function isObject$2(e){var t=_typeof(e);return null!=e&&("object"==t||"function"==t)}var isObject_1=isObject$2,baseGetTag=baseGetTag$2,isObject$1=isObject_1,asyncTag="[object AsyncFunction]",funcTag="[object Function]",genTag="[object GeneratorFunction]",proxyTag="[object Proxy]";function isFunction$1(e){if(!isObject$1(e))return!1;e=baseGetTag(e);return e==funcTag||e==genTag||e==asyncTag||e==proxyTag}var isFunction_1=isFunction$1,root$1=_root,coreJsData$1=_root["__core-js_shared__"],_coreJsData=coreJsData$1,coreJsData=coreJsData$1,maskSrcKey=function(){var e=/[^.]+$/.exec(coreJsData&&coreJsData.keys&&coreJsData.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function isMasked$1(e){return!!maskSrcKey&&maskSrcKey in e}var _isMasked=isMasked$1,funcProto$1=Function.prototype,funcToString$1=funcProto$1.toString;function toSource$1(e){if(null!=e){try{return funcToString$1.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var _toSource=toSource$1,isFunction=isFunction_1,isMasked=_isMasked,isObject=isObject_1,toSource=toSource$1,reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reIsHostCtor=/^\[object .+?Constructor\]$/,funcProto=Function.prototype,objectProto$2=Object.prototype,funcToString=funcProto.toString,hasOwnProperty$2=objectProto$2.hasOwnProperty,reIsNative=RegExp("^"+funcToString.call(hasOwnProperty$2).replace(reRegExpChar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function baseIsNative$1(e){return!(!isObject(e)||isMasked(e))&&(isFunction(e)?reIsNative:reIsHostCtor).test(toSource(e))}var _baseIsNative=baseIsNative$1;function getValue$1(e,t){return null==e?void 0:e[t]}var _getValue=getValue$1,baseIsNative=baseIsNative$1,getValue=getValue$1;function getNative$2(e,t){e=getValue(e,t);return baseIsNative(e)?e:void 0}var _getNative=getNative$2,getNative$1=_getNative,nativeCreate$4=_getNative(Object,"create"),_nativeCreate=nativeCreate$4,nativeCreate$3=_nativeCreate;function hashClear$1(){this.__data__=nativeCreate$3?nativeCreate$3(null):{},this.size=0}var _hashClear=hashClear$1;function hashDelete$1(e){e=this.has(e)&&delete this.__data__[e];return this.size-=e?1:0,e}var _hashDelete=hashDelete$1,nativeCreate$2=_nativeCreate,HASH_UNDEFINED$1="__lodash_hash_undefined__",objectProto$1=Object.prototype,hasOwnProperty$1=objectProto$1.hasOwnProperty;function hashGet$1(e){var t,r=this.__data__;return nativeCreate$2?(t=r[e])===HASH_UNDEFINED$1?void 0:t:hasOwnProperty$1.call(r,e)?r[e]:void 0}var _hashGet=hashGet$1,nativeCreate$1=_nativeCreate,objectProto=Object.prototype,hasOwnProperty=objectProto.hasOwnProperty;function hashHas$1(e){var t=this.__data__;return nativeCreate$1?void 0!==t[e]:hasOwnProperty.call(t,e)}var _hashHas=hashHas$1,nativeCreate=_nativeCreate,HASH_UNDEFINED="__lodash_hash_undefined__";function hashSet$1(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=nativeCreate&&void 0===t?HASH_UNDEFINED:t,this}var _hashSet=hashSet$1,hashClear=_hashClear,hashDelete=_hashDelete,hashGet=_hashGet,hashHas=hashHas$1,hashSet=hashSet$1;function Hash$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}Hash$1.prototype.clear=hashClear,Hash$1.prototype.delete=hashDelete,Hash$1.prototype.get=hashGet,Hash$1.prototype.has=hashHas,Hash$1.prototype.set=hashSet;var _Hash=Hash$1;function listCacheClear$1(){this.__data__=[],this.size=0}var _listCacheClear=listCacheClear$1;function eq$1(e,t){return e===t||e!=e&&t!=t}var eq_1=eq$1,eq=eq$1;function assocIndexOf$4(e,t){for(var r=e.length;r--;)if(eq(e[r][0],t))return r;return-1}var _assocIndexOf=assocIndexOf$4,assocIndexOf$3=_assocIndexOf,arrayProto=Array.prototype,splice=arrayProto.splice;function listCacheDelete$1(e){var t=this.__data__,e=assocIndexOf$3(t,e);return!(e<0)&&(e==t.length-1?t.pop():splice.call(t,e,1),--this.size,!0)}var _listCacheDelete=listCacheDelete$1,assocIndexOf$2=_assocIndexOf;function listCacheGet$1(e){var t=this.__data__,e=assocIndexOf$2(t,e);return e<0?void 0:t[e][1]}var _listCacheGet=listCacheGet$1,assocIndexOf$1=_assocIndexOf;function listCacheHas$1(e){return-1<assocIndexOf$1(this.__data__,e)}var _listCacheHas=listCacheHas$1,assocIndexOf=_assocIndexOf;function listCacheSet$1(e,t){var r=this.__data__,a=assocIndexOf(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var _listCacheSet=listCacheSet$1,listCacheClear=_listCacheClear,listCacheDelete=listCacheDelete$1,listCacheGet=listCacheGet$1,listCacheHas=listCacheHas$1,listCacheSet=listCacheSet$1;function ListCache$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}ListCache$1.prototype.clear=listCacheClear,ListCache$1.prototype.delete=listCacheDelete,ListCache$1.prototype.get=listCacheGet,ListCache$1.prototype.has=listCacheHas,ListCache$1.prototype.set=listCacheSet;var _ListCache=ListCache$1,getNative=_getNative,root=_root,Map$2=_getNative(_root,"Map"),_Map=Map$2,Hash=_Hash,ListCache=_ListCache,Map$1=Map$2;function mapCacheClear$1(){this.size=0,this.__data__={hash:new Hash,map:new(Map$1||ListCache),string:new Hash}}var _mapCacheClear=mapCacheClear$1;function isKeyable$1(e){var t=_typeof(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}var _isKeyable=isKeyable$1,isKeyable=isKeyable$1;function getMapData$4(e,t){e=e.__data__;return isKeyable(t)?e["string"==typeof t?"string":"hash"]:e.map}var _getMapData=getMapData$4,getMapData$3=getMapData$4;function mapCacheDelete$1(e){e=getMapData$3(this,e).delete(e);return this.size-=e?1:0,e}var _mapCacheDelete=mapCacheDelete$1,getMapData$2=getMapData$4;function mapCacheGet$1(e){return getMapData$2(this,e).get(e)}var _mapCacheGet=mapCacheGet$1,getMapData$1=getMapData$4;function mapCacheHas$1(e){return getMapData$1(this,e).has(e)}var _mapCacheHas=mapCacheHas$1,getMapData=getMapData$4;function mapCacheSet$1(e,t){var r=getMapData(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var _mapCacheSet=mapCacheSet$1,mapCacheClear=mapCacheClear$1,mapCacheDelete=mapCacheDelete$1,mapCacheGet=mapCacheGet$1,mapCacheHas=mapCacheHas$1,mapCacheSet=mapCacheSet$1;function MapCache$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}MapCache$1.prototype.clear=mapCacheClear,MapCache$1.prototype.delete=mapCacheDelete,MapCache$1.prototype.get=mapCacheGet,MapCache$1.prototype.has=mapCacheHas,MapCache$1.prototype.set=mapCacheSet;var _MapCache=MapCache$1,MapCache=MapCache$1,FUNC_ERROR_TEXT="Expected a function";function memoize$1(a,o){if("function"!=typeof a||null!=o&&"function"!=typeof o)throw new TypeError(FUNC_ERROR_TEXT);function n(){var e=arguments,t=o?o.apply(this,e):e[0],r=n.cache;return r.has(t)?r.get(t):(e=a.apply(this,e),n.cache=r.set(t,e)||r,e)}return n.cache=new(memoize$1.Cache||MapCache),n}memoize$1.Cache=MapCache;var memoize_1=memoize$1,memoize=memoize$1,MAX_MEMOIZE_SIZE=500;function memoizeCapped$1(e){var e=memoize(e,function(e){return t.size===MAX_MEMOIZE_SIZE&&t.clear(),e}),t=e.cache;return e}var _memoizeCapped=memoizeCapped$1,memoizeCapped=memoizeCapped$1,rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,reEscapeChar=/\\(\\)?/g,stringToPath$1=memoizeCapped$1(function(e){var o=[];return 46===e.charCodeAt(0)&&o.push(""),e.replace(rePropName,function(e,t,r,a){o.push(r?a.replace(reEscapeChar,"$1"):t||e)}),o}),_stringToPath=stringToPath$1;function arrayMap$1(e,t){for(var r=-1,a=null==e?0:e.length,o=Array(a);++r<a;)o[r]=t(e[r],r,e);return o}var _arrayMap=arrayMap$1,_Symbol=_Symbol$3,arrayMap=arrayMap$1,isArray$1=isArray_1,isSymbol$1=isSymbol_1,INFINITY$1=1/0,symbolProto=_Symbol$3?_Symbol$3.prototype:void 0,symbolToString=symbolProto?symbolProto.toString:void 0;function baseToString$1(e){if("string"==typeof e)return e;if(isArray$1(e))return arrayMap(e,baseToString$1)+"";if(isSymbol$1(e))return symbolToString?symbolToString.call(e):"";var t=e+"";return"0"==t&&1/e==-INFINITY$1?"-0":t}var _baseToString=baseToString$1,baseToString=baseToString$1;function toString$1(e){return null==e?"":baseToString(e)}var toString_1=toString$1,isArray=isArray_1,isKey=_isKey,stringToPath=_stringToPath,toString=toString$1;function castPath$1(e,t){return isArray(e)?e:isKey(e,t)?[e]:stringToPath(toString(e))}var _castPath=castPath$1,isSymbol=isSymbol_1,INFINITY=1/0;function toKey$1(e){if("string"==typeof e||isSymbol(e))return e;var t=e+"";return"0"==t&&1/e==-INFINITY?"-0":t}var _toKey=toKey$1,castPath=castPath$1,toKey=toKey$1;function baseGet$1(e,t){for(var r=0,a=(t=castPath(t,e)).length;null!=e&&r<a;)e=e[toKey(t[r++])];return r&&r==a?e:void 0}var _baseGet=baseGet$1,baseGet=baseGet$1;function get(e,t,r){e=null==e?void 0:baseGet(e,t);return void 0===e?r:e}var get_1=get;function fillTokens(e,t){for(var r=t._fillData,a=(void 0===t._fillData&&(r=t),Array.isArray(r)||(r=[r]),[]),o=0;o<e.length;o++){var n=e[o];if(/^[a-zA-z_][\w\[\]"'_.]*$/.test(n)){if("undefined"===n||"NaN"===n)throw new TokensFillError("key不应该为:".concat(n));for(var i=null,s=0;s<r.length;s++){var l=r[s],l=get_1(l,n);if(void 0!==l){i=l;break}}if(null===i)throw new TokensFillError("token填充失败,请确认".concat(n,"存在"));if("string"==typeof i){if(""===i.trim())throw new TokensFillError("token填充失败,".concat(n,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(i))throw new TokensFillError("token填充失败,".concat(n,"值:").concat(i,"为非法数字"))}i="string"!=typeof i?i.toString():i,a.push(i)}else a.push(n)}return a}function fmt(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var a=parseArgs(t),o=tokenizer(a.expr),n=null;if(""===a.expr.trim()&&null!==a.data&&void 0!==a.data._error)return a.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(a.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==a.data){var i=a.data;if(null!==(n=!Array.isArray(i)&&anyNoUndefined(i._fillData,i._error,i._fillError)?i:n)&&void 0!==i._fillData&&anyNoUndefined(n._fillError,n._error))try{o=fillTokens(o,i._fillData)}catch(e){if(e instanceof TokensFillError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),n._fillError||n._error;throw e}else o=fillTokens(o,i)}if(null===a.fmt)throw"表达式没有格式化部分";n=o[0];if(/^[+-]*[\d.]+$/.test(n))return format(o[0],a.fmt);throw new TokensFillError("待格式化对象: ".concat(n," 不是数字"))}var version="0.0.56";function token2postfix(e){for(var t=[],r=[],a=e;0<a.length;){var o=a.shift();if(isOperator(o))if("("===o)t.push(o);else if(")"===o){for(var n=t.pop();"("!==n&&0<t.length;)r.push(n),n=t.pop();if("("!==n)throw"error: unmatched ()"}else{for(;prioraty(o,t[t.length-1])&&0<t.length;)r.push(t.pop());t.push(o)}else r.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)r.push(t.pop())}return r}function evalPostfix(e){for(var t=[];0<e.length;){var r=e.shift();if(isOperator(r)){if(t.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var a=t.pop(),o=t.pop();if("string"==typeof a&&!BigNumber__default.default.isBigNumber(a)){if(!/^[+-]*[\d.]+$/.test(a))throw new CalculatorError("".concat(a,"不是一个合法的数字"));a=new BigNumber__default.default(a)}if("string"==typeof o&&!BigNumber__default.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber__default.default(o)}switch(r){case"+":t.push(o.plus(a));break;case"-":t.push(o.minus(a));break;case"*":t.push(o.times(a));break;case"/":t.push(o.div(a));break;case"%":t.push(o.mod(a))}}else t.push(r)}if(1!==t.length)throw"unvalid expression";return t[0]}function calc(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var a=parseArgs(t),o=tokenizer(a.expr),n=null;if(null!==a.data){var i=a.data;if(null!==(n=!Array.isArray(i)&&anyNoUndefined(i._fillData,i._error,i._fillError,i._calcError)?i:n)&&void 0!==i._fillData&&anyNoUndefined(n._fillError,n._error))try{o=fillTokens(o,i._fillData)}catch(e){if(e instanceof TokensFillError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),n._fillError||n._error;throw e}else o=fillTokens(o,i)}i=token2postfix(o),o=null;if(null===n||void 0===n._calcError&&void 0===n._error)o=evalPostfix(i);else try{o=evalPostfix(i)}catch(e){if(e instanceof CalculatorError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),void 0!==n._calcError?n._calcError:n._error;throw e}return o=null!==a.fmt?format(o,a.fmt):null!==o?o.toFixed():null}exports.calc=calc,exports.fmt=fmt,exports.tokenizer=tokenizer,exports.version=version;
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import BigNumber from"bignumber.js";function _classCallCheck(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function _createClass(r,e,t){return e&&_defineProperties(r.prototype,e),t&&_defineProperties(r,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function _inherits(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&_setPrototypeOf(r,e)}function _getPrototypeOf(r){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function _setPrototypeOf(r,e){return(_setPrototypeOf=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(r){return!1}}function _construct(r,e,t){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);e=new(Function.bind.apply(r,n));return t&&_setPrototypeOf(e,t.prototype),e}).apply(null,arguments)}function _isNativeFunction(r){return-1!==Function.toString.call(r).indexOf("[native code]")}function _wrapNativeSuper(r){var t="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(r){if(null===r||!_isNativeFunction(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return _construct(r,arguments,_getPrototypeOf(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(e,r)})(r)}function _assertThisInitialized(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function _possibleConstructorReturn(r,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(r)}function _createSuper(t){var n=_isNativeReflectConstruct();return function(){var r,e=_getPrototypeOf(t);return _possibleConstructorReturn(this,n?(r=_getPrototypeOf(this).constructor,Reflect.construct(e,arguments,r)):e.apply(this,arguments))}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _unsupportedIterableToArray(r,e){if(r){if("string"==typeof r)return _arrayLikeToArray(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Map"===(t="Object"===t&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,e):void 0}}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function isOperator(r){return-1<"+-*/%()".indexOf(r)}function getPrioraty(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(r,e){return getPrioraty(r)<=getPrioraty(e)}function isObj(r){return"[object Object]"===Object.prototype.toString.call(r)&&!Array.isArray(r)}function anyNoUndefined(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];return e.some(function(r){return void 0!==r})}function parseArgs(r){var e={expr:"",fmt:null,data:null},t="",n=r[0];if(1===r.length)"string"==typeof n?t=n:"number"==typeof n?t=n.toString():Array.isArray(n)&&(t=n[0]);else if(1<r.length){n=r[r.length-1];if(isObj(n))t=r[0],e.data=n;else for(var o=_toConsumableArray(r.shift());o.length||r.length;)var i=0===o.length?"":o.shift(),a=0===r.length?"":r.shift(),t=t+i+(a="number"==typeof a?a.toString():a)}var n=t.split("|");return 1===n.length?e.expr=n[0]:(e.expr=n[0],""!==(n=n[1]).trim()&&(e.fmt=n)),e}function format(r,e){var t="",n=(t=BigNumber.isBigNumber(r)?r.toFixed():"string"!=typeof r?r.toString():r,null),r=null,o=null,i=e.match(/(<=|>=|=)\s*(\d+)/);if(i&&(r=i[1],n=Number(i[2])),e.includes(",")&&(o=!0),null!==n){var i=t.split("."),e=i[0],a=1===i.length?"":i[1],l=a.length;switch(r){case"<=":a=l<=n?a:a.slice(0,n);break;case"=":l<n?a+="0".repeat(n-l):n<l&&(a=a.slice(0,n));break;case">=":a=n<=l?a:a+"0".repeat(n-l)}t=""===a?e:"".concat(e,".").concat(a)}return t=null!==o?1<(i=t.split(".")).length?((r=i[0]).includes("-")?i[0]=r[0]+r.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):i[0]=r.replace(/(?=(?!^)(?:\d{3})+$)/g,","),i.join(".")):(e=i[0]).includes("-")?e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):e.replace(/(?=(?!^)(?:\d{3})+$)/g,","):t}function tokenizer(r){for(var e=[],t=0,n=null,o=r.length;t<o;)if(n=r[t],/\s/.test(n))t++;else if("+-".includes(n)){var i=e[e.length-1];if(0===e.length||"+-".includes(i)||"("===i){for(var a=n,n=r[++t];/[a-zA-Z\d._]/.test(n);)a+=n,n=r[++t];e.push(a)}else e.push(n),t++}else if("*/%()".includes(n))e.push(n),t++;else if(/[a-zA-Z_]/.test(n)){for(var l="";/[a-zA-Z0-9_]/.test(n)&&(l+=n,!(++t>=o));)n=r[t];e.push(l)}else if(/\d/.test(n)){for(var u="";/[\d.]/.test(n)&&(u+=n,!(++t>=o));)n=r[t];e.push(u)}return e}var CalculatorError=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="CalculatorError",e.message=r,e}return _createClass(n)}(),TokensFillError=function(){_inherits(n,_wrapNativeSuper(Error));var t=_createSuper(n);function n(r){var e;return _classCallCheck(this,n),(e=t.call(this,r)).name="TokensFillError",e.message=r,e}return _createClass(n)}();function fillTokens(r,e){for(var t=e._fillData,n=(void 0===e._fillData&&(t=e),Array.isArray(t)||(t=[t]),[]),o=0;o<r.length;o++){var i=r[o];if(/^[a-zA-z_][\w_]*$/.test(i)){if("undefined"===i||"NaN"===i)throw new TokensFillError("key不应该为:".concat(i));for(var a=null,l=0;l<t.length;l++){var u=t[l];if(void 0!==u[i]){a=u[i];break}}if(null===a)throw new TokensFillError("token填充失败,请确认".concat(i,"存在"));if("string"==typeof a){if(""===a.trim())throw new TokensFillError("token填充失败,".concat(i,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(a))throw new TokensFillError("token填充失败,".concat(i,"值:").concat(a,"为非法数字"))}a="string"!=typeof a?a.toString():a,n.push(a)}else n.push(i)}return n}function fmt(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(""===n.expr.trim()&&null!==n.data&&void 0!==n.data._error)return n.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(n.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&anyNoUndefined(a._fillData,a._error,a._fillError)?a:i)&&void 0!==a._fillData&&anyNoUndefined(i._fillError,i._error))try{o=fillTokens(o,a._fillData)}catch(r){if(r instanceof TokensFillError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=fillTokens(o,a)}if(null===n.fmt)throw"表达式没有格式化部分";i=o[0];if(/^[+-]*[\d.]+$/.test(i))return format(o[0],n.fmt);throw new TokensFillError("待格式化对象: ".concat(i," 不是数字"))}var version="0.0.53";function token2postfix(r){for(var e=[],t=[],n=r;0<n.length;){var o=n.shift();if(isOperator(o))if("("===o)e.push(o);else if(")"===o){for(var i=e.pop();"("!==i&&0<e.length;)t.push(i),i=e.pop();if("("!==i)throw"error: unmatched ()"}else{for(;prioraty(o,e[e.length-1])&&0<e.length;)t.push(e.pop());e.push(o)}else t.push(o)}if(0<e.length){if(")"===e[e.length-1]||"("===e[e.length-1])throw"error: unmatched ()";for(;0<e.length;)t.push(e.pop())}return t}function evalPostfix(r){for(var e=[];0<r.length;){var t=r.shift();if(isOperator(t)){if(e.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var n=e.pop(),o=e.pop();if("string"==typeof n&&!BigNumber.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new CalculatorError("".concat(n,"不是一个合法的数字"));n=new BigNumber(n)}if("string"==typeof o&&!BigNumber.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber(o)}switch(t){case"+":e.push(o.plus(n));break;case"-":e.push(o.minus(n));break;case"*":e.push(o.times(n));break;case"/":e.push(o.div(n));break;case"%":e.push(o.mod(n))}}else e.push(t)}if(1!==e.length)throw"unvalid expression";return e[0]}function calc(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=parseArgs(e),o=tokenizer(n.expr),i=null;if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&anyNoUndefined(a._fillData,a._error,a._fillError,a._calcError)?a:i)&&void 0!==a._fillData&&anyNoUndefined(i._fillError,i._error))try{o=fillTokens(o,a._fillData)}catch(r){if(r instanceof TokensFillError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=fillTokens(o,a)}a=token2postfix(o),o=null;if(null!==i){if(void 0!==i._calcError||void 0!==i._error)try{o=evalPostfix(a)}catch(r){if(r instanceof CalculatorError)return void 0!==i._warn&&!0===i._warn&&console.warn(r),void 0!==i._calcError?i._calcError:i._error;throw r}}else o=evalPostfix(a);return o=null!==n.fmt?format(o,n.fmt):null!==o?o.toFixed():null}export{calc,fmt,version};
|
|
1
|
+
import BigNumber from"bignumber.js";function isOperator(e){return-1<"+-*/%()".indexOf(e)}function getPrioraty(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function prioraty(e,t){return getPrioraty(e)<=getPrioraty(t)}function isObj(e){return"[object Object]"===Object.prototype.toString.call(e)&&!Array.isArray(e)}function anyNoUndefined(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.some(function(e){return void 0!==e})}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _construct(e,t,r){return(_construct=_isNativeReflectConstruct()?Reflect.construct:function(e,t,r){var a=[null];a.push.apply(a,t);t=new(Function.bind.apply(e,a));return r&&_setPrototypeOf(t,r.prototype),t}).apply(null,arguments)}function _isNativeFunction(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function _wrapNativeSuper(e){var r="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(e){if(null===e||!_isNativeFunction(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,t)}function t(){return _construct(e,arguments,_getPrototypeOf(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(t,e)})(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _createSuper(r){var a=_isNativeReflectConstruct();return function(){var e,t=_getPrototypeOf(r);return _possibleConstructorReturn(this,a?(e=_getPrototypeOf(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}var CalculatorError=function(){_inherits(a,_wrapNativeSuper(Error));var r=_createSuper(a);function a(e){var t;return _classCallCheck(this,a),(t=r.call(this,e)).name="CalculatorError",t.message=e,t}return _createClass(a)}(),TokensFillError=function(){_inherits(a,_wrapNativeSuper(Error));var r=_createSuper(a);function a(e){var t;return _classCallCheck(this,a),(t=r.call(this,e)).name="TokensFillError",t.message=e,t}return _createClass(a)}();function parseArgs(e){var t={expr:"",fmt:null,data:null},r="",a=e[0];if(1===e.length)"string"==typeof a?r=a:"number"==typeof a?r=a.toString():Array.isArray(a)&&(r=a[0]);else if(1<e.length){a=e[e.length-1];if(!isObj(a)&&!Array.isArray(a))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(r=e[0])){if(""===r.trim())throw new TokensFillError("参数不可为空字符串")}else if("number"==typeof r)r=r.toString();else if(void 0===r||Number.isNaN(r))throw new TokensFillError("非法参数:".concat(r));t.data=a}e=r.split("|");return 1===e.length?t.expr=e[0]:(t.expr=e[0],""!==(a=e[1]).trim()&&(t.fmt=a)),null!==t.data&&null===t.fmt&&t.data._fmt&&(t.fmt=t.data._fmt),t}function format(e,t){var r="",a=(r=BigNumber.isBigNumber(e)?e.toFixed():"string"!=typeof e?e.toString():e,null),e=null,o=null,n=t.match(/(<=|>=|=)\s*(\d+)/);if(n&&(e=n[1],a=Number(n[2])),t.includes(",")&&(o=!0),null!==a){var n=r.split("."),t=n[0],i=1===n.length?"":n[1],s=i.length;switch(e){case"<=":i=s<=a?i:i.slice(0,a);break;case"=":s<a?i+="0".repeat(a-s):a<s&&(i=i.slice(0,a));break;case">=":i=a<=s?i:i+"0".repeat(a-s)}r=""===i?t:"".concat(t,".").concat(i)}return r=null!==o?1<(n=r.split(".")).length?((e=n[0]).includes("-")?n[0]=e[0]+e.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):n[0]=e.replace(/(?=(?!^)(?:\d{3})+$)/g,","),n.join(".")):(t=n[0]).includes("-")?t[0]+t.slice(1).replace(/(?=(?!^)(?:\d{3})+$)/g,","):t.replace(/(?=(?!^)(?:\d{3})+$)/g,","):r}function tokenizer(e){for(var t=[],r=0,a=null,o=e.length;r<o;)if(a=e[r],/\s/.test(a))r++;else if("+-".includes(a)){var n=t[t.length-1];if(0===t.length||"+-".includes(n)||"("===n){for(var i=a,a=e[++r];/[a-zA-Z\d._]/.test(a);)i+=a,a=e[++r];t.push(i)}else t.push(a),r++}else if("*/%()".includes(a))t.push(a),r++;else if(/[\w_.\[\]"']/.test(a)){for(var s="";/[\w_.\[\]"']/.test(a)&&(s+=a,!(++r>=o));)a=e[r];t.push(s)}else if(/\d/.test(a)){for(var c="";/[\d.]/.test(a)&&(c+=a,!(++r>=o));)a=e[r];t.push(c)}return t}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},isArray$3=Array.isArray,isArray_1=isArray$3,freeGlobal$1="object"==_typeof(commonjsGlobal)&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_freeGlobal=freeGlobal$1,freeGlobal=freeGlobal$1,freeSelf="object"==("undefined"==typeof self?"undefined":_typeof(self))&&self&&self.Object===Object&&self,root$3=freeGlobal||freeSelf||Function("return this")(),_root=root$3,root$2=_root,_Symbol2=_root.Symbol,_Symbol$3=_Symbol2,_Symbol$2=_Symbol$3,objectProto$4=Object.prototype,hasOwnProperty$3=objectProto$4.hasOwnProperty,nativeObjectToString$1=objectProto$4.toString,symToStringTag$1=_Symbol$2?_Symbol$2.toStringTag:void 0;function getRawTag$1(e){var t=hasOwnProperty$3.call(e,symToStringTag$1),r=e[symToStringTag$1];try{var a=!(e[symToStringTag$1]=void 0)}catch(e){}var o=nativeObjectToString$1.call(e);return a&&(t?e[symToStringTag$1]=r:delete e[symToStringTag$1]),o}var _getRawTag=getRawTag$1,objectProto$3=Object.prototype,nativeObjectToString=objectProto$3.toString;function objectToString$1(e){return nativeObjectToString.call(e)}var _objectToString=objectToString$1,_Symbol$1=_Symbol$3,getRawTag=_getRawTag,objectToString=objectToString$1,nullTag="[object Null]",undefinedTag="[object Undefined]",symToStringTag=_Symbol$3?_Symbol$3.toStringTag:void 0;function baseGetTag$2(e){return null==e?void 0===e?undefinedTag:nullTag:(symToStringTag&&symToStringTag in Object(e)?getRawTag:objectToString)(e)}var _baseGetTag=baseGetTag$2;function isObjectLike$1(e){return null!=e&&"object"==_typeof(e)}var isObjectLike_1=isObjectLike$1,baseGetTag$1=baseGetTag$2,isObjectLike=isObjectLike$1,symbolTag="[object Symbol]";function isSymbol$3(e){return"symbol"==_typeof(e)||isObjectLike(e)&&baseGetTag$1(e)==symbolTag}var isSymbol_1=isSymbol$3,isArray$2=isArray_1,isSymbol$2=isSymbol_1,reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/;function isKey$1(e,t){if(isArray$2(e))return!1;var r=_typeof(e);return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!isSymbol$2(e))||(reIsPlainProp.test(e)||!reIsDeepProp.test(e)||null!=t&&e in Object(t))}var _isKey=isKey$1;function isObject$2(e){var t=_typeof(e);return null!=e&&("object"==t||"function"==t)}var isObject_1=isObject$2,baseGetTag=baseGetTag$2,isObject$1=isObject_1,asyncTag="[object AsyncFunction]",funcTag="[object Function]",genTag="[object GeneratorFunction]",proxyTag="[object Proxy]";function isFunction$1(e){if(!isObject$1(e))return!1;e=baseGetTag(e);return e==funcTag||e==genTag||e==asyncTag||e==proxyTag}var isFunction_1=isFunction$1,root$1=_root,coreJsData$1=_root["__core-js_shared__"],_coreJsData=coreJsData$1,coreJsData=coreJsData$1,maskSrcKey=function(){var e=/[^.]+$/.exec(coreJsData&&coreJsData.keys&&coreJsData.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function isMasked$1(e){return!!maskSrcKey&&maskSrcKey in e}var _isMasked=isMasked$1,funcProto$1=Function.prototype,funcToString$1=funcProto$1.toString;function toSource$1(e){if(null!=e){try{return funcToString$1.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var _toSource=toSource$1,isFunction=isFunction_1,isMasked=_isMasked,isObject=isObject_1,toSource=toSource$1,reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reIsHostCtor=/^\[object .+?Constructor\]$/,funcProto=Function.prototype,objectProto$2=Object.prototype,funcToString=funcProto.toString,hasOwnProperty$2=objectProto$2.hasOwnProperty,reIsNative=RegExp("^"+funcToString.call(hasOwnProperty$2).replace(reRegExpChar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function baseIsNative$1(e){return!(!isObject(e)||isMasked(e))&&(isFunction(e)?reIsNative:reIsHostCtor).test(toSource(e))}var _baseIsNative=baseIsNative$1;function getValue$1(e,t){return null==e?void 0:e[t]}var _getValue=getValue$1,baseIsNative=baseIsNative$1,getValue=getValue$1;function getNative$2(e,t){e=getValue(e,t);return baseIsNative(e)?e:void 0}var _getNative=getNative$2,getNative$1=_getNative,nativeCreate$4=_getNative(Object,"create"),_nativeCreate=nativeCreate$4,nativeCreate$3=_nativeCreate;function hashClear$1(){this.__data__=nativeCreate$3?nativeCreate$3(null):{},this.size=0}var _hashClear=hashClear$1;function hashDelete$1(e){e=this.has(e)&&delete this.__data__[e];return this.size-=e?1:0,e}var _hashDelete=hashDelete$1,nativeCreate$2=_nativeCreate,HASH_UNDEFINED$1="__lodash_hash_undefined__",objectProto$1=Object.prototype,hasOwnProperty$1=objectProto$1.hasOwnProperty;function hashGet$1(e){var t,r=this.__data__;return nativeCreate$2?(t=r[e])===HASH_UNDEFINED$1?void 0:t:hasOwnProperty$1.call(r,e)?r[e]:void 0}var _hashGet=hashGet$1,nativeCreate$1=_nativeCreate,objectProto=Object.prototype,hasOwnProperty=objectProto.hasOwnProperty;function hashHas$1(e){var t=this.__data__;return nativeCreate$1?void 0!==t[e]:hasOwnProperty.call(t,e)}var _hashHas=hashHas$1,nativeCreate=_nativeCreate,HASH_UNDEFINED="__lodash_hash_undefined__";function hashSet$1(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=nativeCreate&&void 0===t?HASH_UNDEFINED:t,this}var _hashSet=hashSet$1,hashClear=_hashClear,hashDelete=_hashDelete,hashGet=_hashGet,hashHas=hashHas$1,hashSet=hashSet$1;function Hash$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}Hash$1.prototype.clear=hashClear,Hash$1.prototype.delete=hashDelete,Hash$1.prototype.get=hashGet,Hash$1.prototype.has=hashHas,Hash$1.prototype.set=hashSet;var _Hash=Hash$1;function listCacheClear$1(){this.__data__=[],this.size=0}var _listCacheClear=listCacheClear$1;function eq$1(e,t){return e===t||e!=e&&t!=t}var eq_1=eq$1,eq=eq$1;function assocIndexOf$4(e,t){for(var r=e.length;r--;)if(eq(e[r][0],t))return r;return-1}var _assocIndexOf=assocIndexOf$4,assocIndexOf$3=_assocIndexOf,arrayProto=Array.prototype,splice=arrayProto.splice;function listCacheDelete$1(e){var t=this.__data__,e=assocIndexOf$3(t,e);return!(e<0)&&(e==t.length-1?t.pop():splice.call(t,e,1),--this.size,!0)}var _listCacheDelete=listCacheDelete$1,assocIndexOf$2=_assocIndexOf;function listCacheGet$1(e){var t=this.__data__,e=assocIndexOf$2(t,e);return e<0?void 0:t[e][1]}var _listCacheGet=listCacheGet$1,assocIndexOf$1=_assocIndexOf;function listCacheHas$1(e){return-1<assocIndexOf$1(this.__data__,e)}var _listCacheHas=listCacheHas$1,assocIndexOf=_assocIndexOf;function listCacheSet$1(e,t){var r=this.__data__,a=assocIndexOf(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var _listCacheSet=listCacheSet$1,listCacheClear=_listCacheClear,listCacheDelete=listCacheDelete$1,listCacheGet=listCacheGet$1,listCacheHas=listCacheHas$1,listCacheSet=listCacheSet$1;function ListCache$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}ListCache$1.prototype.clear=listCacheClear,ListCache$1.prototype.delete=listCacheDelete,ListCache$1.prototype.get=listCacheGet,ListCache$1.prototype.has=listCacheHas,ListCache$1.prototype.set=listCacheSet;var _ListCache=ListCache$1,getNative=_getNative,root=_root,Map$2=_getNative(_root,"Map"),_Map=Map$2,Hash=_Hash,ListCache=_ListCache,Map$1=Map$2;function mapCacheClear$1(){this.size=0,this.__data__={hash:new Hash,map:new(Map$1||ListCache),string:new Hash}}var _mapCacheClear=mapCacheClear$1;function isKeyable$1(e){var t=_typeof(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}var _isKeyable=isKeyable$1,isKeyable=isKeyable$1;function getMapData$4(e,t){e=e.__data__;return isKeyable(t)?e["string"==typeof t?"string":"hash"]:e.map}var _getMapData=getMapData$4,getMapData$3=getMapData$4;function mapCacheDelete$1(e){e=getMapData$3(this,e).delete(e);return this.size-=e?1:0,e}var _mapCacheDelete=mapCacheDelete$1,getMapData$2=getMapData$4;function mapCacheGet$1(e){return getMapData$2(this,e).get(e)}var _mapCacheGet=mapCacheGet$1,getMapData$1=getMapData$4;function mapCacheHas$1(e){return getMapData$1(this,e).has(e)}var _mapCacheHas=mapCacheHas$1,getMapData=getMapData$4;function mapCacheSet$1(e,t){var r=getMapData(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var _mapCacheSet=mapCacheSet$1,mapCacheClear=mapCacheClear$1,mapCacheDelete=mapCacheDelete$1,mapCacheGet=mapCacheGet$1,mapCacheHas=mapCacheHas$1,mapCacheSet=mapCacheSet$1;function MapCache$1(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}MapCache$1.prototype.clear=mapCacheClear,MapCache$1.prototype.delete=mapCacheDelete,MapCache$1.prototype.get=mapCacheGet,MapCache$1.prototype.has=mapCacheHas,MapCache$1.prototype.set=mapCacheSet;var _MapCache=MapCache$1,MapCache=MapCache$1,FUNC_ERROR_TEXT="Expected a function";function memoize$1(a,o){if("function"!=typeof a||null!=o&&"function"!=typeof o)throw new TypeError(FUNC_ERROR_TEXT);function n(){var e=arguments,t=o?o.apply(this,e):e[0],r=n.cache;return r.has(t)?r.get(t):(e=a.apply(this,e),n.cache=r.set(t,e)||r,e)}return n.cache=new(memoize$1.Cache||MapCache),n}memoize$1.Cache=MapCache;var memoize_1=memoize$1,memoize=memoize$1,MAX_MEMOIZE_SIZE=500;function memoizeCapped$1(e){var e=memoize(e,function(e){return t.size===MAX_MEMOIZE_SIZE&&t.clear(),e}),t=e.cache;return e}var _memoizeCapped=memoizeCapped$1,memoizeCapped=memoizeCapped$1,rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,reEscapeChar=/\\(\\)?/g,stringToPath$1=memoizeCapped$1(function(e){var o=[];return 46===e.charCodeAt(0)&&o.push(""),e.replace(rePropName,function(e,t,r,a){o.push(r?a.replace(reEscapeChar,"$1"):t||e)}),o}),_stringToPath=stringToPath$1;function arrayMap$1(e,t){for(var r=-1,a=null==e?0:e.length,o=Array(a);++r<a;)o[r]=t(e[r],r,e);return o}var _arrayMap=arrayMap$1,_Symbol=_Symbol$3,arrayMap=arrayMap$1,isArray$1=isArray_1,isSymbol$1=isSymbol_1,INFINITY$1=1/0,symbolProto=_Symbol$3?_Symbol$3.prototype:void 0,symbolToString=symbolProto?symbolProto.toString:void 0;function baseToString$1(e){if("string"==typeof e)return e;if(isArray$1(e))return arrayMap(e,baseToString$1)+"";if(isSymbol$1(e))return symbolToString?symbolToString.call(e):"";var t=e+"";return"0"==t&&1/e==-INFINITY$1?"-0":t}var _baseToString=baseToString$1,baseToString=baseToString$1;function toString$1(e){return null==e?"":baseToString(e)}var toString_1=toString$1,isArray=isArray_1,isKey=_isKey,stringToPath=_stringToPath,toString=toString$1;function castPath$1(e,t){return isArray(e)?e:isKey(e,t)?[e]:stringToPath(toString(e))}var _castPath=castPath$1,isSymbol=isSymbol_1,INFINITY=1/0;function toKey$1(e){if("string"==typeof e||isSymbol(e))return e;var t=e+"";return"0"==t&&1/e==-INFINITY?"-0":t}var _toKey=toKey$1,castPath=castPath$1,toKey=toKey$1;function baseGet$1(e,t){for(var r=0,a=(t=castPath(t,e)).length;null!=e&&r<a;)e=e[toKey(t[r++])];return r&&r==a?e:void 0}var _baseGet=baseGet$1,baseGet=baseGet$1;function get(e,t,r){e=null==e?void 0:baseGet(e,t);return void 0===e?r:e}var get_1=get;function fillTokens(e,t){for(var r=t._fillData,a=(void 0===t._fillData&&(r=t),Array.isArray(r)||(r=[r]),[]),o=0;o<e.length;o++){var n=e[o];if(/^[a-zA-z_][\w\[\]"'_.]*$/.test(n)){if("undefined"===n||"NaN"===n)throw new TokensFillError("key不应该为:".concat(n));for(var i=null,s=0;s<r.length;s++){var c=r[s],c=get_1(c,n);if(void 0!==c){i=c;break}}if(null===i)throw new TokensFillError("token填充失败,请确认".concat(n,"存在"));if("string"==typeof i){if(""===i.trim())throw new TokensFillError("token填充失败,".concat(n,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(i))throw new TokensFillError("token填充失败,".concat(n,"值:").concat(i,"为非法数字"))}i="string"!=typeof i?i.toString():i,a.push(i)}else a.push(n)}return a}function fmt(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var a=parseArgs(t),o=tokenizer(a.expr),n=null;if(""===a.expr.trim()&&null!==a.data&&void 0!==a.data._error)return a.data._error;if(2<o.length)throw new Error("fmt并非用于计算, 不能传入多个标识:".concat(a.expr));if(1!==o.length)throw new Error("fmt接收了一个无法被解析的标识");if(null!==a.data){var i=a.data;if(null!==(n=!Array.isArray(i)&&anyNoUndefined(i._fillData,i._error,i._fillError)?i:n)&&void 0!==i._fillData&&anyNoUndefined(n._fillError,n._error))try{o=fillTokens(o,i._fillData)}catch(e){if(e instanceof TokensFillError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),n._fillError||n._error;throw e}else o=fillTokens(o,i)}if(null===a.fmt)throw"表达式没有格式化部分";n=o[0];if(/^[+-]*[\d.]+$/.test(n))return format(o[0],a.fmt);throw new TokensFillError("待格式化对象: ".concat(n," 不是数字"))}var version="0.0.56";function token2postfix(e){for(var t=[],r=[],a=e;0<a.length;){var o=a.shift();if(isOperator(o))if("("===o)t.push(o);else if(")"===o){for(var n=t.pop();"("!==n&&0<t.length;)r.push(n),n=t.pop();if("("!==n)throw"error: unmatched ()"}else{for(;prioraty(o,t[t.length-1])&&0<t.length;)r.push(t.pop());t.push(o)}else r.push(o)}if(0<t.length){if(")"===t[t.length-1]||"("===t[t.length-1])throw"error: unmatched ()";for(;0<t.length;)r.push(t.pop())}return r}function evalPostfix(e){for(var t=[];0<e.length;){var r=e.shift();if(isOperator(r)){if(t.length<2)throw new CalculatorError("错误的栈长度, 可能是无法计算的表达式");var a=t.pop(),o=t.pop();if("string"==typeof a&&!BigNumber.isBigNumber(a)){if(!/^[+-]*[\d.]+$/.test(a))throw new CalculatorError("".concat(a,"不是一个合法的数字"));a=new BigNumber(a)}if("string"==typeof o&&!BigNumber.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new CalculatorError("".concat(o,"不是一个合法的数字"));o=new BigNumber(o)}switch(r){case"+":t.push(o.plus(a));break;case"-":t.push(o.minus(a));break;case"*":t.push(o.times(a));break;case"/":t.push(o.div(a));break;case"%":t.push(o.mod(a))}}else t.push(r)}if(1!==t.length)throw"unvalid expression";return t[0]}function calc(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var a=parseArgs(t),o=tokenizer(a.expr),n=null;if(null!==a.data){var i=a.data;if(null!==(n=!Array.isArray(i)&&anyNoUndefined(i._fillData,i._error,i._fillError,i._calcError)?i:n)&&void 0!==i._fillData&&anyNoUndefined(n._fillError,n._error))try{o=fillTokens(o,i._fillData)}catch(e){if(e instanceof TokensFillError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),n._fillError||n._error;throw e}else o=fillTokens(o,i)}i=token2postfix(o),o=null;if(null===n||void 0===n._calcError&&void 0===n._error)o=evalPostfix(i);else try{o=evalPostfix(i)}catch(e){if(e instanceof CalculatorError)return void 0!==n._warn&&!0===n._warn&&console.warn(e),void 0!==n._calcError?n._calcError:n._error;throw e}return o=null!==a.fmt?format(o,a.fmt):null!==o?o.toFixed():null}export{calc,fmt,tokenizer,version};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a-calc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "JavaScript的字符串四则运算库, 支持格式化操作例如: 千分位格式化, 灵活指定小数点位数",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"ava": "^4.2.0",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
62
|
"glob": "^8.0.1",
|
|
63
|
+
"lodash": "^4.17.21",
|
|
63
64
|
"npm-run-all": "^4.1.5",
|
|
64
65
|
"rollup": "^2.70.2",
|
|
65
66
|
"rollup-plugin-livereload": "^2.0.5",
|