Skip to content

Instantly share code, notes, and snippets.

@artem-solovev
artem-solovev / nemathodeApiWithLove.js
Last active May 23, 2021
Nemathode Api - With love
View nemathodeApiWithLove.js
import Nemathode from 'nemathode';
import { config } from './config';
const nemathode = Nemathode({
...config,
});
// doing same thing as `evaluate` but with love (don't forget being polite even with code)
const res = nemathode.evaluatePlease([...]);
View nemathodeApiStandart.js
import Nemathode from 'nemathode';
import { config } from './config';
const nemathode = Nemathode({
...config,
});
// method for expression evaluation
const res = nemathode.evaluate([...]);
@artem-solovev
artem-solovev / nemathodeOperatorConfigurationExample.md
Created May 22, 2021
Nemathode operator configuration example
View nemathodeOperatorConfigurationExample.md
...
    '+': {
        precedence: 1,
        implementation: (l: number, r: number): number => {
            return l + r;
        },
    }
...
@artem-solovev
artem-solovev / nemathodeToOutputTypeConfigurationExample.ts
Created May 22, 2021
Nemathode toOutputType configuration example
View nemathodeToOutputTypeConfigurationExample.ts
const toOutputValue = (val: unknown): number | boolean => {
if (val instanceof Decimal) {
return val.toNumber();
}
return val;
};
@artem-solovev
artem-solovev / nemathodeToInputTypeConfigurationExample.ts
Created May 22, 2021
Nemathode toInputType configuration example
View nemathodeToInputTypeConfigurationExample.ts
const toInputType = (val: unknown): Decimal | unknown => {
if (typeof val === 'number') {
const input = new Decimal(val);
return input;
}
return val;
};
@artem-solovev
artem-solovev / nemathodePureJSConfigurationExample.js
Last active May 23, 2021
Nemathode PureJS configuration example
View nemathodePureJSConfigurationExample.js
const config = {
mathConstants: {
'E': Math.E,
'LN2': Math.LN2,
'LN10': Math.LN10,
'LOG10E': Math.LOG10E,
'LOG2E': Math.LOG2E,
'PI': Math.PI,
'SQRT1_2': Math.SQRT1_2,
'SQRT2': Math.SQRT2,
@artem-solovev
artem-solovev / nemathodeWithNestedExpressions.js
Created May 22, 2021
Nemathode with nested expressions
View nemathodeWithNestedExpressions.js
const resOfNestedExp = nemathode.evaluate([1, '+', 'PI', '*', ['abs', 1, 2, 3], '-', [1, '+', [1, '/', 25]]]);
View nemathodeWithMathConstants.js
const piConst = nemathode.mathConstants.PI;
const piConstInUse = nemathode.evaluate([1, '+', 'PI']);
@artem-solovev
artem-solovev / nemathodeWithFunctions.js
Last active May 23, 2021
Nemathode with functions
View nemathodeWithFunctions.js
const customFunction = nemathode.evaluate([1, '+', ['abs', 1, 2, 3]]); //a rguments are not evaluated (future)
const singleFunction = nemathode.evaluate([['abs', 1, 2, 3]]; // single function syntax (it's not convinient, but for now it's only way)
const boolResult = nemathode.evaluate([['areEqual', 1, 2, 3]]); // returns boolean
// etc
View nemathodeWithBinaryOperators.js
const sumOperator = nemathode.evaluate([1, '+', 1]); // 2
const mulOperator = nemathode.evaluate([1, '*', 1]); // 1