pax_global_header00006660000000000000000000000064140437460140014515gustar00rootroot0000000000000052 comment=199598328d4d11b938f86a9ba9b82dc0796c8331 md5-hex-4.0.0/000077500000000000000000000000001404374601400127655ustar00rootroot00000000000000md5-hex-4.0.0/.editorconfig000066400000000000000000000002571404374601400154460ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 md5-hex-4.0.0/.gitattributes000066400000000000000000000000231404374601400156530ustar00rootroot00000000000000* text=auto eol=lf md5-hex-4.0.0/.github/000077500000000000000000000000001404374601400143255ustar00rootroot00000000000000md5-hex-4.0.0/.github/workflows/000077500000000000000000000000001404374601400163625ustar00rootroot00000000000000md5-hex-4.0.0/.github/workflows/main.yml000066400000000000000000000006641404374601400200370ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 16 - 14 - 12 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test md5-hex-4.0.0/.gitignore000066400000000000000000000000271404374601400147540ustar00rootroot00000000000000node_modules yarn.lock md5-hex-4.0.0/.npmrc000066400000000000000000000000231404374601400141000ustar00rootroot00000000000000package-lock=false md5-hex-4.0.0/browser.js000066400000000000000000000002421404374601400150040ustar00rootroot00000000000000import blueimpMd5 from 'blueimp-md5'; export default function md5Hex(data) { if (Array.isArray(data)) { data = data.join(''); } return blueimpMd5(data); } md5-hex-4.0.0/index.d.ts000066400000000000000000000010631404374601400146660ustar00rootroot00000000000000/** Create a MD5 hash with hex encoding. @param data - Prefer buffers as they're faster to hash, but strings can be useful for small things. Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation. @example ``` import fs from 'node:fs'; import md5Hex from 'md5-hex'; const buffer = fs.readFileSync('unicorn.png'); md5Hex(buffer); //=> '1abcb33beeb811dca15f0ac3e47b88d9' ``` */ export default function md5Hex(data: Buffer | string | ReadonlyArray): string; md5-hex-4.0.0/index.js000066400000000000000000000006231404374601400144330ustar00rootroot00000000000000import crypto from 'node:crypto'; export default function md5Hex(data) { const hash = crypto.createHash('md5'); const update = buffer => { const inputEncoding = typeof buffer === 'string' ? 'utf8' : undefined; hash.update(buffer, inputEncoding); }; if (Array.isArray(data)) { for (const element of data) { update(element); } } else { update(data); } return hash.digest('hex'); } md5-hex-4.0.0/index.test-d.ts000066400000000000000000000005201404374601400156400ustar00rootroot00000000000000import {expectType} from 'tsd'; import * as fs from 'node:fs'; import md5Hex from './index.js'; const buffer = fs.readFileSync('unicorn.png'); expectType(md5Hex(buffer)); expectType(md5Hex([buffer])); expectType(md5Hex('foo')); expectType(md5Hex(['foo'])); expectType(md5Hex([buffer, 'foo'])); md5-hex-4.0.0/license000066400000000000000000000021351404374601400143330ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. md5-hex-4.0.0/package.json000066400000000000000000000014471404374601400152610ustar00rootroot00000000000000{ "name": "md5-hex", "version": "4.0.0", "description": "Create a MD5 hash with hex encoding", "license": "MIT", "repository": "sindresorhus/md5-hex", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": { "node": "./index.js", "default": "./browser.js" }, "engines": { "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts", "browser.js" ], "keywords": [ "hash", "crypto", "md5", "hex", "buffer", "browser" ], "dependencies": { "blueimp-md5": "^2.18.0" }, "devDependencies": { "@types/node": "^15.0.1", "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.39.1" } } md5-hex-4.0.0/readme.md000066400000000000000000000021611404374601400145440ustar00rootroot00000000000000# md5-hex > Create a MD5 hash with hex encoding *Please don't use MD5 hashes for anything sensitive!* Works in the browser too, when used with a bundler like Webpack, Rollup, Browserify. Checkout [`hasha`](https://github.com/sindresorhus/hasha) if you need something more flexible. ## Install ``` $ npm install md5-hex ``` ## Usage ```js import fs from 'node:fs'; import md5Hex from 'md5-hex'; const buffer = fs.readFileSync('unicorn.png'); md5Hex(buffer); //=> '1abcb33beeb811dca15f0ac3e47b88d9' ``` ## API ### md5Hex(data) #### data Type: `Buffer | string | Array` Prefer buffers as they're faster to hash, but strings can be useful for small things. Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation. ## Related - [crypto-hash](https://github.com/sindresorhus/crypto-hash) - Tiny hashing module that uses the native crypto API in Node.js and the browser - [hasha](https://github.com/sindresorhus/hasha) - Hashing made simple - [hash-obj](https://github.com/sindresorhus/hash-obj) - Get the hash of an object md5-hex-4.0.0/test.js000066400000000000000000000010331404374601400142770ustar00rootroot00000000000000import test from 'ava'; import md5Hex from './index.js'; import md5HexBrowser from './browser.js'; test('main', t => { t.is(md5Hex('unicorn'), '1abcb33beeb811dca15f0ac3e47b88d9'); t.is(md5Hex(Buffer.from('unicorn')), '1abcb33beeb811dca15f0ac3e47b88d9'); t.is(md5Hex(['uni', 'corn']), '1abcb33beeb811dca15f0ac3e47b88d9'); t.is(md5Hex(['uni', Buffer.from('corn')]), '1abcb33beeb811dca15f0ac3e47b88d9'); }); test('ensure the Node.js and browser version match', t => { t.is(md5Hex('中文chinese'), md5HexBrowser('中文chinese')); });