1 var repeat = require('../string/repeat');
3 /** Native method references. */
6 /* Native method references for those with the same name as other `lodash` methods. */
7 var nativeIsFinite = global.isFinite;
10 * Creates the padding required for `string` based on the given `length`.
11 * The `chars` string is truncated if the number of characters exceeds `length`.
14 * @param {string} string The string to create padding for.
15 * @param {number} [length=0] The padding length.
16 * @param {string} [chars=' '] The string used as padding.
17 * @returns {string} Returns the pad for `string`.
19 function createPadding(string, length, chars) {
20 var strLength = string.length;
23 if (strLength >= length || !nativeIsFinite(length)) {
26 var padLength = length - strLength;
27 chars = chars == null ? ' ' : (chars + '');
28 return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
31 module.exports = createPadding;