UNPKG

fillo

Version:

Fill a value with characters to the given size.

20 lines (19 loc) 640 B
"use strict"; /** * fillo * Fill additional characters at the beginning of the string. * * @name fillo * @function * @param {String|Number} what The input snippet (number, string or anything that can be stringified). * @param {Number} size The width of the final string (default: `2`). * @param {String} ch The character to repeat (default: `"0"`). * @return {String} The input value with filled characters. */ module.exports = function fillo(what, size, ch) { size = size || 2; ch = ch || "0"; what = what.toString(); var howMany = size - what.length; return (howMany <= 0 ? "" : String(ch).repeat(howMany)) + what; };