docs: function readToMatch(stream, regexp, options) {
    const endOK = Boolean(options && (options.endOK || options.endOk));
    const maxMatchLen = Number(options && options.maxMatchLen);
    // Convert to RegExp where necessary, like String.prototype.match
    // Make sure RegExp has global flag so lastIndex will be set
    if (!(regexp instanceof RegExp)) {
      try {
        regexp = new RegExp(regexp, 'g');
      } catch (errRegExp) {
        // Note:  Synchronous Yaku emits unhandledRejection before returning.
        // Best current option is to use an async promise, even when flowing
        const ReadPromise = (options && options.Promise) || Promise;
        return ReadPromise.reject(errRegExp);
      }
    } else if (!regexp.global) {
      regexp = new RegExp(regexp.source, `${regexp.flags || ''}g`);
    }
    function until(result, chunk, ended) {
      if (ended) {
        return endOK ? (result ? result.length : 0) : -1;
      }
  
      if (typeof result !== 'string') {
        throw new TypeError('readToMatch requires a string stream'
            + ' (use constructor options.encoding or .setEncoding method)');
      }
  
      regexp.lastIndex = maxMatchLen
        ? Math.max((result.length - chunk.length - maxMatchLen) + 1, 0)
        : 0;
      if (regexp.test(result)) {
        return regexp.lastIndex;
      }
  
      return -1;
    }
    return readInternal(stream, undefined, until, options);
  }