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