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

Commit 93ab644

Browse files
authored
fix: update aegir and fix types (#79)
1 parent d8080af commit 93ab644

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"main": "src/index.js",
2222
"repository": "github:multiformats/js-multibase",
2323
"scripts": {
24-
"prepare": "aegir build",
24+
"prepare": "aegir build --no-bundle",
2525
"lint": "aegir lint",
2626
"test": "aegir test",
2727
"test:node": "aegir test -t node",
@@ -35,10 +35,10 @@
3535
},
3636
"dependencies": {
3737
"@multiformats/base-x": "^4.0.1",
38-
"web-encoding": "^1.0.4"
38+
"web-encoding": "^1.0.6"
3939
},
4040
"devDependencies": {
41-
"aegir": "^29.0.1",
41+
"aegir": "^30.3.0",
4242
"benchmark": "^2.1.4"
4343
},
4444
"engines": {

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { encodeText, decodeText, concat } = require('./util')
1010
/** @typedef {import('./base')} Base */
1111
/** @typedef {import("./types").BaseNameOrCode} BaseNameOrCode */
1212
/** @typedef {import("./types").BaseCode} BaseCode */
13+
/** @typedef {import("./types").BaseName} BaseName */
1314

1415
/**
1516
* Create a new Uint8Array with the multibase varint+code.
@@ -113,10 +114,10 @@ function validEncode (name, buf) {
113114
* @throws {Error} Will throw if the encoding is not supported
114115
*/
115116
function encoding (nameOrCode) {
116-
if (constants.names[nameOrCode]) {
117-
return constants.names[nameOrCode]
118-
} else if (constants.codes[nameOrCode]) {
119-
return constants.codes[nameOrCode]
117+
if (constants.names[/** @type {BaseName} */(nameOrCode)]) {
118+
return constants.names[/** @type {BaseName} */(nameOrCode)]
119+
} else if (constants.codes[/** @type {BaseCode} */(nameOrCode)]) {
120+
return constants.codes[/** @type {BaseCode} */(nameOrCode)]
120121
} else {
121122
throw new Error(`Unsupported encoding: ${nameOrCode}`)
122123
}

src/rfc4648.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
const decode = (string, alphabet, bitsPerChar) => {
1212
// Build the character lookup table:
13+
/** @type {Record<string, number>} */
1314
const codes = {}
1415
for (let i = 0; i < alphabet.length; ++i) {
1516
codes[alphabet[i]] = i

src/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type BaseCode =
2424
| 'm'
2525
| 'M'
2626
| 'u'
27-
| 'U';
27+
| 'U'
2828

2929
/**
3030
* - Names of the supported encodings
@@ -52,11 +52,11 @@ export type BaseName =
5252
| 'base64'
5353
| 'base64pad'
5454
| 'base64url'
55-
| 'base64urlpad';
55+
| 'base64urlpad'
5656

57-
export type BaseNameOrCode = BaseCode | BaseName;
58-
export type Codec = {
59-
encode: (buffer: Uint8Array) => string;
60-
decode: (hash: string) => Uint8Array;
61-
};
62-
export type CodecFactory = (input: string) => Codec;
57+
export type BaseNameOrCode = BaseCode | BaseName
58+
export interface Codec {
59+
encode: (buffer: Uint8Array) => string
60+
decode: (hash: string) => Uint8Array
61+
}
62+
export interface CodecFactory { (input: string): Codec }

test/multibase.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { encodeText, decodeText } = require('../src/util')
66
const multibase = require('../src')
77
const constants = require('../src/constants.js')
88

9+
/** @type {Array<[BaseName, string, string]>} */
910
const unsupportedBases = []
1011

1112
/**
@@ -88,6 +89,10 @@ const supportedBases = [
8889
['base64urlpad', '÷ïÿ🥰÷ïÿ😎🥶🤯', 'Uw7fDr8O_8J-lsMO3w6_Dv_CfmI7wn6W28J-krw==']
8990
]
9091

92+
/**
93+
* @param {string} label
94+
* @param {(encodeText:(text: string) => Uint8Array) => void} def
95+
*/
9196
const they = (label, def) => {
9297
it(`${label} (Uint8Array)`, def.bind(null, encodeText))
9398
}

0 commit comments

Comments
 (0)