Skip to content

Commit

Permalink
chore: upgrade multiaddr (#81)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses new major of multiaddr module
  • Loading branch information
achingbrain authored Jul 7, 2021
1 parent 14d8cae commit 2785b23
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

/** @type {import('aegir').PartialOptions} */
module.exports = {
build: {
bundlesizeMax: '12KB'
}
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"scripts": {
"lint": "aegir lint",
"lint": "aegir ts -p check && aegir lint",
"build": "aegir build",
"test": "aegir test",
"test:node": "aegir test --target node",
Expand All @@ -29,14 +29,12 @@
"bugs": "https://github.com/multiformats/js-mafmt/issues",
"homepage": "https://github.com/multiformats/js-mafmt#readme",
"devDependencies": {
"@types/chai": "^4.2.8",
"@types/mocha": "^8.0.0",
"aegir": "^33.0.0",
"uint8arrays": "^2.0.5",
"util": "^0.12.3"
},
"dependencies": {
"multiaddr": "^9.0.1"
"multiaddr": "^10.0.0"
},
"files": [
"src",
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,19 @@ function base (n) {
* @type {MatchesFunction}
*/
function matches (a) {
if (typeof a === 'string') {
let ma

if (typeof a === 'string' || a instanceof Uint8Array) {
try {
a = new Multiaddr(a)
ma = new Multiaddr(a)
} catch (err) { // catch error
return false // also if it's invalid it's propably not matching as well so return false
return false // also if it's invalid it's probably not matching as well so return false
}
} else {
ma = a
}

const pnames = a.protoNames()
const pnames = ma.protoNames()
if (pnames.length === 1 && pnames[0] === name) {
return true
}
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Multiaddr } from 'multiaddr'

export type MatchesFunction = (a: string | Uint8Array | Multiaddr) => boolean
export type PartialMatchesFunction = (protos: string[]) => boolean | string[] | null
Expand Down

0 comments on commit 2785b23

Please sign in to comment.