Skip to content

Commit

Permalink
Simplified the IPv6.prototype.toString method
Browse files Browse the repository at this point in the history
Fixes #84
  • Loading branch information
JamesMGreene committed Sep 14, 2017
1 parent 8f6e210 commit b96fa42
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 95 deletions.
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.

56 changes: 1 addition & 55 deletions lib/ipaddr.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,61 +226,7 @@
};

IPv6.prototype.toString = function() {
var addr, compactStringParts, k, len, part, pushPart, state, stringParts, suffix;
stringParts = (function() {
var k, len, ref, results;
ref = this.parts;
results = [];
for (k = 0, len = ref.length; k < len; k++) {
part = ref[k];
results.push(part.toString(16));
}
return results;
}).call(this);
compactStringParts = [];
pushPart = function(part) {
return compactStringParts.push(part);
};
state = 0;
for (k = 0, len = stringParts.length; k < len; k++) {
part = stringParts[k];
switch (state) {
case 0:
if (part === '0') {
pushPart('');
} else {
pushPart(part);
}
state = 1;
break;
case 1:
if (part === '0') {
state = 2;
} else {
pushPart(part);
}
break;
case 2:
if (part !== '0') {
pushPart('');
pushPart(part);
state = 3;
}
break;
case 3:
pushPart(part);
}
}
if (state === 2) {
pushPart('');
pushPart('');
}
addr = compactStringParts.join(":");
suffix = '';
if (this.zoneId) {
suffix = '%' + this.zoneId;
}
return addr + suffix;
return this.toNormalizedString().replace(/((^|:)(0(:|$))+)/, '::');
};

IPv6.prototype.toByteArray = function() {
Expand Down
Loading

0 comments on commit b96fa42

Please sign in to comment.