a-calc 0.0.54 → 0.0.55
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 +5 -2
- package/browser/index.core.js +1 -1
- package/browser/index.html +39 -21
- package/browser/index.js +1 -1
- package/cjs/index.js +1 -1
- package/es/index.js +1 -1
- package/package.json +1 -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,11 @@ 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
|
|
59
62
|
```
|
|
60
63
|
|
|
61
64
|
## 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&&
|
|
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 l(r){return-1<"+-*/%()".indexOf(r)}function f(r){switch(r){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function c(){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 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&&p(r,t)}function s(r){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function p(r,t){return(p=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}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(r){return!1}}function d(r,t,e){return(d=h()?Reflect.construct:function(r,t,e){var n=[null];n.push.apply(n,t);t=new(Function.bind.apply(r,n));return e&&p(t,e.prototype),t}).apply(null,arguments)}function w(r){var e="function"==typeof Map?new Map:void 0;return(w=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 d(r,arguments,s(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),p(t,r)})(r)}function y(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 v(e){var n=h();return function(){var r,t=s(e);return y(this,n?(r=s(this).constructor,Reflect.construct(t,arguments,r)):t.apply(this,arguments))}}var g=function(){a(n,w(Error));var e=v(n);function n(r){var t;return o(this,n),(t=e.call(this,r)).name="CalculatorError",t.message=r,t}return i(n)}(),_=function(){a(n,w(Error));var e=v(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 b(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(o=n,("[object Object]"!==Object.prototype.toString.call(o)||Array.isArray(o))&&!Array.isArray(n))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(e=r[0])){if(""===e.trim())throw new _("参数不可为空字符串")}else if("number"==typeof e)e=e.toString();else if(void 0===e||Number.isNaN(e))throw new _("非法参数:".concat(e));t.data=n}var o=e.split("|");return 1===o.length?t.expr=o[0]:(t.expr=o[0],""!==(r=o[1]).trim()&&(t.fmt=r)),null!==t.data&&null===t.fmt&&t.data._fmt&&(t.fmt=t.data._fmt),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 E(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}function A(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 _("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 _("token填充失败,请确认".concat(i,"存在"));if("string"==typeof a){if(""===a.trim())throw new _("token填充失败,".concat(i,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(a))throw new _("token填充失败,".concat(i,"值:").concat(a,"为非法数字"))}a="string"!=typeof a?a.toString():a,n.push(a)}else n.push(i)}return n}function O(r){for(var t,e=[],n=[],o=r;0<o.length;){var i=o.shift();if(l(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],f(i)<=f(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 j(r){for(var t=[];0<r.length;){var e=r.shift();if(l(e)){if(t.length<2)throw new g("错误的栈长度, 可能是无法计算的表达式");var n=t.pop(),o=t.pop();if("string"==typeof n&&!u.default.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new g("".concat(n,"不是一个合法的数字"));n=new u.default(n)}if("string"==typeof o&&!u.default.isBigNumber(o)){if(!/^[+-]*[\d.]+$/.test(o))throw new g("".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=b(t),o=E(n.expr),i=null;if(null!==n.data){var a=n.data;if(null!==(i=!Array.isArray(a)&&c(a._fillData,a._error,a._fillError,a._calcError)?a:i)&&void 0!==a._fillData&&c(i._fillError,i._error))try{o=A(o,a._fillData)}catch(r){if(r instanceof _)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=A(o,a)}if(a=O(o),(o=null)===i||void 0===i._calcError&&void 0===i._error)o=j(a);else try{o=j(a)}catch(r){if(r instanceof g)return void 0!==i._warn&&!0===i._warn&&console.warn(r),void 0!==i._calcError?i._calcError:i._error;throw r}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=b(t),o=E(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)&&c(a._fillData,a._error,a._fillError)?a:i)&&void 0!==a._fillData&&c(i._fillError,i._error))try{o=A(o,a._fillData)}catch(r){if(r instanceof _)return void 0!==i._warn&&!0===i._warn&&console.warn(r),i._fillError||i._error;throw r}else o=A(o,a)}if(null===n.fmt)throw"表达式没有格式化部分";if(i=o[0],/^[+-]*[\d.]+$/.test(i))return m(o[0],n.fmt);throw new _("待格式化对象: ".concat(i," 不是数字"))},r.version="0.0.55",Object.defineProperty(r,"__esModule",{value:!0}),r}({});
|
package/browser/index.html
CHANGED
|
@@ -7,31 +7,49 @@
|
|
|
7
7
|
<body>
|
|
8
8
|
<script src="./index.js"></script>
|
|
9
9
|
<script>
|
|
10
|
-
const {calc, fmt} = a_calc
|
|
10
|
+
const { calc, fmt } = a_calc;
|
|
11
11
|
|
|
12
|
-
// console.log(calc("1 * 2 - sfsd"))
|
|
13
12
|
|
|
14
|
-
// console.log(
|
|
15
|
-
//
|
|
13
|
+
// console.log(calc("a * (b + c) % d", [
|
|
14
|
+
// {a: 1, b: 2},
|
|
15
|
+
// {c: 3, d: 4}
|
|
16
|
+
// ]))
|
|
16
17
|
|
|
17
|
-
// console.log(
|
|
18
|
+
// console.log(
|
|
19
|
+
// calc("a * (b + c) % d + 7.123", {
|
|
20
|
+
// _fillData: [
|
|
21
|
+
// { a: 1, b: 2 },
|
|
22
|
+
// { c: 3, d: 4 }
|
|
23
|
+
// ],
|
|
24
|
+
// _error: "---",
|
|
25
|
+
// _fmt: ",=8"
|
|
26
|
+
// })
|
|
27
|
+
// );
|
|
28
|
+
|
|
29
|
+
console.log(fmt(2,{_fmt: ",=2"}))
|
|
30
|
+
// console.log(calc("1 * 2 - sfsd"))
|
|
18
31
|
|
|
19
|
-
// console.log(
|
|
20
|
-
// console.log(
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
// console.log(calc("
|
|
25
|
-
//
|
|
26
|
-
// console.log(
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
// console.log(
|
|
32
|
+
// console.log(fmt("a | ,",{a: ""}))
|
|
33
|
+
// console.log(fmt("n | , >=8", {n:123}))
|
|
34
|
+
|
|
35
|
+
// console.log(fmt("n|,",{n:"----"}))
|
|
36
|
+
|
|
37
|
+
// console.log(calc("1 * 2 / *8 + a9 - 8 % 7",{_fillData:{a9: 10},error:"-"}))
|
|
38
|
+
// console.log(calc("a + b",{a: 1, b: 3}))
|
|
39
|
+
// console.log(fmt("100|=5"))
|
|
40
|
+
// let a = 0.000001
|
|
41
|
+
// let b = 888.789
|
|
42
|
+
// console.log(calc("a + b", {a,b}))
|
|
43
|
+
//
|
|
44
|
+
// console.log(calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)"))
|
|
45
|
+
// console.log(calc("0.11111 + 0.11111 | <=4"))
|
|
46
|
+
//
|
|
47
|
+
// // console.log(fmt("123"))
|
|
48
|
+
//
|
|
49
|
+
// a = 0.1
|
|
50
|
+
// b = 0.2
|
|
51
|
+
// let c = calc("a + b + 1 |= 2",{a,b})
|
|
52
|
+
// console.log(c)
|
|
35
53
|
</script>
|
|
36
54
|
</body>
|
|
37
55
|
</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 u(e){return-1<"+-*/%()".indexOf(e)}function f(e){switch(e){case"+":case"-":return 1;case"*":case"/":case"%":return 2;default:return 0}}function s(){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 C(e){return(C="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&&c(e,r)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,r){return(c=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 h(e,r,t){return(h=a()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);r=new(Function.bind.apply(e,n));return t&&c(r,t.prototype),r}).apply(null,arguments)}function p(e){var t="function"==typeof Map?new Map:void 0;return(p=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 h(e,arguments,l(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(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 g(t){var n=a();return function(){var e,r=l(t);return b(this,n?(e=l(this).constructor,Reflect.construct(r,arguments,e)):r.apply(this,arguments))}}var w=function(){o(n,p(Error));var t=g(n);function n(e){var r;return i(this,n),(r=t.call(this,e)).name="CalculatorError",r.message=e,r}return r(n)}(),d=function(){o(n,p(Error));var t=g(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 m(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 d("参数不可为空字符串")}else if("number"==typeof t)t=t.toString();else if(void 0===t||Number.isNaN(t))throw new d("非法参数:".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,I=Math.ceil,M=Math.floor,F="[BigNumber Error] ",re=F+"Number primitive has more than 15 significant digits: ",$=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(F+(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 v=function U(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,_=-1e7,O=1e7,E=!1,i=1,N=0,A={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>O?c.c=c.e=null:e.e<_?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<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)>O)c.c=c.e=null;else if(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 B(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,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 j(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)>O?e.c=e.e=null:t<_?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=I((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]==$&&(a[0]=1));break}if(a[s]+=u,a[s]!=$)break;a[s--]=0,u=1}for(o=a.length;0===a[--o];a.pop());}e.e>O?e.c=e.e=null:e.e<_&&(e.c=[e.e=0])}return e}function L(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=U,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"!=C(e))throw Error(F+"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),_=t[0],O=t[1];else{if(Y(t,-V,V,r),!t)throw Error(F+r+" cannot be zero: "+t);_=-(O=t<0?-t:t)}if(e.hasOwnProperty(r="CRYPTO")){if((t=e[r])!==!!t)throw Error(F+r+" not true or false: "+t);if(t){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw E=!t,Error(F+"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),N=t),e.hasOwnProperty(r="FORMAT")){if("object"!=C(t=e[r]))throw Error(F+r+" not an object: "+t);A=t}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(t=e[r])||/^.?$|[+\-.\s]|(.).*\1/.test(t))throw Error(F+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:N,FORMAT:A,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||$<=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(F+"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=I(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(F+"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=N,N=0,e=e.replace(".",""),c=(h=new D(r)).pow(e.length-p),N=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,N=r.c;if(!(E&&E[0]&&N&&N[0]))return new D(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 D(O)).c=[],O=t+(l=e.e-r.e)+1,i||(i=$,l=W(e.e/G)-W(r.e/G),O=O/G|0),u=0;N[u]==(E[u]||0);u++);if(N[u]>(E[u]||0)&&l--,O<0)p.push(1),f=!0;else{for(v=E.length,b=N.length,O+=2,1<(s=M(i/(N[u=0]+1)))&&(N=R(N,s,i),E=R(E,s,i),b=N.length,v=E.length),m=b,w=(g=E.slice(0,b)).length;w<b;g[w++]=0);_=N.slice(),_=[0].concat(_),y=N[0],N[1]>=i/2&&y++;do{if(s=0,(o=B(N,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(N,s=i<=s?i-1:s,i)).length,w=g.length;1==B(c,g,a,w);)s--,T(c,b<a?_:N,a,i),a=c.length,o=1;else 0==s&&(o=s=1),a=(c=N.slice()).length;if(T(g,c=a<w?[0].concat(c):c,w,i),w=g.length,-1==o)for(;B(N,g,b,w)<1;)s++,T(g,b<w?_:N,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])&&O--);f=null!=g[0],p[0]||p.splice(0,1)}if(i==$){for(u=1,O=p[0];10<=O;O/=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(F+"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(F+"Exponent not an integer: "+L(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(+L(c),l?2-J(e):+L(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);N&&(o=I(N/G+2))}for(f=l?(t=new D(.5),u&&(e.s=1),J(e)):(i=Math.abs(+L(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=+L(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,N,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=$-1;u<n;){if(c[--n]<a[n]){for(t=n;t&&!c[--t];c[t]=r);--c[t],c[n]+=$}c[n]-=a[n]}for(;0==c[0];c.splice(0,1),--s);return c[0]?j(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),j(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)/$|0,u[r]=$===u[r]?0:u[r]%$;return i&&(u=[i].concat(u),++l),j(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(+L(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"==C(r)?(t=r,r=null):e&&"object"==C(e)?(t=e,e=r=null):t=A;else if("object"!=C(t))throw Error(F+"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(F+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+L(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=O,O=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],O=l,h},t.toNumber=function(){return+L(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 L(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,r){var t="",n=(t=v.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 O(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}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 d("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 d("token填充失败,请确认".concat(o,"存在"));if("string"==typeof l){if(""===l.trim())throw new d("token填充失败,".concat(o,"值不可为空字符"));if(!/^[+-]*[\d.]+$/.test(l))throw new d("token填充失败,".concat(o,"值:").concat(l,"为非法数字"))}l="string"!=typeof l?l.toString():l,n.push(l)}else n.push(o)}return n}function E(e){for(var r,t=[],n=[],i=e;0<i.length;){var o=i.shift();if(u(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],f(o)<=f(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 N(e){for(var r=[];0<e.length;){var t=e.shift();if(u(t)){if(r.length<2)throw new w("错误的栈长度, 可能是无法计算的表达式");var n=r.pop(),i=r.pop();if("string"==typeof n&&!v.isBigNumber(n)){if(!/^[+-]*[\d.]+$/.test(n))throw new w("".concat(n,"不是一个合法的数字"));n=new v(n)}if("string"==typeof i&&!v.isBigNumber(i)){if(!/^[+-]*[\d.]+$/.test(i))throw new w("".concat(i,"不是一个合法的数字"));i=new v(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=m(r),i=O(n.expr),o=null;if(null!==n.data){var l=n.data;if(null!==(o=!Array.isArray(l)&&s(l._fillData,l._error,l._fillError,l._calcError)?l:o)&&void 0!==l._fillData&&s(o._fillError,o._error))try{i=y(i,l._fillData)}catch(e){if(e instanceof d)return void 0!==o._warn&&!0===o._warn&&console.warn(e),o._fillError||o._error;throw e}else i=y(i,l)}if(l=E(i),(i=null)===o||void 0===o._calcError&&void 0===o._error)i=N(l);else try{i=N(l)}catch(e){if(e instanceof w)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?_(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=m(r),i=O(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)&&s(l._fillData,l._error,l._fillError)?l:o)&&void 0!==l._fillData&&s(o._fillError,o._error))try{i=y(i,l._fillData)}catch(e){if(e instanceof d)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 _(i[0],n.fmt);throw new d("待格式化对象: ".concat(o," 不是数字"))},e.version="0.0.55",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(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var BigNumber__default=_interopDefaultLegacy(BigNumber);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 _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))}}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 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)&&!Array.isArray(n))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(t=r[0])){if(""===t.trim())throw new TokensFillError("参数不可为空字符串")}else if("number"==typeof t)t=t.toString();else if(void 0===t||Number.isNaN(t))throw new TokensFillError("非法参数:".concat(t));e.data=n}r=t.split("|");return 1===r.length?e.expr=r[0]:(e.expr=r[0],""!==(n=r[1]).trim()&&(e.fmt=n)),null!==e.data&&null===e.fmt&&e.data._fmt&&(e.fmt=e.data._fmt),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}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.55";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||void 0===i._calcError&&void 0===i._error)o=evalPostfix(a);else 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}return o=null!==n.fmt?format(o,n.fmt):null!==o?o.toFixed():null}exports.calc=calc,exports.fmt=fmt,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(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 _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))}}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 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)&&!Array.isArray(n))throw new Error("参数错误, 暂不支持的参数");if("string"==typeof(t=r[0])){if(""===t.trim())throw new TokensFillError("参数不可为空字符串")}else if("number"==typeof t)t=t.toString();else if(void 0===t||Number.isNaN(t))throw new TokensFillError("非法参数:".concat(t));e.data=n}r=t.split("|");return 1===r.length?e.expr=r[0]:(e.expr=r[0],""!==(n=r[1]).trim()&&(e.fmt=n)),null!==e.data&&null===e.fmt&&e.data._fmt&&(e.fmt=e.data._fmt),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 s="";/[\d.]/.test(n)&&(s+=n,!(++t>=o));)n=r[t];e.push(s)}return e}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 s=t[l];if(void 0!==s[i]){a=s[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.55";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||void 0===i._calcError&&void 0===i._error)o=evalPostfix(a);else 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}return o=null!==n.fmt?format(o,n.fmt):null!==o?o.toFixed():null}export{calc,fmt,version};
|