maths: add pad function
This commit is contained in:
parent
9f81e0b9cb
commit
1c53aea10e
2 changed files with 11 additions and 2 deletions
|
|
@ -13,13 +13,14 @@ Where FORMULA is a valid [MathJS](http://mathjs.org/docs/expressions/syntax.html
|
|||
- [available constants](http://mathjs.org/docs/reference/constants.html)
|
||||
- formulas can be [multiline](http://mathjs.org/docs/expressions/syntax.html#multiline-expressions)
|
||||
- property inheritance calls (`@{...}`) are always resolved before formulas
|
||||
- arrays / matrices indexes are **zero-based** (ie `['a','b'][0]` returns `'a'`)
|
||||
- arrays / matrices indexes are **zero-based** (ie `["a","b"][0]` returns `"a"`)
|
||||
- strings can be multiline when enclosed in backticks instead of double quotes (``` ` ` ```)
|
||||
- inner closing brackets (`}`) must be escaped with a backslash (`\}`)
|
||||
|
||||
Additionnal functions:
|
||||
|
||||
- `unpack`: remove an array's brackets (`unpack([1,2])` returns `'1, 2'`)
|
||||
- `unpack(x)`: remove an array's brackets (`unpack([1,2])` returns `"1, 2"`)
|
||||
- `pad(x, padding)`: add leading zeros if the length the integer part of `x` is smaller than `padding` (`pad(1,2)` returns `"01"`)
|
||||
|
||||
!!! tip ""
|
||||
A single widget property can contain multiple formulas. Variables and functions declared in a formula are available to subsequent formulas in the same property definition.
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ module.exports = {
|
|||
})
|
||||
math.import({
|
||||
unpack: function(a) { return Array.isArray(a) ? a.toString() : a },
|
||||
pad: function(x, padding) {
|
||||
var str = String(x),
|
||||
[int, dec] = str.split('.')
|
||||
while (int.length < padding) {
|
||||
int = '0' + int
|
||||
}
|
||||
return dec ? int + '.' + dec : int
|
||||
},
|
||||
// basic relationnal to keep alphabetical string comparison (v4 change)
|
||||
equal: function (a, b) { return a == b },
|
||||
unequal: function (a, b) { return a != b },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue