From 3b99dfa331b8160d59ebb9da31791f2676760ba9 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Tue, 6 Dec 2016 16:25:10 +0100 Subject: [PATCH 1/3] docs(api): first pass --- .gitignore | 1 + .npmignore | 3 ++- src/index.js | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 907c78a7..6b9f1541 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ build/Release node_modules dist +docs \ No newline at end of file diff --git a/.npmignore b/.npmignore index 59a480e2..94581de5 100644 --- a/.npmignore +++ b/.npmignore @@ -26,4 +26,5 @@ build/Release # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules -test \ No newline at end of file +test +docs \ No newline at end of file diff --git a/src/index.js b/src/index.js index 8c554084..7fdadfe2 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,16 @@ const crypto = require('./crypto') module.exports = Multihashing +/** + * Hash the given `buf` using the algorithm specified + * by `func`. + * + * @param {Buffer} buf - The value to hash. + * @param {number|string} func - The algorithm to use. + * @param {number} [length] - Optionally trim the result to this length. + * @param {function(Error, Buffer)} callback + * @returns {undefined} + */ function Multihashing (buf, func, length, callback) { if (typeof length === 'function') { callback = length @@ -24,11 +34,25 @@ function Multihashing (buf, func, length, callback) { }) } +/** + * The `buffer` module for easy use in the browser. + * + * @type {Buffer} + */ Multihashing.Buffer = Buffer // for browser things -// expose multihash itself, to avoid silly double requires. +/** + * Expose multihash itself, to avoid silly double requires. + */ Multihashing.multihash = multihash +/** + * @param {Buffer} buf - The value to hash. + * @param {number|string} func - The algorithm to use. + * @param {number} [length] - Optionally trim the result to this length. + * @param {function(Error, Buffer)} callback + * @returns {undefined} + */ Multihashing.digest = function (buf, func, length, callback) { if (typeof length === 'function') { callback = length @@ -60,6 +84,11 @@ Multihashing.digest = function (buf, func, length, callback) { hash(buf, cb) } +/** + * @param {string|number} func + * + * @returns {function} - The to `func` corresponding hash function. + */ Multihashing.createHash = function (func) { func = multihash.coerceCode(func) if (!Multihashing.functions[func]) { @@ -69,6 +98,10 @@ Multihashing.createHash = function (func) { return Multihashing.functions[func] } +/** + * Mapping of multihash codes to their hashing functions. + * @type {Object} + */ Multihashing.functions = { // sha1 0x11: crypto.sha1, From 1c32ebc73189a148fc8acee178ec62c19b48ac7e Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Mon, 12 Dec 2016 12:00:56 +0100 Subject: [PATCH 2/3] update aegir tasks --- package.json | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 298c1dd3..42476275 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,10 @@ "test:browser": "aegir-test browser", "test:node": "aegir-test node", "lint": "aegir-lint", - "release": "aegir-release", - "release-minor": "aegir-release minor", - "release-major": "aegir-release major", + "docs": "aegir-docs", + "release": "aegir-release --docs", + "release-minor": "aegir-release minor --docs", + "release-major": "aegir-release major --docs", "build": "aegir-build", "coverage": "aegir-coverage", "coverage-publish": "aegir-coverage publish", @@ -42,10 +43,10 @@ "nodeify": "^1.0.0" }, "devDependencies": { - "aegir": "^9.1.2", + "aegir": "^9.2.2", "benchmark": "^2.1.2", "chai": "^3.5.0", - "pre-commit": "^1.1.3" + "pre-commit": "^1.2.1" }, "engines": { "node": ">=4.0.0" @@ -60,4 +61,4 @@ "Richard Littauer ", "npm-to-cdn-bot (by Forbes Lindesay) " ] -} \ No newline at end of file +} From c962837dd03cb54894c1d1a92c80473ddaaa8c6d Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Wed, 14 Dec 2016 14:47:00 +0100 Subject: [PATCH 3/3] add example --- README.md | 12 ++++-------- example.js | 19 +++++++++++++++++++ package.json | 4 ++-- 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 example.js diff --git a/README.md b/README.md index c1e994ed..744f89ec 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,6 @@ and [`browserify-sha3`](https://github.com/wanderer/browserify-sha3) are used. * [Examples](#examples) + [Multihash output](#multihash-output) * [API](#api) - + [`multihashing(buf, func, [length,] callback)`](#multihashingbuf-func-length-callback) - + [`digest(buf, func, [length,] callback)`](#digestbuf-func-length-callback) - + [`createHash(func)`](#createhashfunc) - + [`functions`](#functions) * [Maintainers](#maintainers) * [Contribute](#contribute) * [License](#license) @@ -109,16 +105,16 @@ h(buf, (err, digest) => { ### Multihash output ```js -> const multihashing = require('multihashing') +> const multihashing = require('multihashing-async') > const buf = new Buffer('beep boop') -> multihashing(buf, 'sha1'), (err, mh) => console.log(mh)) +> multihashing(buf, 'sha1', (err, mh) => console.log(mh)) // => -> multihashing(buf, 'sha2-256', (err, mh) => onsole.log(mh)) +> multihashing(buf, 'sha2-256', (err, mh) => console.log(mh)) // => -> multihashing(buf, 'sha2-512'), (err, mh) => console.log(mh)) +> multihashing(buf, 'sha2-512', (err, mh) => console.log(mh)) // => ``` diff --git a/example.js b/example.js new file mode 100644 index 00000000..c5c4f1b7 --- /dev/null +++ b/example.js @@ -0,0 +1,19 @@ +'use strict' + +const multihashing = require('multihashing-async') +const buf = new Buffer('beep boop') + +function print (err, mh) { + if (err) { + throw err + } + console.log(mh) +} +multihashing(buf, 'sha1', print) +// => + +multihashing(buf, 'sha2-256', print) +// => + +multihashing(buf, 'sha2-512', print) +// => diff --git a/package.json b/package.json index 42476275..412b69a3 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,10 @@ "nodeify": "^1.0.0" }, "devDependencies": { - "aegir": "^9.2.2", + "aegir": "^9.3.0", "benchmark": "^2.1.2", "chai": "^3.5.0", - "pre-commit": "^1.2.1" + "pre-commit": "^1.2.2" }, "engines": { "node": ">=4.0.0"