Catalog npm
PACKAGE EXPLORERView in registry

@0ria/constant-folding

npm

Constant Folding javascript code

constant-foldingjavascriptull
Versions collected8
Direct dependencies8From release 1.1.4
Last observed20 Oct, 22:15 UTC

README

Current package documentation

npm version CI for constant-folding

constant-folding

Author

0ria - alu0101027340

Installation

npm install @0ria/constant-folding

Usage as executable:

Default output:

npx cf inputFile.js

Desired output:

npx xf inputFile.js -o outputFile.js

Usage from code:

const constantFolding = require('constant-folding');
const code = "[1, 2, 3].length"

console.log('Code after constant folding' + constantFolding(code));

The documentation of the function.

Examples

inputs:

['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']);
["a", "b", "c"].join();
["a", "b", "c"].join('&');
[1, 2, 3].length;
[1, 2, 3][2 - 1];
[1, 2, 3].shift();
[1, 2, 3].slice(0, 1 + 1);
['a', 'b', 'c'].pop();
['a', 'b', 'c'].reverse();

outputs:

a, b, c, d, e, f, g, h;
a, b, c;
a & b & c;
3;
2;
1;
1, 2;
c;
c, b, a;

Tests

To run the tests create a directory test with a script containing tests and run npm test

const constantFolding =  require('@0ria/constant-folding');
require("chai").should();

const checks = [
  { input: "['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']);", result: "a, b, c, d, e, f, g, h;"},
  { input: '["a", "b", "c"].join();', result: "a, b, c;"},
  { input: '["a", "b", "c"].join("&");', result: "a & b & c;"},
  { input: '[1, 2, 3].length;', result: "3;"},
  { input: '[1, 2, 3][2 - 1]', result: "2;"},
  { input: '[1, 2, 3].shift();', result: "1;"},
  { input: '[1, 2, 3].slice(0, 1 + 1);', result: "1, 2;"},
  { input: '["a", "b", "c"].pop();', result: "c;"},
  { input: '["a", "b", "c"].reverse();', result: "c, b, a;"},
  { input: '[7, 2*3, 9/3].reverse()', result: "3, 6, 7;"},
  { input: 'a = 2*3*4', result: 'a = 24;'}
];

describe("Testing constant folding operations", () => {
  for (let c of checks) {
    it(`Test ${c.input} = ${c.result}`, () => {
      constantFolding(c.input).should.equal(c.result);
    })
  }
})

Test output:

Testing constant folding operations
    ✔ Test ['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']); = a, b, c, d, e, f, g, h;
    ✔ Test ["a", "b", "c"].join(); = a, b, c;
    ✔ Test ["a", "b", "c"].join("&"); = a & b & c;
    ✔ Test [1, 2, 3].length; = 3;
    ✔ Test [1, 2, 3][2 - 1] = 2;
    ✔ Test [1, 2, 3].shift(); = 1;
    ✔ Test [1, 2, 3].slice(0, 1 + 1); = 1, 2;
    ✔ Test ["a", "b", "c"].pop(); = c;
    ✔ Test ["a", "b", "c"].reverse(); = c, b, a;
    ✔ Test [7, 2*3, 9/3].reverse() = 3, 6, 7;
    ✔ Test a = 2*3*4 = a = 24;

  11 passing (45ms)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 8

Collected releases
VersionPublishedDirect dependenciesOpen version
1.1.4Registry latest30 May 20228
1.1.329 May 20228
1.1.229 May 20228
1.1.129 May 20228
1.1.029 May 20228
1.0.210 Mar 20227
1.0.110 Mar 20227
1.0.010 Mar 20227

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
ull-esit-pl-2122/constant-folding-module-daniel-oria-martin-alu0101027340

Shared repository data · GitHub

License detected in repository
Not collected

Repository

PENDING
ull-esit-pl-2021/constant-folding-module-aluxxx

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:15 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:d1f693f88da2b64a4c71fe6e66f3c3b17ba7daa38d5257794845dc2fcac9db7d