Nodejs String Trimming Right endTrim(char)

Here you can find the source of endTrim(char)

Method Source Code

String.prototype.endTrim = function (char) {
    let length = this.length;
    if (length) {
        if (this.charAt(length - 1) === char) {
            return this.substring(0, length - 1);
        }//from  w w w  . j  a  v  a2  s .c om
    }
    return this.toString();
};

Related

  1. rightTrim()
    String.prototype.rightTrim=function(){
        return this.replace(/\s+$/,'');
    
  2. TrimEnd( aimStr )
    String.prototype.TrimEnd = function( aimStr )
        var str = this;
        var re = My.RegExp.InvolvedCharsRegExp;
        var reEnd;
        if ( aimStr )
            aimStr = aimStr.replace( re, '\\$1' );
            reEnd = new RegExp( '(' + aimStr + ')+$' );
    ...
    
  3. TrimEnd(v)
    String.prototype.TrimEnd = function (v)
        if (this.substring(this.length - 1, this.length) == v) {
            return this.substring(0, this.length - 1);
        else {
            return this;
    
  4. RTrim()
    String.prototype.RTrim = function() {
        return this.replace(/\s+$/g, "");
    
  5. Rtrim()
    String.prototype.Rtrim = function(){
      return this.replace(/(\s*$)/g, "");
    };