@alu0101337760/constant-folding
Version:
Constant Folding javascript code
77 lines (48 loc) • 1.71 kB
Markdown
[](https://badge.fury.io/js/%40alu0101337760%2Fconstant-folding)
[](https://github.com/ULL-ESIT-PL-2021/constant-folding-module-alu0101337760/actions/workflows/nodejs.yml)
## constant-folding
This package offers utility to apply constant folding optimization to Javascript code.
## Installation
To install this package you can type:
```
npm i @alu0101337760/constant-folding
```
or add this entry to your `package.json` file:
```javascript
{
"@alu0101337760/constant-folding": "^1.1.1"
}
```
## Usage as executable:
To run the executable you can type:
```
npx cf <input_file> -o <output_file>
```
This command reads the contents of the input file and writes in the output file the result of applying the constant folding.
You can see the information in detail with the option `-h`:
```
npx cf -h
```
## Usage from code:
The `constantFolding()` function, takes a `String` containing Javascript source code as a parameter and returns the
```javascript
const constantFolding = require('constant-folding');
let foldedCode = constantFolding("string");
```
[The documentation of the function](https://ull-esit-pl-2021.github.io/constant-folding-module-alu0101337760/).
## Examples
From code:
```Javascript
const example4 = `30+2-4`;
console.log(constantFolding(example));
// output: 28;
```
## Author
name: Enrique Viña Alonso
email: alu0101337760@ull.edu.es
url: [https://github.com/alu0101337760]()
## Tests
To run the tests you can use:
```
npm test
```