Nodejs String Ends With ends( other )

Here you can find the source of ends( other )

Method Source Code

String.prototype.ends = function( other ){
  // True if this string is at the end of the other one
  if( !other )return false
  var endlen   = this.length
  var otherlen = other.length
  if( !endlen || endlen > otherlen ){ return false }
  // ToDo: should avoid concatenation
  return other.substr( 0, otherlen - endlen) + this == other
}

function str_ends( that, other ){
// Like that.ends( other) but sometimes faster
  // True if this string is at the end of the other one
  if( !other )return false
  var endlen   = this.length
  var otherlen = other.length
  if( !endlen || endlen > otherlen ){ return false }
  // ToDo: should avoid concatenation
  return other.substr( 0, otherlen - endlen) + that == other
}

Related

  1. EndsWith( str )
    String.prototype.EndsWith = function( str )
        return this.lastIndexOf( str ) == this.length - str.length;
    };
    
  2. endWith(endStr)
    String.prototype.endWith = function (endStr) {
        var lastIndex = this.length - endStr.length;
        return (lastIndex > 0 && this.lastIndexOf(endStr) == lastIndex);
    };
    
  3. endWith(endStr)
    function ConvertJSONDateToJSDate(jsondate) {
        var date = new Date(parseInt(jsondate.replace("/Date(", "").replace(")/", ""), 10));
        return date;
    function getDate(date) {
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        return year + "-" + month + "-" + day;
    ...
    
  4. endsWith( keyword, ignoreCase)
    jCube.String.endsWith  =
    String.prototype.endsWith  = function( keyword, ignoreCase) {
      var _string  = this;
      if ( ignoreCase == true ) {
        _string  = _string.toLowerCase();
        keyword  = keyword.toLowerCase();
      return _string.substring( _string.length-keyword.length) == keyword;
    
  5. endsWith( str )
    String.prototype.endsWith = function( str ) {
        if( str.length > this.length ) {
            return false;
        return( String( this ).substr( this.length - str.length, this.length ) == str );
    };
    
  6. endsWith( value, ignoreCase )
    String.prototype.endsWith = function( value, ignoreCase )
      var L1 = this.length ;
      var L2 = value.length ;
      if ( L2 > L1 )
        return false ;
      if ( ignoreCase )
        var oRegex = new RegExp( value + '$' , 'i' ) ;
    ...
    
  7. endsWith(end)
    String.prototype.endsWith = function(end) {
      return this.indexOf(end) == this.length-end.length;
    };