data-2-hash
Advanced tools
Comparing version 1.1.0 to 1.2.0
#!/usr/bin/env node | ||
var program = require('commander'), | ||
chalk = require('chalk'), | ||
Hash = require('../'), | ||
pkg = require('../package.json'); | ||
var program = require('commander'); | ||
var chalk = require('chalk'); | ||
var Hash = require('../'); | ||
var pkg = require('../package.json'); | ||
program | ||
.version(pkg.version) | ||
.usage('<hash-function> <data> [options]') | ||
.option('-l, --list', 'Print all available hash functions') | ||
.option('-f, --file', 'Execute hashing of file') | ||
.parse(process.argv); | ||
.version(pkg.version) | ||
.usage('<hash-function> <data> [options]') | ||
.option('-l, --list', 'Print all available hash functions') | ||
.option('-f, --file', 'Execute hashing of file') | ||
.parse(process.argv); | ||
if (!!program.list) { | ||
for (var i = 0; i < Hash.SUPPORTED_HASHES.length; i++) { | ||
var hash = Hash.SUPPORTED_HASHES[i]; | ||
process.stdout.write(chalk.yellow(hash) + ' -- ' + chalk.blue('d2h ' + hash + ' <data>') + ' || ' + chalk.blue('d2h ' + hash + ' <file> --file\n')); | ||
} | ||
for (var i = 0; i < Hash.SUPPORTED_HASHES.length; i++) { | ||
var hash = Hash.SUPPORTED_HASHES[i]; | ||
process.stdout.write(chalk.yellow(hash) + ' -- ' + chalk.blue('d2h ' + hash + ' <data>') + ' || ' + chalk.blue('d2h ' + hash + ' <file> --file\n')); | ||
} | ||
process.exit(0); | ||
process.exit(0); | ||
} else if (!!program.file) { | ||
process.stdout.write('Calculating...\n'); | ||
process.stdout.write('Calculating...\n'); | ||
return new Hash(program.args[0], program.args[1], true).on('done', function (hash) { | ||
process.stdout.write(hash + '\n'); | ||
process.exit(0); | ||
}); | ||
return new Hash(program.args[0], program.args[1], true).on('done', function (hash) { | ||
process.stdout.write(hash + '\n'); | ||
process.exit(0); | ||
}); | ||
} else { | ||
process.stdout.write(new Hash(program.args[0], program.args[1]).digest() + '\n'); | ||
process.exit(0); | ||
process.stdout.write(new Hash(program.args[0], program.args[1]).digest() + '\n'); | ||
process.exit(0); | ||
} |
# Changelog | ||
## Version 1.2.0 | ||
- Just code styling; | ||
## Version 1.1.0 | ||
@@ -4,0 +8,0 @@ |
@@ -1,5 +0,5 @@ | ||
var crypto = require('crypto'), | ||
fs = require('fs'), | ||
util = require('util'), | ||
EventEmitter = require('events').EventEmitter; | ||
var crypto = require('crypto'); | ||
var fs = require('fs'); | ||
var util = require('util'); | ||
var EventEmitter = require('events').EventEmitter; | ||
@@ -23,23 +23,23 @@ util.inherits(Hash, EventEmitter); | ||
function Hash(algorithm, data, isFile) { | ||
EventEmitter.apply(this, arguments); | ||
EventEmitter.call(this); | ||
if (SUPPORTED_HASHES.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported algorithm'); | ||
} | ||
if (SUPPORTED_HASHES.indexOf(algorithm) === -1) { | ||
throw new Error('Unsupported algorithm'); | ||
} | ||
this._setHash(crypto.createHash(algorithm)); | ||
this._setHash(crypto.createHash(algorithm)); | ||
if (isFile) { | ||
if (!(fs.existsSync(data) && fs.lstatSync(data).isFile())) { | ||
throw new Error('File not exists'); | ||
} | ||
if (isFile) { | ||
if (!(fs.existsSync(data) && fs.lstatSync(data).isFile())) { | ||
throw new Error('File not exists'); | ||
} | ||
fs.createReadStream(data) | ||
.on('data', this.update.bind(this)) | ||
.on('end', function () { | ||
this.emit('done', this.digest()); | ||
}.bind(this)); | ||
} else if (data) { | ||
this.update(data); | ||
} | ||
fs.createReadStream(data) | ||
.on('data', this.update.bind(this)) | ||
.on('end', function () { | ||
this.emit('done', this.digest()); | ||
}.bind(this)); | ||
} else if (data) { | ||
this.update(data); | ||
} | ||
} | ||
@@ -53,3 +53,3 @@ | ||
Hash.prototype._getHash = function () { | ||
return this._hash; | ||
return this._hash; | ||
}; | ||
@@ -64,4 +64,4 @@ | ||
Hash.prototype._setHash = function (hash) { | ||
this._hash = hash; | ||
return this; | ||
this._hash = hash; | ||
return this; | ||
}; | ||
@@ -75,4 +75,4 @@ | ||
Hash.prototype.update = function (data) { | ||
this._getHash().update(data); | ||
return this; | ||
this._getHash().update(data); | ||
return this; | ||
}; | ||
@@ -85,3 +85,3 @@ | ||
Hash.prototype.digest = function () { | ||
return this._getHash().digest('hex'); | ||
return this._getHash().digest('hex'); | ||
}; | ||
@@ -88,0 +88,0 @@ |
{ | ||
"name": "data-2-hash", | ||
"version": "1.1.0", | ||
"description": "Tiny wrapper for crypto and CLI where you can call crypto functions from console", | ||
"main": "index.js", | ||
"keywords": [ | ||
"crypto", | ||
"cli", | ||
"wrapper", | ||
"hash", | ||
"file" | ||
], | ||
"bin": { | ||
"d2h": "./bin/d2h.js" | ||
}, | ||
"scripts": { | ||
"test": "node ./node_modules/.bin/istanbul cover --report lcovonly ./node_modules/.bin/_mocha -- --recursive --reporter spec", | ||
"prepublish": "npm test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ghaiklor/data-2-hash.git" | ||
}, | ||
"author": "ghaiklor", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ghaiklor/data-2-hash/issues" | ||
}, | ||
"homepage": "https://github.com/ghaiklor/data-2-hash", | ||
"devDependencies": { | ||
"istanbul": "^0.3.7", | ||
"mocha": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.0.0", | ||
"commander": "^2.6.0" | ||
} | ||
"name": "data-2-hash", | ||
"version": "1.2.0", | ||
"description": "Tiny wrapper for crypto and CLI where you can call crypto functions from console", | ||
"main": "index.js", | ||
"keywords": [ | ||
"crypto", | ||
"cli", | ||
"wrapper", | ||
"hash", | ||
"file" | ||
], | ||
"bin": { | ||
"d2h": "./bin/d2h.js" | ||
}, | ||
"scripts": { | ||
"test": "istanbul cover _mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ghaiklor/data-2-hash.git" | ||
}, | ||
"author": { | ||
"name": "Eugene Obrezkov", | ||
"email": "ghaiklor@gmail.com", | ||
"url": "https://github.com/ghaiklor" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ghaiklor/data-2-hash/issues" | ||
}, | ||
"homepage": "https://github.com/ghaiklor/data-2-hash", | ||
"devDependencies": { | ||
"istanbul": "^0.3.7", | ||
"mocha": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.0.0", | ||
"commander": "^2.6.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
27113
15