1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import baseToString from './_baseToString.js';
- import baseTrim from './_baseTrim.js';
- import castSlice from './_castSlice.js';
- import charsEndIndex from './_charsEndIndex.js';
- import charsStartIndex from './_charsStartIndex.js';
- import stringToArray from './_stringToArray.js';
- import toString from './toString.js';
- function trim(string, chars, guard) {
- string = toString(string);
- if (string && (guard || chars === undefined)) {
- return baseTrim(string);
- }
- if (!string || !(chars = baseToString(chars))) {
- return string;
- }
- var strSymbols = stringToArray(string),
- chrSymbols = stringToArray(chars),
- start = charsStartIndex(strSymbols, chrSymbols),
- end = charsEndIndex(strSymbols, chrSymbols) + 1;
- return castSlice(strSymbols, start, end).join('');
- }
- export default trim;
|