Nodejs String Starts With startsWith( pattern )

Here you can find the source of startsWith( pattern )

Method Source Code

// string utilities borrowed from Prototype JavaScript Library ( http://prototypejs.org/ )

// method startsWith
// 'Prototype Library'.startsWith( 'Pro' ); => true
String.prototype.startsWith = String.prototype.startsWith || function ( pattern ) {
    // We use `lastIndexOf` instead of `indexOf` to avoid tying execution
    // time to string length when string doesn't start with pattern.
    return this.lastIndexOf(pattern, 0) === 0;
}

Related

  1. StartsWith( str )
    String.prototype.StartsWith = function( str )
        return this.indexOf( str ) == 0;
    };
    
  2. starts( other )
    String.prototype.starts = function( other ){
      return !!other && other.substr( 0, this.length) == this
    function str_starts( that, other ){
      return !!other && other.substr( 0, that.length) == that
    
  3. startsWith( str )
    String.prototype.startsWith = function( str ) {
        if ( str.length > this.length ) {
            return false;
        return( String( this ).substr( 0, str.length ) == str );
    };
    
  4. startsWith( value )
    String.prototype.startsWith = function( value )
      return ( this.substr( 0, value.length ) == value ) ;
    
  5. startsWith()
    const strPro=String.prototype;
    String.prototype.startsWith||Object.assign(strPro,{
      startsWith(searchString,position){
        if (position) {
          return this.indexOf(searchString) === position;
        return this.indexOf(searchString)===0;
      },
      endsWith(searchString,position){
    ...
    
  6. startsWith(e,t)
    String.prototype.startsWith||(String.prototype.startsWith=function(e,t){
         return t=t||0,this.substr(t,e.length)===e}
    );