src/core.js
// this is same as indexOf, but can stop searching earlier
this is same as indexOf, but can stop searching earlier
this is same as indexOf but can stop searching earlier
function indexWithin(needle, from, within = 99, throws = true) {
  for (let i = from, L = from + within, j = 0; i < L; ++i) {
    if (this.charCodeAt(i) === needle.charCodeAt(j)) {
      while (j < needle.length) {
        if (this.charCodeAt(i + j) === needle.charCodeAt(j)) {
          ++j;
        } else {
          j = 0;
          break;
        }
      }
      if (j === needle.length) {
        return i;
      }
    }
  }
  if (throws) {
    throw new Error(
      `ParseError: Failed to find \`${needle}\` within ${within} characters from position ${from}` +
        (LOOKING_FOR ? ` while looking for ${LOOKING_FOR}` : "") +
        "\n\nINPUT STRING:" +
        `\n${"*".repeat(20)}\n` +
        this +
        `\n${"*".repeat(20)}\n`
    );
  } else {
    return -1;
  }
}
function indexWithin ( needle , from , within = 99 , throws = true ) { for ( let i = from , L = from + within , j = 0 ; i < L ; ++ i ) { if ( this . charCodeAt ( i ) === needle . charCodeAt ( j ) ) { while ( j < needle . length ) { if ( this . charCodeAt ( i + j ) === needle . charCodeAt ( j ) ) { ++ j ; } else { j = 0 ; break ; } } if ( j === needle . length ) { return i ; } } } if ( throws ) { throw new Error ( ` \` ${ needle } \` ${ within } ${ from } ` + ( LOOKING_FOR ? ` ${ LOOKING_FOR } ` : "" ) + "\n\nINPUT STRING:" + ` \n ${ "*" . repeat ( 20 ) } \n ` + this + ` \n ${ "*" . repeat ( 20 ) } \n ` ) ; } else { return - 1 ; } }
this is same as indexOf, but can stop searching earlier
this is same as indexOf but can stop searching earlier