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

feat: add types to the library #92

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,14 @@
"./src/sha.js": "./src/sha.browser.js"
},
"types": "dist/src/index.d.ts",
"typesVersions": {
"*": {
"src/*": [
"dist/src/*",
"dist/src/*/index"
],
"src/": [
"dist/src/index"
]
}
},
"repository": "github:multiformats/js-multihashing-async",
"scripts": {
"test": "aegir test",
"test:browser": "aegir test -t browser",
"test:node": "aegir test -t node",
"lint": "aegir lint",
"check": "aegir ts -p check",
"prepare": "aegir ts -p types",
"prepare": "aegir build --no-bundle",
"docs": "aegir docs",
"release": "aegir release --docs",
"release-minor": "aegir release --type minor --docs",
Expand All @@ -49,15 +38,14 @@
},
"dependencies": {
"blakejs": "^1.1.0",
"err-code": "git://github.com/gozala/js-err-code#feat/ts-typedefs",
"err-code": "^2.0.3",
"js-sha3": "^0.8.0",
"multihashes": "^3.1.0",
"multihashes": "multiformats/js-multihash#fix/temp-types",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^2.0.5"
},
"devDependencies": {
"@types/sinon": "9.0.9",
"aegir": "^30.1.0",
"aegir": "ipfs/aegir#feat/docs2.0",
"benchmark": "^2.1.4",
"sinon": "^9.0.2"
},
Expand Down
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ const multihash = require('multihashes')
const crypto = require('./crypto')
const equals = require('uint8arrays/equals')

/**
* @typedef {import("./types").Digest} Digest
* @typedef {import("./types").HashName} HashName
*/

/**
* Hash the given `bytes` using the algorithm specified by `alg`.
*
* @param {Uint8Array} bytes - The value to hash.
* @param {import('./types').HashName} alg - The algorithm to use eg 'sha1'
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Uint8Array>}
*/
Expand All @@ -25,7 +30,7 @@ Multihashing.multihash = multihash

/**
* @param {Uint8Array} bytes - The value to hash.
* @param {import('./types').HashName} alg - The algorithm to use eg 'sha1'
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @param {number} [length] - Optionally trim the result to this length.
* @returns {Promise<Uint8Array>}
*/
Expand All @@ -38,8 +43,8 @@ Multihashing.digest = async (bytes, alg, length) => {
/**
* Creates a function that hashes with the given algorithm
*
* @param {import('./types').HashName} alg - The algorithm to use eg 'sha1'
* @returns {import('./types').Digest} - The hash function corresponding to `alg`
* @param {HashName} alg - The algorithm to use eg 'sha1'
* @returns {Digest} - The hash function corresponding to `alg`
*/
Multihashing.createHash = function (alg) {
if (!alg) {
Expand All @@ -58,7 +63,7 @@ Multihashing.createHash = function (alg) {
/**
* Mapping of multihash codes to their hashing functions.
*
* @type {Record<number, import('./types').Digest>}
* @type {Record<number, Digest>}
*/
// @ts-ignore - most of those functions aren't typed
Multihashing.functions = {
Expand Down
2 changes: 1 addition & 1 deletion src/sha.browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable require-await */
'use strict'

const multihash = require('multihashes/src/index')
const multihash = require('multihashes')

const crypto =
self.crypto ||
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist",
"noImplicitAny": true
"outDir": "dist"
Gozala marked this conversation as resolved.
Show resolved Hide resolved
},
"include": [
"test",
Expand Down