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

Added distinctMultiaddr method #29

Merged
merged 5 commits into from
Nov 22, 2016
Merged
Changes from 2 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
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Id = require('peer-id')
const multiaddr = require('multiaddr')
const _ = require('lodash')
Copy link
Member

Choose a reason for hiding this comment

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

use const uniqBy = require('lodash.uniqBy') if that is the only feature you are going to use, it saves in bundle size :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

David, I have not seen a require like this: require('lodash.uniqBy'), did you mean like this: require('lodash').uniqBy? Or am I missing something?


exports = module.exports = PeerInfo

Expand Down Expand Up @@ -88,6 +89,13 @@ function PeerInfo (peerId) {
})
}

this.distinctMultiaddr = () => {
var result = _.uniqBy(this.multiaddrs, function (item) {
return [item.toOptions().port, item.toOptions().transport].join()
})
return result
}

// TODO: add features to fetch multiaddr using filters
// look at https://github.com/whyrusleeping/js-mafmt/blob/master/src/index.js
}
Expand Down