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

fix: update aegir and fix types #79

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"main": "src/index.js",
"repository": "github:multiformats/js-multibase",
"scripts": {
"prepare": "aegir build",
"prepare": "aegir build --no-bundle",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep the prepare script around? Or only when in development for testing purposes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It believe it is in place to use git url in dependent packages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt hurt i guess, dunno maybe we should discuss it

"lint": "aegir lint",
"test": "aegir test",
"test:node": "aegir test -t node",
Expand All @@ -35,10 +35,10 @@
},
"dependencies": {
"@multiformats/base-x": "^4.0.1",
"web-encoding": "^1.0.4"
"web-encoding": "^1.0.6"
},
"devDependencies": {
"aegir": "^29.0.1",
"aegir": "^30.3.0",
"benchmark": "^2.1.4"
},
"engines": {
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { encodeText, decodeText, concat } = require('./util')
/** @typedef {import('./base')} Base */
/** @typedef {import("./types").BaseNameOrCode} BaseNameOrCode */
/** @typedef {import("./types").BaseCode} BaseCode */
/** @typedef {import("./types").BaseName} BaseName */

/**
* Create a new Uint8Array with the multibase varint+code.
Expand Down Expand Up @@ -113,10 +114,10 @@ function validEncode (name, buf) {
* @throws {Error} Will throw if the encoding is not supported
*/
function encoding (nameOrCode) {
if (constants.names[nameOrCode]) {
return constants.names[nameOrCode]
} else if (constants.codes[nameOrCode]) {
return constants.codes[nameOrCode]
if (constants.names[/** @type {BaseName} */(nameOrCode)]) {
return constants.names[/** @type {BaseName} */(nameOrCode)]
} else if (constants.codes[/** @type {BaseCode} */(nameOrCode)]) {
return constants.codes[/** @type {BaseCode} */(nameOrCode)]
} else {
throw new Error(`Unsupported encoding: ${nameOrCode}`)
}
Expand Down
1 change: 1 addition & 0 deletions src/rfc4648.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
const decode = (string, alphabet, bitsPerChar) => {
// Build the character lookup table:
/** @type {Record<string, number>} */
const codes = {}
for (let i = 0; i < alphabet.length; ++i) {
codes[alphabet[i]] = i
Expand Down
16 changes: 8 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type BaseCode =
| 'm'
| 'M'
| 'u'
| 'U';
| 'U'

/**
* - Names of the supported encodings
Expand Down Expand Up @@ -52,11 +52,11 @@ export type BaseName =
| 'base64'
| 'base64pad'
| 'base64url'
| 'base64urlpad';
| 'base64urlpad'

export type BaseNameOrCode = BaseCode | BaseName;
export type Codec = {
encode: (buffer: Uint8Array) => string;
decode: (hash: string) => Uint8Array;
};
export type CodecFactory = (input: string) => Codec;
export type BaseNameOrCode = BaseCode | BaseName
export interface Codec {
encode: (buffer: Uint8Array) => string
decode: (hash: string) => Uint8Array
}
export interface CodecFactory { (input: string): Codec }
5 changes: 5 additions & 0 deletions test/multibase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { encodeText, decodeText } = require('../src/util')
const multibase = require('../src')
const constants = require('../src/constants.js')

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

/**
Expand Down Expand Up @@ -88,6 +89,10 @@ const supportedBases = [
['base64urlpad', '÷ïÿ🥰÷ïÿ😎🥶🤯', 'Uw7fDr8O_8J-lsMO3w6_Dv_CfmI7wn6W28J-krw==']
]

/**
* @param {string} label
* @param {(encodeText:(text: string) => Uint8Array) => void} def
*/
const they = (label, def) => {
it(`${label} (Uint8Array)`, def.bind(null, encodeText))
}
Expand Down