voca
Version:
The ultimate JavaScript string library
46 lines (38 loc) • 1.26 kB
JavaScript
import { i as isNil } from './internal/is_nil.js';
import './is_string.js';
import { c as coerceToString } from './internal/coerce_to_string.js';
import './internal/const.js';
import { t as toString } from './internal/to_string.js';
import './internal/to_integer.js';
import './includes.js';
import trimLeft from './trim_left.js';
import trimRight from './trim_right.js';
/**
* Removes whitespaces from left and right sides of the `subject`.
*
* @function trim
* @static
* @since 1.0.0
* @memberOf Manipulate
* @param {string} [subject=''] The string to trim.
* @param {string} [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped.
* @return {string} Returns the trimmed string.
* @example
* v.trim(' Mother nature ');
* // => 'Mother nature'
*
* v.trim('--Earth--', '-');
* // => 'Earth'
*/
function trim(subject, whitespace) {
var subjectString = coerceToString(subject);
if (whitespace === '' || subjectString === '') {
return subjectString;
}
var whitespaceString = toString(whitespace);
if (isNil(whitespaceString)) {
return subjectString.trim();
}
return trimRight(trimLeft(subjectString, whitespaceString), whitespaceString);
}
export default trim;