Skip to content

Instantly share code, notes, and snippets.

View kas-elvirov's full-sized avatar
🇷🇺

Kas Elvirov kas-elvirov

🇷🇺
View GitHub Profile
@kas-elvirov
kas-elvirov / nemathodeApiWithLove.js
Last active May 23, 2021 16:13
Nemathode Api - With love
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([...]);
@kas-elvirov
kas-elvirov / nemathodeApiStandart.js
Last active May 23, 2021 16:12
Nemathode Api-Standart
import Nemathode from 'nemathode';
import { config } from './config';
const nemathode = Nemathode({
...config,
});
// method for expression evaluation
const res = nemathode.evaluate([...]);
@kas-elvirov
kas-elvirov / nemathodeOperatorConfigurationExample.md
Created May 22, 2021 17:46
Nemathode operator configuration example
...
    '+': {
        precedence: 1,
        implementation: (l: number, r: number): number => {
            return l + r;
        },
    }
...
@kas-elvirov
kas-elvirov / nemathodeToOutputTypeConfigurationExample.ts
Created May 22, 2021 17:42
Nemathode toOutputType configuration example
const toOutputValue = (val: unknown): number | boolean => {
if (val instanceof Decimal) {
return val.toNumber();
}
return val;
};
@kas-elvirov
kas-elvirov / nemathodeToInputTypeConfigurationExample.ts
Created May 22, 2021 17:40
Nemathode toInputType configuration example
const toInputType = (val: unknown): Decimal | unknown => {
if (typeof val === 'number') {
const input = new Decimal(val);
return input;
}
return val;
};
@kas-elvirov
kas-elvirov / nemathodePureJSConfigurationExample.js
Last active May 23, 2021 13:34
Nemathode PureJS configuration example
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,
@kas-elvirov
kas-elvirov / nemathodeWithNestedExpressions.js
Created May 22, 2021 17:30
Nemathode with nested expressions
const resOfNestedExp = nemathode.evaluate([1, '+', 'PI', '*', ['abs', 1, 2, 3], '-', [1, '+', [1, '/', 25]]]);
@kas-elvirov
kas-elvirov / nemathodeWithMathConstants.js
Created May 22, 2021 17:28
Nemathode with math constants
const piConst = nemathode.mathConstants.PI;
const piConstInUse = nemathode.evaluate([1, '+', 'PI']);
@kas-elvirov
kas-elvirov / nemathodeWithFunctions.js
Last active May 23, 2021 11:35
Nemathode with functions
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
@kas-elvirov
kas-elvirov / nemathodeWithBinaryOperators.js
Created May 22, 2021 16:43
Nemathode with binary operators
const sumOperator = nemathode.evaluate([1, '+', 1]); // 2
const mulOperator = nemathode.evaluate([1, '*', 1]); // 1