1.1.1 • Published 6 years ago

js-ast-hash v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

js-ast-hash Build Status

Output hash value of JavaScript AST. This tool help to compare source codes ignoring space and comment.

This tool is inspired by following article.

Features

  • Output JavaScript AST hash(md5) value
  • Ignore space, break line, and comment of the source code

Ignore comments example:

/* comment A */ var a = 1;// a

===

/* comment B */ var a = 1; // b

Ignore spaces example:

var fn = function(){}

===

var fn = function (){
};

Install

Install with npm:

npm install js-ast-hash

Usage

Usage
  $ js-ast-hash file.js ["src/**/*.js"]

Options
  --format -f output format: json, csv (default: csv)

Examples
  $ js-ast-hash file.js
  $ js-ast-hash "src/**/*.js" -f json

Example

example1.js:

// this is example 1
var a = 1;

example2.js:

// this is example 2
var b = 1;

example3.js:

// this is example 3
var a = 1 // code is same with example1

CSV results:

$ js-ast-hash test/fixtures/example.js
"filePath","hash"
"test/fixtures/example1.js","3a5c739d9c4b6284c5790de8b557bd3d"
"test/fixtures/example2.js","da948b06f3c073a32dc6de72e00dbe8f"
"test/fixtures/example3.js","3a5c739d9c4b6284c5790de8b557bd3d"

JSON results:

$ js-ast-hash test/fixtures/ -f json
[{"filePath":"test/fixtures/example1.js","hash":"3a5c739d9c4b6284c5790de8b557bd3d"},{"filePath":"test/fixtures/example2.js","hash":"da948b06f3c073a32dc6de72e00dbe8f"},{"filePath":"test/fixtures/example3.js","hash":"3a5c739d9c4b6284c5790de8b557bd3d"},]

example1.js and example3.js should be same hash value.

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago