Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

@0ria/constant-folding

Constant Folding javascript code

constant-foldingjavascriptull
Published10 Mar 2022
Direct dependencies7
Transitive dependenciesNot calculated

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.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
commander
Environment
{
  "local_name": "commander",
  "alias": false,
  "peer_metadata": null
}
^7.1.0runtime
escodegen
Environment
{
  "local_name": "escodegen",
  "alias": false,
  "peer_metadata": null
}
^1.14.3runtime
espree
Environment
{
  "local_name": "espree",
  "alias": false,
  "peer_metadata": null
}
^9.3.1runtime
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
jison
Environment
{
  "local_name": "jison",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment
nyc
Environment
{
  "local_name": "nyc",
  "alias": false,
  "peer_metadata": null
}
latestdevelopment

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-nnOE9IZFnHK8XVHZ5qcUwkL8u0S9I5ET03CcG2A5zlHFZKwqBfgQil2gc/phlhvwdL0bil8klqnO1TwJoKJOpA==",
  "shasum": "b53e2e446369e75fa4c5dcf8895ba5b483749aef",
  "tarball": "https://registry.npmjs.org/@0ria/constant-folding/-/constant-folding-1.0.0.tgz",
  "fileCount": 11,
  "unpackedSize": 8178,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiKf7xACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrpEA//bOYEuie/myNSWwoLxLHOWZ/+tInV1mwk55qwyEfNsyBj0EWM\r\nCNLRC4S9U2tKu2hzV2VMy6n9go6B7NtNVsAp266t4t+lSsbUka/b4XslpTeR\r\nhHZGSFJdF47rt6eQjr21A8u7OwL76rKRleSO9dOis2xK/mmo6FifK7azgEge\r\n7oFbz6zYA23ihFGGCpMGFNLd25NN8edeu1kJjBHvgx8fVXEXiqenMB9zV7QQ\r\n1kWexKX6g/zEZjIjyKKlVV0EcBQZ6ItHlHTRV/v5DrQ3POR7eKy683INHbGq\r\nbHkrGIUbUVJaOmr5Uc4Uegtpq62KztEAAhhePLoa4iUl9qw2s8OWiO/EACyP\r\nzE6AEh08sMx8UryXXSjVi2wPWJN0kw+kyJNhq1amz9haTANWKdxoWZ4K3mYI\r\nsiwnBkBw5XjhEmbmddRtkuPSG0Jxh4Z00l5arKv8IlNySqdxs8owSedRUUbb\r\nW6B06osJa+cmLOCYTh22rfvHicuWZSSIPI4OeUMD5Z/+9V870cD9CqQ+KHRU\r\nJVL3kUQUsYBwi5r+rn6jWWj0mB86K1L3pBIW/+aj7ZtjLDz4TcMMGYASe12y\r\nKlSJSo8MOXHOv4vOg6VXkwGUcPHDhJqe9hH0mOyKLkpdQOHuDSHgEKtv8OOX\r\ngfaX681JPMfT04wUnNMfW7rt6QdkR7mwjzY=\r\n=eKOJ\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIEd21jUax4fJVI+dkAGXx74Ge/Pbyk/dM3ZkyYbvr8+YAiBkvgBeOlydZtnJayGVIIRtsumF3iAK1GyKq707b+WfSA=="
    }
  ]
}

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_version:bfbb91c9b092737ae5c927f91fcb4c3f9a25312b70e9b7e7e81bea154ae2f072

Other collected versions

1.1.430 May1.1.329 May1.1.229 May1.1.129 May1.1.029 May1.0.210 MarView all collected versions →