1 | var baseToString = require('./_baseToString'),
|
2 | castSlice = require('./_castSlice'),
|
3 | charsEndIndex = require('./_charsEndIndex'),
|
4 | charsStartIndex = require('./_charsStartIndex'),
|
5 | stringToArray = require('./_stringToArray'),
|
6 | toString = require('./toString');
|
7 |
|
8 |
|
9 | var reTrim = /^\s+|\s+$/g;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function trim(string, chars, guard) {
|
34 | string = toString(string);
|
35 | if (string && (guard || chars === undefined)) {
|
36 | return string.replace(reTrim, '');
|
37 | }
|
38 | if (!string || !(chars = baseToString(chars))) {
|
39 | return string;
|
40 | }
|
41 | var strSymbols = stringToArray(string),
|
42 | chrSymbols = stringToArray(chars),
|
43 | start = charsStartIndex(strSymbols, chrSymbols),
|
44 | end = charsEndIndex(strSymbols, chrSymbols) + 1;
|
45 |
|
46 | return castSlice(strSymbols, start, end).join('');
|
47 | }
|
48 |
|
49 | module.exports = trim;
|