Const
.start
removes only leading whitespace (like String.prototype.trimStart)..end
removes only trailing whitespace (like String.prototype.trimEnd)..normalizeWhitespace
trims the string and replaces any sequence of whitespace characters with a single space.// Trim both sides
console.log(trim(" hello ")); // "hello"
console.log(trim("")); // ""
console.log(trim("hello")); // "hello"
// Trim leading whitespace
console.log(trim.start(" hello ")); // "hello "
console.log(trim.start("")); // ""
console.log(trim.start("hello")); // "hello"
// Trim trailing whitespace
console.log(trim.end(" hello ")); // " hello"
console.log(trim.end("")); // ""
console.log(trim.end("hello")); // "hello"
// Normalize whitespace
console.log(trim.normalizeWhitespace(" hello world ")); // "hello world"
console.log(trim.normalizeWhitespace("hello\t world")); // "hello world"
console.log(trim.normalizeWhitespace("")); // ""
String trimming utilities. Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.