Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createPadding.js
1 var repeat = require('../string/repeat');
2
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeCeil = Math.ceil,
5     nativeIsFinite = global.isFinite;
6
7 /**
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`.
10  *
11  * @private
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`.
16  */
17 function createPadding(string, length, chars) {
18   var strLength = string.length;
19   length = +length;
20
21   if (strLength >= length || !nativeIsFinite(length)) {
22     return '';
23   }
24   var padLength = length - strLength;
25   chars = chars == null ? ' ' : (chars + '');
26   return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
27 }
28
29 module.exports = createPadding;