{"id":13455135,"url":"https://github.com/sindresorhus/hasha","last_synced_at":"2025-05-14T07:09:13.560Z","repository":{"id":32534286,"uuid":"36116052","full_name":"sindresorhus/hasha","owner":"sindresorhus","description":"Hashing made simple. Get the hash of a buffer/string/stream/file.","archived":false,"fork":false,"pushed_at":"2023-11-11T12:43:06.000Z","size":105,"stargazers_count":956,"open_issues_count":3,"forks_count":32,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-06T18:49:42.762Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-05-23T09:23:44.000Z","updated_at":"2025-03-19T18:32:42.000Z","dependencies_parsed_at":"2023-12-21T05:37:53.913Z","dependency_job_id":"9e9caa81-36a0-482c-aab8-6d9e221be786","html_url":"https://github.com/sindresorhus/hasha","commit_stats":{"total_commits":57,"total_committers":11,"mean_commits":5.181818181818182,"dds":"0.24561403508771928","last_synced_commit":"f9522dc7143953ca80e7aa1b41454892147cbd8b"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhasha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhasha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhasha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fhasha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/hasha/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253518949,"owners_count":21921076,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:01:01.645Z","updated_at":"2025-05-14T07:09:08.548Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","包","目录","Miscellaneous","Number"],"sub_categories":["Miscellaneous","其他","杂项"],"readme":"\u003ch1 align=\"center\"\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cimg width=\"380\" src=\"media/logo.svg\" alt=\"hasha\"\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\u003c/h1\u003e\n\n\u003e Hashing made simple. Get the hash of a buffer/string/stream/file.\n\nConvenience wrapper around the core [`crypto` Hash class](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) with simpler API and better defaults.\n\n## Install\n\n```sh\nnpm install hasha\n```\n\n## Usage\n\n```js\nimport {hash} from 'hasha';\n\nawait hash('unicorn');\n//=\u003e 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'\n```\n\n## API\n\nSee the Node.js [`crypto` docs](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options) for more about hashing.\n\n### hash(input, options?)\n\nThe 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.\n\nReturns a hash asynchronously.\n\n### hashSync(input, options?)\n\nReturns a hash.\n\n#### input\n\nType: `Uint8Array | string | Array\u003cUint8Array | string\u003e | NodeJS.ReadableStream` *(`NodeJS.ReadableStream` is not available in `hashSync`)*\n\nThe value to hash.\n\nWhile 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.\n\nPass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.\n\n#### options\n\nType: `object`\n\n##### encoding\n\nType: `string`\\\nDefault: `'hex'`\\\nValues: `'hex' | 'base64' | 'buffer' | 'latin1'`\n\nThe encoding of the returned hash.\n\n##### algorithm\n\nType: `string`\\\nDefault: `'sha512'`\\\nValues: `'md5' | 'sha1' | 'sha256' | 'sha512'` *([Platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options))*\n\n*The `md5` algorithm is good for [file revving](https://github.com/sindresorhus/rev-hash), but you should never use `md5` or `sha1` for anything sensitive. [They're insecure.](https://security.googleblog.com/2014/09/gradually-sunsetting-sha-1.html)*\n\n### hashFile(filePath, options?)\n\nThe 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.\n\nReturns a `Promise` for the calculated file hash.\n\n```js\nimport {hashFile} from 'hasha';\n\n// Get the MD5 hash of an image\nawait hashFile('unicorn.png', {algorithm: 'md5'});\n//=\u003e '1abcb33beeb811dca15f0ac3e47b88d9'\n```\n\n### hashFileSync(filePath, options?)\n\nReturns the calculated file hash.\n\n```js\nimport {hashFileSync} from 'hasha';\n\n// Get the MD5 hash of an image\nhashFileSync('unicorn.png', {algorithm: 'md5'});\n//=\u003e '1abcb33beeb811dca15f0ac3e47b88d9'\n```\n\n### hashingStream(options?)\n\nReturns a [hash transform stream](https://nodejs.org/api/crypto.html#crypto_class_hash).\n\n```js\nimport {hashingStream} from 'hasha';\n\n// Hash the process input and output the hash sum\nprocess.stdin.pipe(hashingStream()).pipe(process.stdout);\n```\n\n## Related\n\n- [hasha-cli](https://github.com/sindresorhus/hasha-cli) - CLI for this module\n- [crypto-hash](https://github.com/sindresorhus/crypto-hash) - Tiny hashing module that uses the native crypto API in Node.js and the browser\n- [hash-object](https://github.com/sindresorhus/hash-object) - Get the hash of an object\n- [md5-hex](https://github.com/sindresorhus/md5-hex) - Create a MD5 hash with hex encoding\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fhasha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fhasha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fhasha/lists"}