Skip to content

Commit

Permalink
fix: return ports as ints not strings (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnchris authored and jacobheun committed Aug 5, 2019
1 parent 811b343 commit 2a170c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ Multiaddr.prototype.toJSON = Multiaddr.prototype.toString
/**
* Returns Multiaddr as a convinient options object to be used with net.createConnection
*
* @returns {{family: String, host: String, transport: String, port: String}}
* @returns {{family: String, host: String, transport: String, port: Number}}
* @example
* Multiaddr('/ip4/127.0.0.1/tcp/4001').toOptions()
* // { family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: '4001' }
* // { family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: 4001 }
*/
Multiaddr.prototype.toOptions = function toOptions () {
const opts = {}
const parsed = this.toString().split('/')
opts.family = parsed[1] === 'ip4' ? 'ipv4' : 'ipv6'
opts.host = parsed[2]
opts.transport = parsed[3]
opts.port = parsed[4]
opts.port = parseInt(parsed[4])
return opts
}

Expand Down Expand Up @@ -321,7 +321,7 @@ Multiaddr.prototype.equals = function equals (addr) {
*
* Has to be a ThinWaist Address, otherwise throws error
*
* @returns {{family: String, address: String, port: String}}
* @returns {{family: String, address: String, port: Number}}
* @throws {Error} Throws error if Multiaddr is not a Thin Waist address
* @example
* Multiaddr('/ip4/127.0.0.1/tcp/4001').nodeAddress()
Expand All @@ -343,7 +343,7 @@ Multiaddr.prototype.nodeAddress = function nodeAddress () {
return {
family: (codes[0] === 41 || codes[0] === 55) ? 6 : 4,
address: parts[1], // ip addr
port: parts[3] // tcp or udp port
port: parseInt(parts[3]) // tcp or udp port
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ describe('helpers', () => {
family: 'ipv4',
host: '0.0.0.0',
transport: 'tcp',
port: '1234'
port: 1234
})
})
})
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('helpers', () => {
).to.be.eql({
address: '192.168.0.1',
family: 4,
port: '1234'
port: 1234
})
})

Expand All @@ -639,7 +639,7 @@ describe('helpers', () => {
).to.be.eql({
address: 'wss0.bootstrap.libp2p.io',
family: 4,
port: '443'
port: 443
})
})

Expand Down

0 comments on commit 2a170c3

Please sign in to comment.