0.2.0 • Published 2 years ago

@adrian-alu0101024363/constant-folding v0.2.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
2 years ago

npm version CI for constant-folding

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

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.2

2 years ago