Skip to content

Commit

Permalink
update String#leftPad with proposal: string filler truncated from t…
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 26, 2015
1 parent 6dad33d commit 7b15772
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
4 changes: 1 addition & 3 deletions library/modules/$.string-pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ module.exports = function(that, maxLength, fillString, left){
if(fillStr == '')fillStr = ' ';
var fillLen = intMaxLength - stringLength
, stringFiller = repeat.call(fillStr, Math.ceil(fillLen / fillStr.length));
if(stringFiller.length > fillLen)stringFiller = left
? stringFiller.slice(stringFiller.length - fillLen)
: stringFiller.slice(0, fillLen);
if(stringFiller.length > fillLen)stringFiller = stringFiller.slice(0, fillLen);
return left ? stringFiller + S : S + stringFiller;
};
4 changes: 1 addition & 3 deletions modules/$.string-pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ module.exports = function(that, maxLength, fillString, left){
if(fillStr == '')fillStr = ' ';
var fillLen = intMaxLength - stringLength
, stringFiller = repeat.call(fillStr, Math.ceil(fillLen / fillStr.length));
if(stringFiller.length > fillLen)stringFiller = left
? stringFiller.slice(stringFiller.length - fillLen)
: stringFiller.slice(0, fillLen);
if(stringFiller.length > fillLen)stringFiller = stringFiller.slice(0, fillLen);
return left ? stringFiller + S : S + stringFiller;
};
2 changes: 1 addition & 1 deletion tests/library/es7.string.pad-left.ls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test 'String#padLeft' (assert)->
{padLeft} = core.String
assert.ok typeof! padLeft is \Function, 'is function'
assert.strictEqual padLeft(\abc 5), ' abc'
assert.strictEqual padLeft(\abc 4 \de), \eabc
assert.strictEqual padLeft(\abc 4 \de), \dabc
assert.strictEqual padLeft(\abc), \abc
assert.strictEqual padLeft(\abc 5 '_'), '__abc'
assert.strictEqual padLeft('' 0), ''
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/es7.string.pad-left.ls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test 'String#padLeft' (assert)->
assert.ok /native code/.test(String::padLeft), 'looks like native'
assert.strictEqual String::padLeft.name, \padLeft, 'name is "padLeft"'
assert.strictEqual 'abc'padLeft(5), ' abc'
assert.strictEqual 'abc'padLeft(4 \de), \eabc
assert.strictEqual 'abc'padLeft(4 \de), \dabc
assert.strictEqual 'abc'padLeft!, \abc
assert.strictEqual 'abc'padLeft(5 '_'), '__abc'
assert.strictEqual ''padLeft(0), ''
Expand Down

0 comments on commit 7b15772

Please sign in to comment.