JSPM

@adrian-alu0101024363/constant-folding

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q44370F
  • License Unlicense

Constant Folding javascript code

Package Exports

  • @adrian-alu0101024363/constant-folding
  • @adrian-alu0101024363/constant-folding/src/constant-folding.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@adrian-alu0101024363/constant-folding) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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