Pad a string to a certain length with .pad()


Description: add a pad of characters to a string up to a certain length .


<!doctype html>
    <html lang="en">
      <meta charset="utf-8">
      <title>pad demo</title>
      <script src=""></script>
    <p class="padded"></p>
      bitsyCode(".padded").html(bitsyCode.pad("1", { direction:"left", padWith:"0", size:6 }));


  • Usage

    • How to use:

      Specify a value with the needed options.

    • Specify a value you want to add a pad to.

      bitsyCode.pad("string", { direction:"left", padWith:"0", size:6 })
    • Example Usage:
      bitsyCode.pad("2"); // Result: 02
      bitsyCode.pad("2", { direction:"left", padWith:"0", size:6 }); // Result: 000002
  • Options

    • What options are there:
      direction: 'left' (default value) // Specify if the string pad should occur on the left or right of string.
      padWith: '0' (default value) // Specify what character should be used as a pad.
      size: 2 (default value) // Specify the size of the pad, this size will exclude the string length, so when specifying "size" add the pad length plus the string length.
  • Returns

    • Returns:

      Padded string.