Skip to content

Commit

Permalink
Implemented utils.leftPad.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Apr 11, 2014
1 parent 5dccb43 commit f545947
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/unexpected-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var utils = namespace.utils;
var isRegExp = utils.isRegExp;
var leftPad = utils.leftPad;

expect.addType({
identify: function (obj) {
Expand Down Expand Up @@ -69,7 +70,7 @@
for (var j = 0 ; j < width ; j += 1) {
if (i + j < obj.length) {
var octet = obj[i + j];
hexChars += (octet < 16 ? '0' : '') + octet.toString(16).toUpperCase() + ' ';
hexChars += leftPad(octet.toString(16).toUpperCase(), 2, '0') + ' ';
asciiChars += (octet >= 32 && octet < 127) ? String.fromCharCode(octet) : '.';
} else {
hexChars += ' ';
Expand Down
8 changes: 8 additions & 0 deletions lib/unexpected-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@
}
}
return null;
},

leftPad: function (str, width, ch) {
ch = ch || ' ';
while (str.length < width) {
str = ch + str;
}
return str;
}
};

Expand Down

0 comments on commit f545947

Please sign in to comment.