or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

PDF Page Validator

Build a utility that validates PDF page numbers before attempting conversion operations. The tool should help prevent errors by checking page numbers against PDF constraints.

Requirements

Page Validation

The utility should validate page numbers for PDF conversion operations and provide clear error handling.

  • Given a page number of 0, the validator throws an error with message "Invalid page number: must be at least 1" @test
  • Given a page number of -5, the validator throws an error with message "Invalid page number: must be at least 1" @test
  • Given a page number of 1, the validator accepts it and returns the page number @test
  • Given a page number of 10, the validator accepts it and returns the page number @test

PDF Conversion Integration

The utility should integrate with a PDF conversion library to convert valid page numbers.

  • Given a valid PDF file path "./sample.pdf" and page number 1, convert that page to an image buffer @test
  • Given an invalid page number 0, attempting conversion throws an error before calling the converter @test

Implementation

@generates

API

/**
 * Validates a page number for PDF conversion.
 *
 * @param {number} pageNumber - The page number to validate (must be >= 1)
 * @returns {number} The validated page number
 * @throws {Error} If page number is less than 1
 */
function validatePageNumber(pageNumber) {
  // IMPLEMENTATION HERE
}

/**
 * Converts a specific page from a PDF to an image buffer.
 *
 * @param {string} pdfPath - Path to the PDF file
 * @param {number} pageNumber - The page number to convert (1-indexed)
 * @param {object} options - Conversion options (optional)
 * @returns {Promise<Buffer>} Image buffer of the converted page
 * @throws {Error} If page number is invalid
 */
async function convertPage(pdfPath, pageNumber, options = {}) {
  // IMPLEMENTATION HERE
}

module.exports = {
  validatePageNumber,
  convertPage,
};

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion capabilities.

@satisfied-by