Skip to content

Instantly share code, notes, and snippets.

@ianpgall
Last active December 20, 2015 17:19
Show Gist options
  • Save ianpgall/6168164 to your computer and use it in GitHub Desktop.
Save ianpgall/6168164 to your computer and use it in GitHub Desktop.
JavaScript function that pads the left side of a string/number with a specific prefix, up to a specific length
var PadText = (function () {
"use strict";
var func;
func = function (text, prefix, finalLength) {
return (new Array(finalLength).join(prefix.charAt(0)) + text).slice(-finalLength);
};
return func;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment