From 5d309ff52cd399a6b71968a6b9a70c8ac0b98981 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 5 Mar 2022 19:02:27 +0200 Subject: Added node_modules for the updating to work properly. --- node_modules/generate-function/example.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 node_modules/generate-function/example.js (limited to 'node_modules/generate-function/example.js') diff --git a/node_modules/generate-function/example.js b/node_modules/generate-function/example.js new file mode 100644 index 0000000..7c36c76 --- /dev/null +++ b/node_modules/generate-function/example.js @@ -0,0 +1,27 @@ +const genfun = require('./') +const { d } = genfun.formats + +function multiply (a, b) { + return a * b +} + +function addAndMultiplyNumber (val) { + const fn = genfun(` + function (n) { + if (typeof n !== 'number') { + throw new Error('argument should be a number') + } + const result = multiply(${d(val)}, n + ${d(val)}) + return result + } + `) + + // use fn.toString() if you want to see the generated source + + return fn.toFunction({multiply}) +} + +const addAndMultiply2 = addAndMultiplyNumber(2) + +console.log(addAndMultiply2.toString()) +console.log('(3 + 2) * 2 =', addAndMultiply2(3)) -- cgit v1.2.3