Nodejs String Ends With endsWith(value)

Here you can find the source of endsWith(value)

Method Source Code

/*/*from   www  .  j a va2  s .com*/
   Makerator Javascript String Library 1.0
   ====================================================
   Copyright (c) 2009 Chris Corwin
   
   http://chriscorwin.com/about/
   
   
   
   String.endsWith
   ====================================================
   Returns true if the base string ends with the string
   parameter, false otherwise.
   
   Requires a single string parameter.
   
   The test is case sensitive.
   
   
   
   Usage:
   ====================================================
   myString.endsWith('bob');                      // false
   myString.endsWith('Bob');                      // false
   myString.endsWith('The');                      // false
   myString.endsWith('alcoholics.');              // true
   myString.endsWith('all alcoholics.');          // true
   myString.endsWith(' are all alcoholics.');     // true
   myString.endsWith('.');                        // true   
*/
String.prototype.endsWith = function(value) {
   if (this.length < value.length) {
      return false;
   } else {
      return Boolean(this.substr((this.length - value.length), (value.length + 1)) === value);
   }
}

Related

  1. endsWith(test)
    String.prototype.endsWith = function(test) {
      return this.length >= test.length && this.substr(this.length - test.length) == test;
    
  2. endsWith(text)
    String.prototype.endsWith = function (text) {
      return this.substring(this.length - text.length) === text;
    };
    
  3. endsWith(text)
    String.prototype.endsWith = function(text) {
        return text != null && this.lastIndexOf(text) == this.length - text.length;
    };
    
  4. endsWith(value)
    String.prototype.endsWith = function(value) {
      if (!value)
        return false;
      if (value.length > this.length)
        return false;
      var end = this.substring(this.length - value.length);
      return end === value;
    };
    
  5. endsWith(value)
    String.prototype.endsWith = function (value) {
      if (value == undefined || typeof (value) != "string" || value.length > this.length)
        return false;
      if (value.length == 0)
        return true;
      return this.substr(this.length - value.length) == value;
    };
    
  6. endsWith(value)
    String.prototype.endsWith = function(value) {
      var substringLength = value.length;
      var thisLength = this.length;
      if (substringLength > thisLength) {
        return false;
      };
      var howMuchLettersNeedToBeRemooved = thisLength - substringLength;
      var endsString = this.substring(howMuchLettersNeedToBeRemooved);
      if (endsString === value) {
    ...
    
  7. endsWithAny(endings)
    String.prototype.endsWithAny = function (endings) {
      var string = this;
      return endings.some(function (ending) {
        return string.endsWith(ending);
      });
    };
    
  8. endsWithString.prototype.endsWith || (end)
    String.prototype.endsWith = String.prototype.endsWith || function(end){
      return this.substr(this.length - end.length, end.length) === end;
    if (!window.require) {
      window.isBrowser = true;
      window.require = name => {
        if (name === 'path') {
          return {
            sep: '/'
    ...
    
  9. endsWithString.prototype.endsWith || (searchString, length)
    String.prototype.endsWith = String.prototype.endsWith || function(searchString, length) {
        length = typeof length === 'number' && length <  this.length && length >= 0 ? length : this.length;
        return this.substr(length-searchString.length, searchString.length) == searchString;
    console.log("abcd".endsWith("cd", 3));