Skip to content

Commit

Permalink
Add IPv4.prototype.toNormalizedString for symmetry with the IPv6 me…
Browse files Browse the repository at this point in the history
…thod

Fixes #67
  • Loading branch information
JamesMGreene authored and whitequark committed Aug 20, 2017
1 parent 83174a9 commit c2bcc6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ipaddr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/ipaddr.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
return this.octets.join(".");
};

IPv4.prototype.toNormalizedString = function() {
return this.toString();
};

IPv4.prototype.toByteArray = function() {
return this.octets.slice(0);
};
Expand Down
4 changes: 4 additions & 0 deletions src/ipaddr.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ipaddr.IPv4
toString: ->
return @octets.join "."

# Symmetrical method strictly for aligning with the IPv6 methods.
toNormalizedString: ->
return this.toString()

# Returns an array of byte-sized values in network order (MSB first)
toByteArray: ->
return @octets.slice(0) # octets.clone
Expand Down
1 change: 1 addition & 0 deletions test/ipaddr.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports =
'converts IPv4 to string correctly': (test) ->
addr = new ipaddr.IPv4([192, 168, 1, 1])
test.equal(addr.toString(), '192.168.1.1')
test.equal(addr.toNormalizedString(), '192.168.1.1')
test.done()

'returns correct kind for IPv4': (test) ->
Expand Down

0 comments on commit c2bcc6f

Please sign in to comment.