src/message.js
function findToken(message, token, offset=0, maxSearchLength) {
  let searchLength = message.length;
  if (maxSearchLength) {
    searchLength = Math.min(offset + maxSearchLength, message.length);
  }

  for (let i = offset; i < searchLength; i++) {
    // If the first value of the message matches
    // the first value of the token, check if
    // this is the full token.
    if (message[i] === token[0]) {
      if (containsToken(message, token, i)) {
        return i;
      }
    }
  }

  return -1;
}
function findToken(message, token, offset=0, maxSearchLength) {
  let searchLength = message.length;
  if (maxSearchLength) {
    searchLength = Math.min(offset + maxSearchLength, message.length);
  }

  for (let i = offset; i < searchLength; i++) {
    // If the first value of the message matches
    // the first value of the token, check if
    // this is the full token.
    if (message[i] === token[0]) {
      if (containsToken(message, token, i)) {
        return i;
      }
    }
  }

  return -1;
}
function findToken ( message , token , offset = 0 , maxSearchLength ) { let searchLength = message . length ; if ( maxSearchLength ) { searchLength = Math . min ( offset + maxSearchLength , message . length ) ; } for ( let i = offset ; i < searchLength ; i ++ ) { // If the first value of the message matches // the first value of the token, check if // this is the full token. if ( message [ i ] === token [ 0 ] ) { if ( containsToken ( message , token , i ) ) { return i ; } } } return - 1 ; }
Finds a given token in a message at a given offset.
@param {Uint8Array} message message content
@param {Uint8Array} token substring that should be found
@param {String} offset message body offset from where search should start
@returns {Boolean} whether message has a part at given offset or not
Finds a given token in a message at a given offset .