Hashing made simple. Get the hash of a buffer/string/stream/file.
Installations
npm install hasha
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
20.9.0
NPM Version
9.2.0
Score
99.4
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (78.42%)
TypeScript (21.58%)
Developer
sindresorhus
Download Statistics
Total Downloads
1,063,043,794
Last Day
354,659
Last Week
2,086,726
Last Month
18,396,809
Last Year
241,135,625
GitHub Statistics
957 Stars
60 Commits
32 Forks
12 Watching
1 Branches
10 Contributors
Bundle Size
2.14 kB
Minified
969.00 B
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
6.0.0
Package Id
hasha@6.0.0
Unpacked Size
14.49 kB
Size
4.49 kB
File Count
6
NPM Version
9.2.0
Node Version
20.9.0
Publised On
11 Nov 2023
Total Downloads
Cumulative downloads
Total Downloads
1,063,043,794
Last day
-13.2%
354,659
Compared to previous day
Last week
-47.6%
2,086,726
Compared to previous week
Last month
-27.5%
18,396,809
Compared to previous month
Last year
10.4%
241,135,625
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Hashing made simple. Get the hash of a buffer/string/stream/file.
Convenience wrapper around the core crypto
Hash class with simpler API and better defaults.
Install
1npm install hasha
Usage
1import {hash} from 'hasha'; 2 3await hash('unicorn'); 4//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
API
See the Node.js crypto
docs for more about hashing.
hash(input, options?)
The operation is executed using worker_threads
. A thread is lazily spawned on the first operation and lives until the end of the program execution. It's unrefed, so it won't keep the process alive.
Returns a hash asynchronously.
hashSync(input, options?)
Returns a hash.
input
Type: Uint8Array | string | Array<Uint8Array | string> | NodeJS.ReadableStream
(NodeJS.ReadableStream
is not available in hashSync
)
The value to hash.
While strings are supported you should prefer buffers as they're faster to hash. Although if you already have a string you should not convert it to a buffer.
Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
options
Type: object
encoding
Type: string
Default: 'hex'
Values: 'hex' | 'base64' | 'buffer' | 'latin1'
The encoding of the returned hash.
algorithm
Type: string
Default: 'sha512'
Values: 'md5' | 'sha1' | 'sha256' | 'sha512'
(Platform dependent)
The md5
algorithm is good for file revving, but you should never use md5
or sha1
for anything sensitive. They're insecure.
hashFile(filePath, options?)
The operation is executed using worker_threads
. A thread is lazily spawned on the first operation and lives until the end of the program execution. It's unrefed, so it won't keep the process alive.
Returns a Promise
for the calculated file hash.
1import {hashFile} from 'hasha'; 2 3// Get the MD5 hash of an image 4await hashFile('unicorn.png', {algorithm: 'md5'}); 5//=> '1abcb33beeb811dca15f0ac3e47b88d9'
hashFileSync(filePath, options?)
Returns the calculated file hash.
1import {hashFileSync} from 'hasha'; 2 3// Get the MD5 hash of an image 4hashFileSync('unicorn.png', {algorithm: 'md5'}); 5//=> '1abcb33beeb811dca15f0ac3e47b88d9'
hashingStream(options?)
Returns a hash transform stream.
1import {hashingStream} from 'hasha'; 2 3// Hash the process input and output the hash sum 4process.stdin.pipe(hashingStream()).pipe(process.stdout);
Related
- hasha-cli - CLI for this module
- crypto-hash - Tiny hashing module that uses the native crypto API in Node.js and the browser
- hash-object - Get the hash of an object
- md5-hex - Create a MD5 hash with hex encoding
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/hasha/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/hasha/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:20
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to hasha
@types/hasha
Stub TypeScript definitions entry for hasha, which provides its own types definitions
hasharray
A data structure that combines a hash and an array for fast dictionary lookup and traversal by complex keys.
@accounter/hashavshevet-mesh
Graphql proxy for Hashavshevet API
hasha-cli
Hashing made simple. Get the hash of text or stdin.