formula; use *mathjs* to parse (safer and handy)
This commit is contained in:
parent
78791180cf
commit
202bb6886a
3 changed files with 15 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
|||
"description": "A libre desktop OSC bi-directionnal control surface application - builder package",
|
||||
"dependencies": {
|
||||
"electron": "1.4.14",
|
||||
"mathjs": "3.9.0",
|
||||
"browserify": "13.3.0",
|
||||
"exorcist": "0.4.0",
|
||||
"node-sass": "^4.1.1",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var _widgets_base = require('../common/_widgets_base'),
|
||||
{widgetManager} = require('../../managers')
|
||||
{widgetManager} = require('../../managers'),
|
||||
{mathEval} = require('../utils')
|
||||
|
||||
|
||||
module.exports = class Formula extends _widgets_base {
|
||||
|
|
@ -79,7 +80,7 @@ module.exports = class Formula extends _widgets_base {
|
|||
|
||||
try {
|
||||
|
||||
this.value = eval(formula)
|
||||
this.value = mathEval(formula).valueOf()
|
||||
|
||||
this.showValue()
|
||||
if (e.options.sync) this.widget.trigger({type: 'sync',id: this.widgetData.id,widget: this.widget, linkId: this.widgetData.linkId, options: e.options})
|
||||
|
|
@ -87,7 +88,7 @@ module.exports = class Formula extends _widgets_base {
|
|||
|
||||
} catch(err) {
|
||||
|
||||
throw 'Error parsing formula "' + formula + '"'
|
||||
throw 'Error parsing formula "' + formula + '"' + err
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,10 @@
|
|||
var core = require('mathjs/core'),
|
||||
math = core.create()
|
||||
|
||||
math.import(require('mathjs/lib/type'))
|
||||
math.import(require('mathjs/lib/function'))
|
||||
math.import(require('mathjs/lib/expression'))
|
||||
|
||||
module.exports = {
|
||||
|
||||
clip: function(value,range) {
|
||||
|
|
@ -68,5 +75,7 @@ module.exports = {
|
|||
hsb.s *= 100/255
|
||||
hsb.b *= 100/255
|
||||
return hsb
|
||||
}
|
||||
},
|
||||
|
||||
mathEval: math.eval
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue