Skip to content

Commit b00b7bc

Browse files
Update _string
1 parent 8e1a21d commit b00b7bc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

modules/_string

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ if (!String.prototype.startsWith) {
1919
return this.indexOf(searchString, position) === position;
2020
};
2121
}
22+
23+
if (!String.prototype.padStart) {
24+
String.prototype.padStart = function padStart(targetLength,padString) {
25+
targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
26+
padString = String((typeof padString !== 'undefined' ? padString : ' '));
27+
if (this.length > targetLength) {
28+
return String(this);
29+
}
30+
else {
31+
targetLength = targetLength-this.length;
32+
if (targetLength > padString.length) {
33+
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
34+
}
35+
return padString.slice(0,targetLength) + String(this);
36+
}
37+
};
38+
}

0 commit comments

Comments
 (0)