π Prefer String#trimStart() / String#trimEnd() over String#trimLeft() / String#trimRight().
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
String#trimLeft() and String#trimRight() are deprecated aliases for String#trimStart() and String#trimEnd(). The newer names use direction-independent wording that works correctly with both left-to-right and right-to-left languages.
// β - Deprecated names
const name = ' John '.trimLeft();
// β
- Preferred method
const name = ' John '.trimStart();// β
const value = text.trimRight();
// β
const value = text.trimEnd();// β
- All three do the same thing
const str = ' hello world ';
str.trim(); // Remove from both sides
str.trimStart(); // Remove from beginning
str.trimEnd(); // Remove from endtrimStart() and trimEnd() are more appropriate for international text, as "left" and "right" don't make sense in right-to-left languages like Arabic or Hebrew.