Nodejs String Ends With endsWith( value, ignoreCase )

Here you can find the source of endsWith( value, ignoreCase )

Method Source Code

// Extends the String object, creating a "endsWith" method on it.
String.prototype.endsWith = function( value, ignoreCase )
{
   var L1 = this.length ;
   var L2 = value.length ;
   //from w ww  .j  ava  2 s  .  co m
   if ( L2 > L1 )
      return false ;

   if ( ignoreCase )
   {
      var oRegex = new RegExp( value + '$' , 'i' ) ;
      return oRegex.test( this ) ;
   }
   else
      return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
}

Related

  1. endWith(endStr)
    String.prototype.endWith = function (endStr) {
        var lastIndex = this.length - endStr.length;
        return (lastIndex > 0 && this.lastIndexOf(endStr) == lastIndex);
    };
    
  2. 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;
    ...
    
  3. ends( other )
    String.prototype.ends = function( other ){
      if( !other )return false
      var endlen   = this.length
      var otherlen = other.length
      if( !endlen || endlen > otherlen ){ return false }
      return other.substr( 0, otherlen - endlen) + this == other
    function str_ends( that, other ){
      if( !other )return false
    ...
    
  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(end)
    String.prototype.endsWith = function(end) {
      return this.indexOf(end) == this.length-end.length;
    };
    
  7. endsWith(end)
    String.prototype.endsWith = function(end) {
        if(end == '') return true;
        else if(end == null || end.length > this.length) return false;
        else return this.indexOf(end, this.length - end.length) !== -1;
    
  8. endsWith(matchstring)
    String.prototype.endsWith = function (matchstring) {
        return reverse(this).startsWith(reverse(matchstring));
    
  9. endsWith(needle)
    String.prototype.endsWith = function(needle) {
        return this.slice(-needle.length) == needle;