Nodejs String Trimming Right trimRight()

Here you can find the source of trimRight()

Method Source Code

String.prototype.trimRight = String.prototype.trimRight || function () {
    return this.replace(/\s+$/g, "");
};

String.prototype.trimLeft = String.prototype.trimLeft || function () {
    return this.replace(/^\s+/g, "");
};

String.prototype.endsWith = String.prototype.endsWith || function(suffix) {
    return this.length ? this.lastIndexOf(suffix) === this.length - 1 : false;
};

String.prototype.startsWith = String.prototype.startsWith || function(prefix) {
    return this.indexOf(prefix) === 0;
};

String.prototype.count = String.prototype.count || function(what) {
    return this.split(what).length - 1;
};

String.prototype.trim = String.prototype.trim || function() {
    return this.trimLeft().trimRight();
};

String.prototype.isEmpty = String.prototype.isEmpty || function() {
    return this.trim().length === 0;
};

String.prototype.isNotEmpty = String.prototype.isNotEmpty || function() {
    return !this.isEmpty();
};

Related

  1. trimEnd(c)
    String.prototype.trimEnd=function(c)
        c = c?c:' ';
        var i=this.length-1;
        for(;i>=0 && this.charAt(i)==c;i--);
        return this.substring(0,i+1);
    var Utils = {
        getValues : function(dataSet)
    ...
    
  2. trimEnd(c)
    String.prototype.trimEnd=function(c)
        c = c?c:' ';
        var i=this.length-1;
        for(;i>=0 && this.charAt(i)==c;i--);
        return this.substring(0,i+1);
    
  3. trimEnd(s)
    String.prototype.trimEnd = function(s) {
        return this.replace(new RegExp(s + "+$", "gm"), "")
    
  4. trimEnd(trimStr)
    String.prototype.trimEnd = function (trimStr) {
        if (!trimStr) {
            return this;
        var temp = this;
        while (true) {
            if (temp.substr(temp.length - trimStr.length, trimStr.length) != trimStr) {
                break;
            temp = temp.substr(0, temp.length - trimStr.length);
        return temp;
    
  5. trimRight()
    String.prototype.trimRight = String.prototype.trimRight || function() {
      return this.replace(/\s+$/,'');
    };
    
  6. trimRight(character)
    String.prototype.trimRight = function (character) {
      character = character || ' ';
      return this.replace(new RegExp('[' + character + ']+$'), "");
    };
    
  7. trimRight(charlist)
    String.prototype.trimRight = function(charlist) {
        "use strict";
        if (charlist === undefined)
            charlist = "\s";
        return this.replace(new RegExp("[" + charlist + "]+$"), "");
    };
    
  8. trimRighttrimRight()
    if (!String.prototype.trimRight)
    String.prototype.trimRight = function trimRight() {
      return this.replace(/(?:\s|\u00A0)+$/, '');
    };
    
  9. rightTrim()
    String.prototype.rightTrim = function () {
        return this.replace(/\s+$/, "");