Nodejs String Starts With beginsWith(s)

Here you can find the source of beginsWith(s)

Method Source Code

String.prototype.beginsWith= function(s)
{
    return s===this.substring(0, s.length);
}

/** Safari 2 doesn't define the localeCompare. This probably will be slow.
 **///from ww  w  . j  a  v a 2s .  co m
if (!String.prototype.localeCompare)
    String.prototype.localeCompare = function(other)
    {
        if (this < other)
            return -1;
        else if (this > other)
            return 1;
        else
            return 0;
    }

String.prototype.expand = function(obj, defaultValue)
{
    function lookupKey(str, key)
    {
        var value= obj[key];
        if (null===value || 'undefined'===typeof(value))
            return defaultValue;
        return value;
    }

    return this.replace(/\$\{(\w+)\}/g, lookupKey);
}

Related

  1. startWith(substr)
    String.prototype.startWith = function(substr) {
        return this.indexOf(substr) == 0;
    };
    
  2. startWith(text)
    String.prototype.startWith = function (text) {
        return this.indexOf(text) == 0;
    };
    var msg = "Hello world!";
    console.log(msg.startWith("Hello"));
    
  3. startWithVowel()
    String.prototype.startWithVowel = function () {
        return this.charAt(0).toLowerCase().isVowel();
    };
    String.prototype.isVowel = function () {
        var vowels = ['a', 'e', 'i', 'o', 'u'];
        return vowels.indexOf(this.toLowerCase()) != -1;
    };
    
  4. beginsWith( str )
    String.prototype.beginsWith = function( str ) {
        return this.substr( 0, str.length ) == str;
    };
    
  5. beginsWith(s)
    String.prototype.beginsWith = function(s){
        return this.indexOf(s) == 0;
    };
    
  6. beginsWith(t)
    String.prototype.beginsWith = function(t) {
        'use strict';
        t = t.toString();
        return (t.toString() === this.substring(0, t.length));
    };
    String.prototype.trim = function() {
        'use strict';
        return this.replace(/^\s+/,'').replace(/\s+$/,'');
    };
    ...
    
  7. beginsWith(t)
    String.prototype.beginsWith = function(t) {
        'use strict';
        t = t.toString();
        return (t.toString() === this.substring(0, t.length));
    };
    
  8. beginsWith(t, i)
    String.prototype.beginsWith = function(t, i) {
      if (i == false) {
        return (t == this.substring(0, t.length));
      } else {
        return (t.toLowerCase() == this.substring(0, t.length).toLowerCase());
    };
    
  9. beginsWithVowel()
    String.prototype.beginsWithVowel = function(){
      if (this == "") return false;
      return "aeiou".split("").indexOf(this[0].toLowerCase()) !== -1
    function translatePigLatin(str) {
       var nonv = str.split(/[aeiou]/)[0].length
       if (nonv == 0){
           return str + "way";
        }else {
    ...