1 var baseToString = require('./_baseToString'),
2 baseTrim = require('./_baseTrim'),
3 castSlice = require('./_castSlice'),
4 charsEndIndex = require('./_charsEndIndex'),
5 charsStartIndex = require('./_charsStartIndex'),
6 stringToArray = require('./_stringToArray'),
7 toString = require('./toString');
10 * Removes leading and trailing whitespace or specified characters from `string`.
16 * @param {string} [string=''] The string to trim.
17 * @param {string} [chars=whitespace] The characters to trim.
18 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
19 * @returns {string} Returns the trimmed string.
25 * _.trim('-_-abc-_-', '_-');
28 * _.map([' foo ', ' bar '], _.trim);
29 * // => ['foo', 'bar']
31 function trim(string, chars, guard) {
32 string = toString(string);
33 if (string && (guard || chars === undefined)) {
34 return baseTrim(string);
36 if (!string || !(chars = baseToString(chars))) {
39 var strSymbols = stringToArray(string),
40 chrSymbols = stringToArray(chars),
41 start = charsStartIndex(strSymbols, chrSymbols),
42 end = charsEndIndex(strSymbols, chrSymbols) + 1;
44 return castSlice(strSymbols, start, end).join('');
47 module.exports = trim;