Nodejs String Strip stripNewline(str)

Here you can find the source of stripNewline(str)

Method Source Code

String.prototype.stripNewline = function(str){
    /*from  ww  w  .  j a  v a2s .com*/
    var trimLoc = this.indexOf("\r\n");
    
    if (trimLoc < 0) {
        trimLoc = this.indexOf("\n");
    }
    
    if (trimLoc < 0) {
        trimLoc = this.indexOf("\r");
    }
    
    if (trimLoc > 0) {
        return this.substring(0, trimLoc)
    }
    
    return this;
}

Related

  1. stripFilePath(path)
    function  {
        if (path.lastIndexOf("file:///") > -1) {
            path = path.substring(path.lastIndexOf("file:///") + 8);
        return path;
    
  2. lstrip()
    String.prototype.lstrip = function(){
      return this.replace(/^\s+/,'')
    
  3. rstrip()
    String.prototype.rstrip = function () {
       return this.replace(/\s+$/, "")
    };
    
  4. rstrip()
    String.prototype.rstrip = function(){
      return  this.replace(/\s+$/,'')
    
  5. rstrip(chars)
    String.prototype.rstrip = function (chars) {
        let regex = new RegExp(chars + "$");
        return this.replace(regex, "");
    };
    
  6. stripNewlines()
    String.prototype.stripNewlines = function() {
        return this.replace(/[\n\r]/g,"");
    
  7. stripPunctuation()
    String.prototype.stripPunctuation = function () {
      return this.replace(/\W+/, '');
    
  8. stripScripts()
    String.prototype.stripScripts = function()
        return this.replace(new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'img'), '');
    };
    
  9. stripSlashes()
    function now(){
      return (new Date()).getTime();
    String.prototype.stripSlashes = function(){
        return this.replace(/\\(.)/mg, "$1");