UNPKG

isbn-bisac-tools

Version:

A toolkit for working with BISAC subject headings and ISBN lookups

176 lines (175 loc) 6.68 kB
/** * Utility functions for the BISAC scraper */ import { Page } from 'puppeteer'; import { Category } from '../src/types/index.js'; /** * Initialize the necessary directories * @param outputDir - The directory to store output files * @param screenshotsDir - The directory to store screenshots * @param takeScreenshots - Whether to initialize the screenshots directory */ export declare function initialize(outputDir: string, screenshotsDir: string, takeScreenshots?: boolean): Promise<void>; /** * Take a screenshot * @param page - Puppeteer page object * @param name - Base name for the screenshot * @param screenshotsDir - Directory to save screenshots */ export declare function takeScreenshot(page: Page, name: string, screenshotsDir: string): Promise<void>; /** * Save data to JSON file * @param filePath - Path to save the JSON file * @param data - Data to save */ export declare function saveToJSON<T>(filePath: string, data: T): Promise<void>; /** * Generate a random delay between min and max with visual countdown * @param min - Minimum delay in ms * @param max - Maximum delay in ms * @returns A Promise that resolves after the delay */ export declare function randomDelay(min: number, max: number): Promise<number>; /** * Get the path to the latest JSON file in the output directory * @param outputDir - The directory containing BISAC JSON files (default: ./output) * @returns The full path to the latest JSON file, or undefined if none found */ /** * Runs the BISAC scraper to generate a new JSON file * @returns A promise that resolves when the scraper completes */ export declare function runBisacScraper(): Promise<boolean>; /** * Check if a JSON file with today's date already exists * @param outputDir - The directory containing BISAC JSON files (default: ./output) * @returns The full path to today's JSON file if it exists, or undefined if not found */ export declare function checkExistingJsonFileForToday(outputDir?: string): Promise<string | undefined>; export declare function getLatestJsonFilePath(outputDir?: string): Promise<string | undefined>; /** * Load BISAC data from JSON file * @param filePath - Path to the JSON file (if undefined, uses latest file) * @returns Array of Category objects */ export declare function loadBisacData(filePath?: string): Promise<Category[]>; /** * Get full label for a subject code * @param code - BISAC subject code (e.g., ANT007000) * @param dataFilePath - Path to the BISAC data JSON file (if undefined, uses latest file) * @returns The full label or undefined if not found */ export declare function getFullLabelFromCode(code: string, dataFilePath?: string): Promise<string | undefined>; /** * Get all codes and full labels for a category heading * @param heading - BISAC category heading (e.g., "ANTIQUES & COLLECTIBLES") * @param dataFilePath - Path to the BISAC data JSON file (if undefined, uses latest file) * @returns Array of code and full label pairs */ export declare function getCodesForHeading(heading: string, dataFilePath?: string): Promise<Array<{ code: string; fullLabel: string; }>>; /** * Get code from a full label * @param fullLabel - Full BISAC label (e.g., "ANTIQUES & COLLECTIBLES / Buttons & Pins") * @param dataFilePath - Path to the BISAC data JSON file (if undefined, uses latest file) * @returns The code or undefined if not found */ export declare function getCodeFromFullLabel(fullLabel: string, dataFilePath?: string): Promise<string | undefined>; export declare function getCodeFromISBN(isbn: string, dataFilePath?: string): Promise<{ title: string; categories: Array<{ code: string; fullLabel: string; }>; bestCategory?: { code: string; fullLabel: string; }; }>; /** * Print formatted JSON to console * Uses jq if available, falls back to JSON.stringify * @param data - The data to print * @param title - Optional title to print before the data */ export declare function printFormattedJSON<T>(data: T, title?: string): Promise<void>; /** * Interface for a comparison result between two BISAC JSON files */ interface BisacComparisonResult { oldFilePath: string; newFilePath: string; oldDate: string; newDate: string; summary: { totalCategoriesOld: number; totalCategoriesNew: number; totalSubjectsOld: number; totalSubjectsNew: number; newCategories: number; removedCategories: number; modifiedCategories: number; newSubjects: number; removedSubjects: number; modifiedSubjects: number; }; newCategories: { heading: string; subjectCount: number; }[]; removedCategories: { heading: string; subjectCount: number; }[]; modifiedCategories: { heading: string; newSubjects: { code: string; label: string; }[]; removedSubjects: { code: string; label: string; }[]; modifiedSubjects: { code: string; oldLabel: string; newLabel: string; }[]; }[]; } /** * Compare two BISAC JSON files and identify differences * @param olderFilePath - Path to the older BISAC JSON file * @param newerFilePath - Path to the newer BISAC JSON file * @returns Comparison results showing differences between the files */ export declare function compareBisacJsonFiles(olderFilePath: string, newerFilePath: string): Promise<BisacComparisonResult>; /** * Print a comparison report between two BISAC JSON files * @param comparison - Comparison result object */ export declare function printComparisonReport(comparison: BisacComparisonResult): Promise<void>; /** * Select two BISAC JSON files for comparison using an interactive prompt * @param outputDir - The directory containing BISAC JSON files (default: ./output) * @returns Object containing paths to the selected files, or undefined if canceled */ /** * Creates a backup of the bisac-data.json file with a timestamp-based filename * @param outputDir Directory where the bisac-data.json file is located * @returns Path to the created backup file, or undefined if backup failed */ export declare function createBackupOfBisacData(outputDir?: string): Promise<string | undefined>; export declare function selectFilesForComparison(outputDir?: string): Promise<{ olderFile: string; newerFile: string; } | undefined>; /** * Browse a JSON file using the fx tool * Allows interactive selection of JSON files from the output directory */ export declare function browseJsonFile(outputDir?: string): Promise<boolean>; export {};