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

add filter functionality for multiaddr #63

Merged
merged 4 commits into from
Apr 9, 2018
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
4 changes: 4 additions & 0 deletions src/multiaddr-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class MultiaddrSet {
return this._multiaddrs.forEach(fn)
}

filter (fn) {
return this._multiaddrs.filter(fn)
}
Copy link
Member

Choose a reason for hiding this comment

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


has (ma) {
ma = ensureMultiaddr(ma)
return this._multiaddrs.some((m) => m.equals(ma))
Expand Down
10 changes: 10 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ describe('peer-info', () => {
})
})

it('multiaddrs.filter', () => {
const ma1 = Multiaddr('/ip4/127.0.0.1/tcp/7000')
const ma2 = Multiaddr('/ip4/127.0.0.1/tcp/5001')
pi.multiaddrs.add(ma1)
pi.multiaddrs.add(ma2)
const maddrs = pi.multiaddrs.filter((ma) => (ma.equals(ma1)))
expect(maddrs.length).to.eq(1)
expect(maddrs[0].equals(ma1)).to.eq(true)
})

it('multiaddrs.toArray', () => {
pi.multiaddrs.add('/ip4/127.0.0.1/tcp/5001')
pi.multiaddrs.toArray().forEach((ma) => {
Expand Down