Skip to content

Commit 03668c2

Browse files
committed
Build files for version 1.2.0
1 parent 92fdea0 commit 03668c2

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

dist/bundle.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function expressionToString(tokens, toJS) {
284284
if (nstack.length > 1) {
285285
throw new Error('invalid Expression (parity)');
286286
}
287-
return nstack[0];
287+
return String(nstack[0]);
288288
}
289289

290290
function escapeValue(v) {
@@ -1308,6 +1308,33 @@ function condition(cond, yep, nope) {
13081308
return cond ? yep : nope;
13091309
}
13101310

1311+
/**
1312+
* Decimal adjustment of a number.
1313+
* From @escopecz.
1314+
*
1315+
* @param {Number} value The number.
1316+
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
1317+
* @return {Number} The adjusted value.
1318+
*/
1319+
function roundTo(value, exp) {
1320+
// If the exp is undefined or zero...
1321+
if (typeof exp === 'undefined' || +exp === 0) {
1322+
return Math.round(value);
1323+
}
1324+
value = +value;
1325+
exp = -(+exp);
1326+
// If the value is not a number or the exp is not an integer...
1327+
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
1328+
return NaN;
1329+
}
1330+
// Shift
1331+
value = value.toString().split('e');
1332+
value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
1333+
// Shift back
1334+
value = value.toString().split('e');
1335+
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
1336+
}
1337+
13111338
function Parser(options) {
13121339
this.options = options || {};
13131340
this.unaryOps = {
@@ -1374,7 +1401,8 @@ function Parser(options) {
13741401
pow: Math.pow,
13751402
atan2: Math.atan2,
13761403
'if': condition,
1377-
gamma: gamma
1404+
gamma: gamma,
1405+
roundTo: roundTo
13781406
};
13791407

13801408
this.consts = {

0 commit comments

Comments
 (0)