code: function createCursorWithCount(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
      let includeComments = false;
      let count = 0;
      let countExists = false;
      let filter = null;
  
      if (typeof opts === "number") {
          count = opts | 0;
          countExists = true;
      } else if (typeof opts === "function") {
          filter = opts;
      } else if (opts) {
          includeComments = !!opts.includeComments;
          count = opts.count | 0;
          countExists = typeof opts.count === "number";
          filter = opts.filter || null;
      }
      assert(count >= 0, "options.count should be zero or a positive integer.");
      assert(!filter || typeof filter === "function", "options.filter should be a function.");
  
      return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, 0, countExists ? count : -1);
  }
docs: Creates the cursor iterates tokens with options.
  
  @param {CursorFactory} factory - The cursor factory to initialize cursor.
  @param {Token[]} tokens - The array of tokens.
  @param {Comment[]} comments - The array of comments.
  @param {Object} indexMap - The map from locations to indices in `tokens`.
  @param {number} startLoc - The start location of the iteration range.
  @param {number} endLoc - The end location of the iteration range.
  @param {number|Function|Object} [opts=0] - The option object. If this is a number then it's `opts.count`. If this is a function then it's `opts.filter`.
  @param {boolean} [opts.includeComments] - The flag to iterate comments as well.
  @param {Function|null} [opts.filter=null] - The predicate function to choose tokens.
  @param {number} [opts.count=0] - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
  @returns {Cursor} The created cursor.
  @private