* chore(NA): eslint rule for disallowing naked eslint-disable * chore(NA): export new rule and update docs * chore(NA): creation of rule in ts * chore(NA): new corrected rule in ts * refact(NA): remove old logic from older plugin * docs(NA): update documentation * docs(NA): update documentation * docs(NA): update documentation * refact(NA): include edge cases for better locating errors * chore(NA): changed regex name * docs(NA): correct name rule on docs * refact(NA): use dedent in the template literals * refact(NA): check for undefined * fix(NA): introduces support for eslint-disable-line * chore(NA): fix extra space * test(NA): created more test cases * chore(NA): rename plugin to eslint-plugin-disable * docs(NA): update nav and operations landing page ids for eslint rule * test(NA): use messageIds on test * chore(NA): complete naked eslint disables with specific rules * chore(NA): specific rules for a few naked eslint disable * chore(NA): add focused eslint disable on big reindex_operation_with_large_error_message.ts file * chore(NA): changes according PR feedback * chore(NA): include specific eslint rules on latest naked eslint disable * chore(NA): missing eslint disable specific rule * fix(NA): remove comment for js annotator * chore(NA): re add eslint focused disable rule to x-pack/plugins/osquery/cypress/support/coverage.ts * chore(NA): re add eslint focused disable rule to x-pack/plugins/osquery/cypress/support/coverage.ts * chore(NA): re add eslint focused disable rule to x-pack/plugins/osquery/cypress/support/coverage.ts Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> |
||
---|---|---|
.. | ||
docs | ||
grammar | ||
src | ||
test | ||
BUILD.bazel | ||
index.d.ts | ||
jest.config.js | ||
package.json | ||
README.md | ||
tsconfig.json |
kbn-tinymath
kbn-tinymath is a tiny arithmetic and function evaluator for simple numbers and arrays. Named properties can be accessed from an optional scope parameter.
It's available as an expression function called math
in Canvas, and the grammar/AST structure is available
for use by Kibana plugins that want to use math.
See Function Documentation for details on built-in functions available in Tinymath.
const { evaluate } = require('@kbn/tinymath');
// Simple math
evaluate('10 + 20'); // 30
evaluate('round(3.141592)') // 3
// Named properties
evaluate('foo + 20', {foo: 5}); // 25
// Arrays
evaluate('bar + 20', {bar: [1, 2, 3]}); // [21, 22, 23]
evaluate('bar + baz', {bar: [1, 2, 3], baz: [4, 5, 6]}); // [5, 7, 9]
evaluate('multiply(bar, baz) / 10', {bar: [1, 2, 3], baz: [4, 5, 6]}); // [0.4, 1, 1.8]
Adding Functions
Functions can be injected, and built in function overwritten, via the 3rd argument to evaluate
:
const { evaluate } = require('@kbn/tinymath');
evaluate('plustwo(foo)', {foo: 5}, {
plustwo: function(a) {
return a + 2;
}
}); // 7
Parsing
You can get to the parsed AST by importing parse
const { parse } = require('@kbn/tinymath');
parse('1 + random()')
/*
{
"name": "add",
"args": [
1,
{
"name": "random",
"args": []
}
]
}
*/
Notes
- Floating point operations have the normal Javascript limitations
Building kbn-tinymath
This package is rebuilt when running yarn kbn bootstrap
, but can also be build directly
using yarn build
from the packages/kbn-tinymath
directory.
Running tests
To test @kbn/tinymath
from Kibana, run yarn run jest --watch packages/kbn-tinymath
from
the top level of Kibana.