Convert string or file contents to SHA1.
First, install to-sha1 globally:
npm i -g to-sha1
You can then use it with pipes:
echo -n "some string I want to hash" | to-sha1
Or passing arguments.
Receives string as argument and return SHA-1:
$ to-sha1 -s "Random text..."
Receives the filepath as argument and return SHA-1 of it's content:
$ to-sha1 -f <filepath>
Displays accepted arguments.
const { toSHA1, sha1 } = require('to-sha1')
//Using SHA1 function directly
//... get file content or text from somewhere ...
var hashedData = sha1(data);
//Using toSHA1 to hash a specific file
toSHA1('filepath', (err, hashedContent) => {
if(err) console.log(`Something went wrong!`, err)
console.log(hashedContent) //or do something else...
})
const { toSHA1, sha1 } = require('to-sha1')
Returns the hash of a given string.
Hash a file asynchronously. If there is any error during processing (eg. file doesn't exist, invalid permissions or it is a directory) cb function will be called with the error as first argument.