General API
hash()
asyncGenerates a hash from the specified data.
- Accepts the specified data as a string, number, array, or object, and accepts optional arguments as either a number specifying how many characters to keep in the resulting hash, or a string indicating the algorithm: "SHA-1", "SHA-256", "SHA-384", or "SHA-512".
The default algorithm is "SHA-256". - Returns the generated hash as a string.
Example:
await 'book'.hash();
// 'f10eb448275d33b2615096fd0438cddc692ee1cc41e0484708dd60e467936ada'
await 'book'.hash(10);
// 'f10eb44827'
await 'book'.hash('SHA-384');
// 'e6466f4cd47e5f964423f29ec682e0977c9464f7de6382bca2038e406ccdb3be844f66f5ff853e701c0be26a7065b432'
await 'book'.hash('SHA-384', 10);
// 'e6466f4cd4'
await (10).hash();
// '4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5'
await ['book', 'cat'].hash();
// 'cf8711d25539ed749b10543286c6e07554b26117a2d26db6b9b4f48087697a97'
await {book: 'cat'}.hash('SHA-1');
// '844d6888615bfcb5e43cae09af35259d38779259'