@adrian-alu0101024363/constant-folding
v0.2.0
Published
Constant Folding javascript code
Downloads
12
Maintainers
Readme
constant-folding
Installation
npm i @adrian-alu0101024363/constant-folding
Usage as executable:
cf input.js output.js
Usage from code:
const constantFolding = require('constant-folding');
let input_file = 'input.js';
let output_file = 'output.js';
//Or use arguments from console like the cf program does
fs.readFile(input_file, 'utf-8', (err, input) => {
if (err) {
console.log("Couldn't read the file: " + err);
return;
}
console.log("File read succesfully");
let output = constantFolding(input);
fs.writeFile(output_file, output, (err) => {
if (err) {
console.log("Couldn't write the output to " + output_file + ": " + err);
return;
}
console.log("Output written succesfully in " + output_file);
});
});
The documentation of the function.
Examples
const Checks = [
{ text: `a=2*3;`, result: `a = 6;` },
{ text: `b=5+null;`, result: `b = 5;` },
{ text: `e=4|3;`, result: `e = 7;` },
{ text: `d = 3+"c";`, result: `d = '3c';` },
{ text: `b = 9 +1;`, result: `b = 10;` },
{ text: `f = 2+3*5+b;`, result: `f = 17 + b;`},
];
Author
alu0101024363 Adrián Fleitas de la Rosa
Tests
npm run cov