Last active
June 29, 2018 02:09
-
-
Save Calerme/782f9e8e7d04522797504ee8a9ba409b to your computer and use it in GitHub Desktop.
String.prototype.padStart Polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
String.prototype.padStart = String.prototype.padStart || function padStart (targetLength, content) { | |
content = String(content) | |
if (this.length >= targetLength) { | |
return this | |
} | |
var needLength = targetLength - this.length; | |
var needStr = content; | |
do { | |
needStr = needStr.substr(0, needLength); | |
if (needStr.length === needLength) { | |
break | |
} | |
needStr += content | |
} while(true); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment