math props: always stringify to keep object intact and add unpack() function for formatting arrays

This commit is contained in:
jean-emmanuel 2018-02-05 15:09:39 +01:00
parent 4279ed6b4b
commit 42d19401fe
2 changed files with 8 additions and 3 deletions

View file

@ -205,7 +205,7 @@ module.exports = class _widgets_base extends EventEmitter {
originalPropName = originalPropName || propName,
obj
if (typeof propValue == 'string' && propValue.indexOf('@{') != -1) {
if (typeof propValue == 'string') {
propValue = propValue.replace(/@\{([^\}]+)\}/g, (m)=>{
let id = m.substr(2, m.length - 3).split('.'),
k = id.pop(),
@ -279,8 +279,10 @@ module.exports = class _widgets_base extends EventEmitter {
try {
propValue = propValue.replace(/#\{([^\}]+)\}/g, (m)=>{
let expression = m.substr(2, m.length - 3).trim()
return math.eval(expression)
let expression = m.substr(2, m.length - 3).trim(),
r = math.eval(expression)
return typeof r != 'string' ? JSON.stringify(r) : r
})
} catch (err) {}

View file

@ -1,6 +1,9 @@
var math = require('mathjs/dist/math.min.js').create({
matrix: 'Array'
})
math.import({
unpack: function(a) { return Array.isArray(a) ? a.toString() : a }
})
// set math's parser array index base to zero
math.expression.mathWithTransform = Object.assign({}, math)