Skip to content

Instantly share code, notes, and snippets.

@Calerme
Last active June 29, 2018 02:09
Show Gist options
  • Save Calerme/782f9e8e7d04522797504ee8a9ba409b to your computer and use it in GitHub Desktop.
Save Calerme/782f9e8e7d04522797504ee8a9ba409b to your computer and use it in GitHub Desktop.
String.prototype.padStart Polyfill
(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