Skip to content

Commit

Permalink
Build files for version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
silentmatt committed Sep 25, 2017
1 parent 92fdea0 commit 03668c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
32 changes: 30 additions & 2 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function expressionToString(tokens, toJS) {
if (nstack.length > 1) {
throw new Error('invalid Expression (parity)');
}
return nstack[0];
return String(nstack[0]);
}

function escapeValue(v) {
Expand Down Expand Up @@ -1308,6 +1308,33 @@ function condition(cond, yep, nope) {
return cond ? yep : nope;
}

/**
* Decimal adjustment of a number.
* From @escopecz.
*
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @return {Number} The adjusted value.
*/
function roundTo(value, exp) {
// If the exp is undefined or zero...
if (typeof exp === 'undefined' || +exp === 0) {
return Math.round(value);
}
value = +value;
exp = -(+exp);
// If the value is not a number or the exp is not an integer...
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
return NaN;
}
// Shift
value = value.toString().split('e');
value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
// Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
}

function Parser(options) {
this.options = options || {};
this.unaryOps = {
Expand Down Expand Up @@ -1374,7 +1401,8 @@ function Parser(options) {
pow: Math.pow,
atan2: Math.atan2,
'if': condition,
gamma: gamma
gamma: gamma,
roundTo: roundTo
};

this.consts = {
Expand Down

0 comments on commit 03668c2

Please sign in to comment.