The lodash _.pad, _.padStart, and _.padEnd methods for padding strings in javaScript.
So today I will be putting together another quick post on lodash as well as vanilla js alternatives to using lodash when it comes to the process of quickly padding strings. What I mean by padding is making it so a string is always a certain fixed length of characters, so in the event that a string is lower than that fixed length a number of chars of a given value are used to pad the remaining number of characters.
With lodash there is the _.pad, _.padStart, and _.padEnd methods that can be used to make quick work of string padding with lodash. If lodash is part of the project these methods are there to work with, but I will be looking at some other options as well when it comes to just native javaScript alone for padding strings. With that said in late javaScript specs there are padding methods baked into core javaScript now, these methods are the String.padStart and String.padEnd String prototype methods. In addition to that of native String prototype methods, if you want better backward support there are some concise tricks for this that will still work just fine in most older javaScript specs.