Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Commit 77567a7

Browse files
docs(api): first pass
1 parent 0d94dfc commit 77567a7

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ build/Release
2727
node_modules
2828

2929
dist
30+
docs

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ build/Release
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
2828

29-
test
29+
test
30+
docs

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ and [`browserify-sha3`](https://github.com/wanderer/browserify-sha3) are used.
3737
* [Examples](#examples)
3838
+ [Multihash output](#multihash-output)
3939
* [API](#api)
40-
+ [`multihashing(buf, func, [length,] callback)`](#multihashingbuf-func-length-callback)
41-
+ [`digest(buf, func, [length,] callback)`](#digestbuf-func-length-callback)
42-
+ [`createHash(func)`](#createhashfunc)
43-
+ [`functions`](#functions)
4440
* [Maintainers](#maintainers)
4541
* [Contribute](#contribute)
4642
* [License](#license)
@@ -109,16 +105,16 @@ h(buf, (err, digest) => {
109105
### Multihash output
110106

111107
```js
112-
> const multihashing = require('multihashing')
108+
> const multihashing = require('multihashing-async')
113109
> const buf = new Buffer('beep boop')
114110

115-
> multihashing(buf, 'sha1'), (err, mh) => console.log(mh))
111+
> multihashing(buf, 'sha1', (err, mh) => console.log(mh))
116112
// => <Buffer 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
117113

118-
> multihashing(buf, 'sha2-256', (err, mh) => onsole.log(mh))
114+
> multihashing(buf, 'sha2-256', (err, mh) => console.log(mh))
119115
// => <Buffer 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
120116

121-
> multihashing(buf, 'sha2-512'), (err, mh) => console.log(mh))
117+
> multihashing(buf, 'sha2-512', (err, mh) => console.log(mh))
122118
// => <Buffer 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>
123119
```
124120

example.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const multihashing = require('multihashing-async')
4+
const buf = new Buffer('beep boop')
5+
6+
function print (err, mh) {
7+
if (err) {
8+
throw err
9+
}
10+
console.log(mh)
11+
}
12+
multihashing(buf, 'sha1', print)
13+
// => <Buffer 11 14 7c 83 57 57 7f 51 d4 f0 a8 d3 93 aa 1a aa fb 28 86 3d 94 21>
14+
15+
multihashing(buf, 'sha2-256', print)
16+
// => <Buffer 12 20 90 ea 68 8e 27 5d 58 05 67 32 50 32 49 2b 59 7b c7 72 21 c6 24 93 e7 63 30 b8 5d dd a1 91 ef 7c>
17+
18+
multihashing(buf, 'sha2-512', print)
19+
// => <Buffer 13 40 14 f3 01 f3 1b e2 43 f3 4c 56 68 93 78 83 77 1f a3 81 00 2f 1a aa 5f 31 b3 f7 8e 50 0b 66 ff 2f 4f 8e a5 e3 c9 f5 a6 1b d0 73 e2 45 2c 48 04 84 b0 ...>

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"test:browser": "aegir-test browser",
1212
"test:node": "aegir-test node",
1313
"lint": "aegir-lint",
14-
"release": "aegir-release",
15-
"release-minor": "aegir-release minor",
16-
"release-major": "aegir-release major",
14+
"docs": "aegir-docs",
15+
"release": "aegir-release --docs",
16+
"release-minor": "aegir-release minor --docs",
17+
"release-major": "aegir-release major --docs",
1718
"build": "aegir-build",
1819
"coverage": "aegir-coverage",
1920
"coverage-publish": "aegir-coverage publish",
@@ -42,10 +43,10 @@
4243
"nodeify": "^1.0.0"
4344
},
4445
"devDependencies": {
45-
"aegir": "^9.1.2",
46+
"aegir": "^9.3.0",
4647
"benchmark": "^2.1.2",
4748
"chai": "^3.5.0",
48-
"pre-commit": "^1.1.3"
49+
"pre-commit": "^1.2.2"
4950
},
5051
"engines": {
5152
"node": ">=4.0.0"
@@ -60,4 +61,4 @@
6061
"Richard Littauer <[email protected]>",
6162
"npm-to-cdn-bot (by Forbes Lindesay) <[email protected]>"
6263
]
63-
}
64+
}

src/index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ const crypto = require('./crypto')
55

66
module.exports = Multihashing
77

8+
/**
9+
* Hash the given `buf` using the algorithm specified
10+
* by `func`.
11+
*
12+
* @param {Buffer} buf - The value to hash.
13+
* @param {number|string} func - The algorithm to use.
14+
* @param {number} [length] - Optionally trim the result to this length.
15+
* @param {function(Error, Buffer)} callback
16+
* @returns {undefined}
17+
*/
818
function Multihashing (buf, func, length, callback) {
919
if (typeof length === 'function') {
1020
callback = length
@@ -24,11 +34,25 @@ function Multihashing (buf, func, length, callback) {
2434
})
2535
}
2636

37+
/**
38+
* The `buffer` module for easy use in the browser.
39+
*
40+
* @type {Buffer}
41+
*/
2742
Multihashing.Buffer = Buffer // for browser things
2843

29-
// expose multihash itself, to avoid silly double requires.
44+
/**
45+
* Expose multihash itself, to avoid silly double requires.
46+
*/
3047
Multihashing.multihash = multihash
3148

49+
/**
50+
* @param {Buffer} buf - The value to hash.
51+
* @param {number|string} func - The algorithm to use.
52+
* @param {number} [length] - Optionally trim the result to this length.
53+
* @param {function(Error, Buffer)} callback
54+
* @returns {undefined}
55+
*/
3256
Multihashing.digest = function (buf, func, length, callback) {
3357
if (typeof length === 'function') {
3458
callback = length
@@ -60,6 +84,11 @@ Multihashing.digest = function (buf, func, length, callback) {
6084
hash(buf, cb)
6185
}
6286

87+
/**
88+
* @param {string|number} func
89+
*
90+
* @returns {function} - The to `func` corresponding hash function.
91+
*/
6392
Multihashing.createHash = function (func) {
6493
func = multihash.coerceCode(func)
6594
if (!Multihashing.functions[func]) {
@@ -69,6 +98,10 @@ Multihashing.createHash = function (func) {
6998
return Multihashing.functions[func]
7099
}
71100

101+
/**
102+
* Mapping of multihash codes to their hashing functions.
103+
* @type {Object}
104+
*/
72105
Multihashing.functions = {
73106
// sha1
74107
0x11: crypto.sha1,

0 commit comments

Comments
 (0)