Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / trim.js
1 var charsEndIndex = require('./internal/charsEndIndex'),
2     charsStartIndex = require('./internal/charsStartIndex'),
3     stringToArray = require('./internal/stringToArray'),
4     toString = require('./toString');
5
6 /** Used to match leading and trailing whitespace. */
7 var reTrim = /^\s+|\s+$/g;
8
9 /**
10  * Removes leading and trailing whitespace or specified characters from `string`.
11  *
12  * @static
13  * @memberOf _
14  * @category String
15  * @param {string} [string=''] The string to trim.
16  * @param {string} [chars=whitespace] The characters to trim.
17  * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
18  * @returns {string} Returns the trimmed string.
19  * @example
20  *
21  * _.trim('  abc  ');
22  * // => 'abc'
23  *
24  * _.trim('-_-abc-_-', '_-');
25  * // => 'abc'
26  *
27  * _.map(['  foo  ', '  bar  '], _.trim);
28  * // => ['foo', 'bar']
29  */
30 function trim(string, chars, guard) {
31   string = toString(string);
32   if (!string) {
33     return string;
34   }
35   if (guard || chars === undefined) {
36     return string.replace(reTrim, '');
37   }
38   chars = (chars + '');
39   if (!chars) {
40     return string;
41   }
42   var strSymbols = stringToArray(string),
43       chrSymbols = stringToArray(chars);
44
45   return strSymbols.slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1).join('');
46 }
47
48 module.exports = trim;