diff --git a/lib/plugins/StandardLibrary/Math.js b/lib/plugins/StandardLibrary/Math.js new file mode 100644 index 0000000..6d7b59c --- /dev/null +++ b/lib/plugins/StandardLibrary/Math.js @@ -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()]);