https://github.com/berkmann18/hashmyjs
A simple NodeJS program that hashes JS files/codes and output it on the terminal or in files or via variables
https://github.com/berkmann18/hashmyjs
base64 csp hashing integrity nodejs sha-256
Last synced: 6 months ago
JSON representation
A simple NodeJS program that hashes JS files/codes and output it on the terminal or in files or via variables
- Host: GitHub
- URL: https://github.com/berkmann18/hashmyjs
- Owner: Berkmann18
- License: mit
- Created: 2017-12-30T21:28:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-11-01T22:08:35.000Z (almost 3 years ago)
- Last Synced: 2025-03-13T14:18:35.882Z (7 months ago)
- Topics: base64, csp, hashing, integrity, nodejs, sha-256
- Language: JavaScript
- Homepage:
- Size: 18.3 MB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HashMyJS
[](https://nodei.co/npm/hashmyjs/)[](https://travis-ci.org/Berkmann18/hashmyjs)
[](https://codecov.io/github/Berkmann18/hashmyjs?branch=master)
[](https://github.com/facebook/jest)
[](https://snyk.io/test/github/Berkmann18/hashmyjs?targetFile=package.json)[](https://github.com/Berkmann18/hashmyjs/blob/master/LICENSE)
[](https://github.com/Berkmann18/hashmyjs/issues)
[](http://commitizen.github.io/cz-cli/)
[](https://dependabot.com)[](https://github.com/Berkmann18/hashmyjs)
[](https://github.com/Berkmann18/hashmyjs)
[](https://github.com/Berkmann18/hashmyjs)[](http://inch-ci.org/github/Berkmann18/hashmyjs)
[](https://bettercodehub.com/results/Berkmann18/hashmyjs)
[](https://app.codacy.com/app/maxieberkmann/hashmyjs?utm_source=github.com&utm_medium=referral&utm_content=Berkmann18/hashmyjs&utm_campaign=Badge_Grade_Dashboard)It's a relatively simple NodeJS program that allows you to get the base64 encoded SHA-256 hash for a JS file or the code itself that you could later on use as the integrity of a script that you would integrate to a page so it won't be flagged by CSP or else.
## Install
To install it you need to execute the following:
```cli
npm i hashmyjs
```_Note_: Don't forget to use `-g`, `--save`, `--save-dev` if appropriate.
## Usage
### In NodeJS
```js
const hmj = require('hashmyjs');//Hashing from the STDIN (followed by a new line: `\$`, `\EOF`) or from file passed as arguments
hmj.run();//Or if you want to hash code that is already present in your script:
let code = `...`;
let digest = hmj.hash(code);
```### In the CLI
```bash
hashmyjs -- [options] [files] #If used via an npm script
```
**Help**:
```cli
Usage: hashmyjs [options] [files...]A simple NodeJS JS file/code hasher.
Options:
-V, --version output the version number
-f, --format [format] Specify the format of the output (text (default), json, csv) (default: text)
-o, --output [path] Output to a file instead of in the STDOUT (default: stdout)
-i, --interactive Forces to read the input from the STDIN
-p, --prettify Prettify the output
-h, --help output usage information
```## Nota bene
If you use wildcard `*` in the CLI to get files, NodeJS will have a hard time getting the file from the right URL so it will lead in errors.## Documentation
See [this](./DOCUMENTATION.md) for more information.## Contribution
If you discover bugs, errors or/and have suggestions/feedback please create an [issue](http://github.com/Berkmann18/hashmyjs/issues) or/and submit a [PR](http://github.com/Berkmann18/hashmyjs/pulls).If you want to contribute, make sure you stick with the coding style that ESLint is enforcing (cf. configuration file).
To check if a file stick to the standards:
```cli
eslint -c ./config/.eslintrc.js yourFile.js
#Or `npm lint` if appropriate
```
To fix formatting errors and such, run:
```cli
./fixjs.sh [your js files seperated by spaces]
```## Contributors
| [
Maximilian Berkmann](http://maxcubing.wordpress.com)
[🐛](https://github.com/Berkmann18/hashmyjs/issues?q=author%3ABerkmann18 "Bug reports") [💻](https://github.com/Berkmann18/hashmyjs/commits?author=Berkmann18 "Code") [📖](https://github.com/Berkmann18/hashmyjs/commits?author=Berkmann18 "Documentation") [🤔](#ideas-Berkmann18 "Ideas, Planning, & Feedback") [💬](#question-Berkmann18 "Answering Questions") [👀](#review-Berkmann18 "Reviewed Pull Requests") [🛡️](#security-Berkmann18 "Security") [⚠️](https://github.com/Berkmann18/hashmyjs/commits?author=Berkmann18 "Tests") | [
Dependabot](https://dependabot.com)
[🔧](#tool-dependabot-bot "Tools") | [
Semantic Release Bot](http://semantic-release.org/)
[📖](https://github.com/Berkmann18/hashmyjs/commits?author=semantic-release-bot "Documentation") [📦](#platform-semantic-release-bot "Packaging/porting to new platform") | [
Codacy Badger](https://www.codacy.com)
[🚇](#infra-codacy-badger "Infrastructure (Hosting, Build-Tools, etc)") |
| :---: | :---: | :---: | :---: |