Nodejs String Ends With sl_endsWith(str)

Here you can find the source of sl_endsWith(str)

Method Source Code

String.prototype.sl_endsWith = function(str) {
  if (typeof String.prototype.endsWith != 'function') {
    return this.indexOf(str, this.length - str.length - 1) !== -1;
  }/*from   ww  w  . jav  a 2 s  .  c om*/
  return this.endsWith(str);
}

String.prototype.sl_startsWith = function(str) {
  if (typeof String.prototype.startsWith != 'function') {
    return this.slice(0, str.length) === str;
  }
  return this.startsWith(str);
}

Related

  1. endswith(needle)
    String.prototype.endswith = function (needle) {
       var nedlen = needle.length;
       var haylen = this.length;
       if (nedlen > haylen) {
          return false; 
       return this.lastIndexOf(needle) === haylen-nedlen;
    };
    
  2. endswith(s)
    String.prototype.endswith = function(s) {
      return (this.match(s+"$")==s)
    
  3. endswith(str)
    String.prototype.endswith = function(str)
      return this.slice(this.length - str.length) === str;
    };
    
  4. endswith(str)
    String.prototype.endswith = function(str) {
      return (this.indexOf(str, this.length - str.length) !== -1) ? true: false;
    
  5. endswith(suffix)
    String.prototype.endswith = function(suffix) {
        return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };
    
  6. endWith(char)
    String.prototype.endWith = function(char) {
      let string = String(this);
      return (new RegExp(".*" + char + "$").test(string));
    
  7. endWith(s)
    String.prototype.endWith = function (s) {
        var d = this.length - s.length;
        return (d >= 0 && this.lastIndexOf(s) == d)
    
  8. endWith(s)
    String.prototype.endWith = function(s) {
      if (s === null || s === "" || this.length === 0 || s.length > this.length)
        return false;
      if (this.substring(this.length - s.length) == s)
        return true;
      else
        return false;
      return true;
    
  9. endWith(str)
    String.prototype.endWith = function(str){
      return this.lastIndexOf(str) == this.length - str.length;
    };