Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / pad.js
1 var createPadding = require('./internal/createPadding'),
2     stringSize = require('./internal/stringSize'),
3     toInteger = require('./toInteger'),
4     toString = require('./toString');
5
6 /* Built-in method references for those with the same name as other `lodash` methods. */
7 var nativeCeil = Math.ceil,
8     nativeFloor = Math.floor;
9
10 /**
11  * Pads `string` on the left and right sides if it's shorter than `length`.
12  * Padding characters are truncated if they can't be evenly divided by `length`.
13  *
14  * @static
15  * @memberOf _
16  * @category String
17  * @param {string} [string=''] The string to pad.
18  * @param {number} [length=0] The padding length.
19  * @param {string} [chars=' '] The string used as padding.
20  * @returns {string} Returns the padded string.
21  * @example
22  *
23  * _.pad('abc', 8);
24  * // => '  abc   '
25  *
26  * _.pad('abc', 8, '_-');
27  * // => '_-abc_-_'
28  *
29  * _.pad('abc', 3);
30  * // => 'abc'
31  */
32 function pad(string, length, chars) {
33   string = toString(string);
34   length = toInteger(length);
35
36   var strLength = stringSize(string);
37   if (!length || strLength >= length) {
38     return string;
39   }
40   var mid = (length - strLength) / 2,
41       leftLength = nativeFloor(mid),
42       rightLength = nativeCeil(mid);
43
44   return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars);
45 }
46
47 module.exports = pad;