Skip to content

Instantly share code, notes, and snippets.

@kawanet
Created June 2, 2016 19:02
Show Gist options
  • Save kawanet/e3a19451b24142a70d0e4eaef5a6eb00 to your computer and use it in GitHub Desktop.
Save kawanet/e3a19451b24142a70d0e4eaef5a6eb00 to your computer and use it in GitHub Desktop.

Revisions

  1. kawanet revised this gist Jun 2, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions pad.js
    Original file line number Diff line number Diff line change
    @@ -23,3 +23,5 @@ function pad(char) {
    return array.join("");
    }
    }

    if ("undefined" !== typeof module) module.exports = pad;
  2. kawanet revised this gist Jun 2, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pad.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    * @param char {String}
    * @returns {Function}
    * @license MIT
    * @see https://gist.github.com/kawanet/e3a19451b24142a70d0e4eaef5a6eb00
    */

    function pad(char) {
  3. kawanet created this gist Jun 2, 2016.
    24 changes: 24 additions & 0 deletions pad.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * sprintf("%08d", x) == pad("0")(8)(x)
    *
    * @param char {String}
    * @returns {Function}
    * @license MIT
    */

    function pad(char) {
    return function(len) {
    var prefix = padder(len);
    return function(str) {
    return (str == null) ? prefix : (prefix + str).substr(-len);
    };
    };

    function padder(len) {
    var array = [];
    for (var i = 0; i < len; i++) {
    array[i] = char;
    }
    return array.join("");
    }
    }