enh(std) enhance standard library plugin with math functionalities
This commit is contained in:
60
lib/plugins/StandardLibrary/Math.js
Normal file
60
lib/plugins/StandardLibrary/Math.js
Normal file
@@ -0,0 +1,60 @@
|
||||
function inc(val, options = [1]) {
|
||||
let [name, amount = 1, ..._rest] = options;
|
||||
return {
|
||||
varName: name,
|
||||
new: val * 1 + amount * 1,
|
||||
old: val * 1,
|
||||
};
|
||||
}
|
||||
|
||||
function dec(val, options = [1]) {
|
||||
let [name, amount = 1, ..._rest] = options;
|
||||
return {
|
||||
varName: name,
|
||||
new: val * 1 - amount * 1,
|
||||
old: val * 1,
|
||||
};
|
||||
}
|
||||
|
||||
function mult(val, options = [1]) {
|
||||
let [name, amount = 1, ..._rest] = options;
|
||||
return {
|
||||
varName: name,
|
||||
new: val * 1 * amount * 1,
|
||||
old: val * 1,
|
||||
};
|
||||
}
|
||||
|
||||
function div(val, options = [1]) {
|
||||
let [name, amount = 1, ..._rest] = options;
|
||||
return {
|
||||
varName: name,
|
||||
new: ((val * 1) / amount) * 1,
|
||||
old: val * 1,
|
||||
};
|
||||
}
|
||||
|
||||
function pow(val, options = [1]) {
|
||||
let [name, amount = 1, ..._rest] = options;
|
||||
return {
|
||||
varName: name,
|
||||
new: Math.pow(val * 1, amount * 1),
|
||||
old: val * 1,
|
||||
};
|
||||
}
|
||||
|
||||
const BasicArithmetic = new Map([
|
||||
['increment', inc],
|
||||
['increase', inc],
|
||||
['inc', inc],
|
||||
['decrement', dec],
|
||||
['decrease', dec],
|
||||
['dec', dec],
|
||||
['multiply', mult],
|
||||
['mult', mult],
|
||||
['divide', div],
|
||||
['div', div],
|
||||
['pow', pow],
|
||||
]);
|
||||
|
||||
export default new Map([...BasicArithmetic.entries()]);
|
||||
Reference in New Issue
Block a user