From 8fdc669cd08ae0a6b74211b4879b4a8cd21e66d6 Mon Sep 17 00:00:00 2001 From: scscgit Date: Fri, 8 Apr 2022 02:22:33 +0200 Subject: [PATCH] docs: describe parameter types & instruct TS usage --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1cc3db5..6cd6f6d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ console.log(sha256stream.read().toString('hex')) Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial. It does update incrementally, so you can hash things larger than RAM, as it uses a constant amount of memory (except when using base64 or utf8 encoding, see code comments). +## TypeScript + +Library can be used with types, use [`npm i @types/sha.js`](https://www.npmjs.com/package/@types/sha.js) and add `sha.js` under `types` in your `tsconfig.json`. Expected type-checking can be illustrated as follows: +```ts +return sha(algorithm as 'sha' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512') + .update(data as string | NodeJS.ArrayBufferView) + .digest(encoding as 'latin1' | 'hex' | 'base64') +``` ## Acknowledgements This work is derived from Paul Johnston's [A JavaScript implementation of the Secure Hash Algorithm](http://pajhome.org.uk/crypt/md5/sha1.html).