Comparing version 2.2.0 to 3.0.0
37
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var crypto = require('crypto'); | ||
var isStream = require('is-stream'); | ||
var Promise = require('pinkie-promise'); | ||
const fs = require('fs'); | ||
const crypto = require('crypto'); | ||
const isStream = require('is-stream'); | ||
var hasha = module.exports = function (input, opts) { | ||
const hasha = (input, opts) => { | ||
opts = opts || {}; | ||
var outputEncoding = opts.encoding || 'hex'; | ||
let outputEncoding = opts.encoding || 'hex'; | ||
@@ -16,6 +15,6 @@ if (outputEncoding === 'buffer') { | ||
var hash = crypto.createHash(opts.algorithm || 'sha512'); | ||
const hash = crypto.createHash(opts.algorithm || 'sha512'); | ||
var update = function (buf) { | ||
var inputEncoding = typeof buf === 'string' ? 'utf8' : undefined; | ||
const update = buf => { | ||
const inputEncoding = typeof buf === 'string' ? 'utf8' : undefined; | ||
hash.update(buf, inputEncoding); | ||
@@ -33,6 +32,6 @@ }; | ||
hasha.stream = function (opts) { | ||
hasha.stream = opts => { | ||
opts = opts || {}; | ||
var outputEncoding = opts.encoding || 'hex'; | ||
let outputEncoding = opts.encoding || 'hex'; | ||
@@ -43,3 +42,3 @@ if (outputEncoding === 'buffer') { | ||
var stream = crypto.createHash(opts.algorithm || 'sha512'); | ||
const stream = crypto.createHash(opts.algorithm || 'sha512'); | ||
stream.setEncoding(outputEncoding); | ||
@@ -49,3 +48,3 @@ return stream; | ||
hasha.fromStream = function (stream, opts) { | ||
hasha.fromStream = (stream, opts) => { | ||
if (!isStream(stream)) { | ||
@@ -57,3 +56,3 @@ return Promise.reject(new TypeError('Expected a stream')); | ||
return new Promise(function (resolve, reject) { | ||
return new Promise((resolve, reject) => { | ||
stream | ||
@@ -69,8 +68,6 @@ .on('error', reject) | ||
hasha.fromFile = function (fp, opts) { | ||
return hasha.fromStream(fs.createReadStream(fp), opts); | ||
}; | ||
hasha.fromFile = (fp, opts) => hasha.fromStream(fs.createReadStream(fp), opts); | ||
hasha.fromFileSync = function (fp, opts) { | ||
return hasha(fs.readFileSync(fp), opts); | ||
}; | ||
hasha.fromFileSync = (fp, opts) => hasha(fs.readFileSync(fp), opts); | ||
module.exports = hasha; |
{ | ||
"name": "hasha", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Hashing made simple. Get the hash of a buffer/string/stream/file.", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -45,4 +45,3 @@ "scripts": { | ||
"dependencies": { | ||
"is-stream": "^1.0.1", | ||
"pinkie-promise": "^2.0.0" | ||
"is-stream": "^1.0.1" | ||
}, | ||
@@ -49,0 +48,0 @@ "devDependencies": { |
@@ -30,3 +30,3 @@ <h1 align="center"> | ||
```js | ||
var hasha = require('hasha'); | ||
const hasha = require('hasha'); | ||
@@ -38,5 +38,5 @@ hasha('unicorn'); | ||
```js | ||
var hasha = require('hasha'); | ||
const hasha = require('hasha'); | ||
// hash the process input and output the hash sum | ||
// Hash the process input and output the hash sum | ||
process.stdin.pipe(hasha.stream()).pipe(process.stdout); | ||
@@ -46,6 +46,6 @@ ``` | ||
```js | ||
var hasha = require('hasha'); | ||
const hasha = require('hasha'); | ||
// get the MD5 hash of an image | ||
hasha.fromFile('unicorn.png', {algorithm: 'md5'}).then(function (hash) { | ||
// Get the MD5 hash of an image | ||
hasha.fromFile('unicorn.png', {algorithm: 'md5'}).then(hash => { | ||
console.log(hash); | ||
@@ -67,7 +67,7 @@ //=> '1abcb33beeb811dca15f0ac3e47b88d9' | ||
Type: `buffer`, `string`, `array` of `string`|`buffer` | ||
Type: `Buffer` `string` `Buffer[]` `string[]` | ||
Buffer you want to hash. | ||
While strings are supported you should prefer buffers as they're faster to hash. Though if you already have a string you should not convert it to a buffer. | ||
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. | ||
@@ -80,5 +80,5 @@ Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation. | ||
Type: `string` | ||
Default: `hex` | ||
Values: `hex`, `base64`, `buffer`, `binary` | ||
Type: `string`<br> | ||
Default: `hex`<br> | ||
Values: `hex` `base64` `buffer` `binary` | ||
@@ -89,5 +89,5 @@ Encoding of the returned hash. | ||
Type: `string` | ||
Default: `sha512` | ||
Values: `md5`, `sha1`, `sha256`, `sha512`, etc *([platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm))* | ||
Type: `string`<br> | ||
Default: `sha512`<br> | ||
Values: `md5` `sha1` `sha256` `sha512` *([Platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm))* | ||
@@ -102,7 +102,7 @@ *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.](http://googleonlinesecurity.blogspot.no/2014/09/gradually-sunsetting-sha-1.html)* | ||
Returns a promise that resolves to a hash. | ||
Returns a `Promise` for a hash. | ||
### hasha.fromFile(filepath, [options]) | ||
Returns a promise that resolves to a hash. | ||
Returns a `Promise` for a hash. | ||
@@ -127,2 +127,2 @@ ### hasha.fromFileSync(filepath, [options]) | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
6369
50
- Removedpinkie-promise@^2.0.0
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)