1 var repeat = require('../string/repeat');
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeCeil = Math.ceil,
5 nativeIsFinite = global.isFinite;
8 * Creates the padding required for `string` based on the given `length`.
9 * The `chars` string is truncated if the number of characters exceeds `length`.
12 * @param {string} string The string to create padding for.
13 * @param {number} [length=0] The padding length.
14 * @param {string} [chars=' '] The string used as padding.
15 * @returns {string} Returns the pad for `string`.
17 function createPadding(string, length, chars) {
18 var strLength = string.length;
21 if (strLength >= length || !nativeIsFinite(length)) {
24 var padLength = length - strLength;
25 chars = chars == null ? ' ' : (chars + '');
26 return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
29 module.exports = createPadding;