@hrefcl/apidoc - v4.0.5
    Preparing search index...

    Class Reader

    Configuration and content reader for APIDoc projects

    The Reader class is responsible for:

    • Reading and parsing configuration files (apidoc.json, package.json)
    • Loading header and footer content from markdown files
    • Merging configuration from multiple sources with proper precedence
    • Providing validated project metadata for documentation generation
    const reader = new Reader(appContext);
    const projectInfo = reader.read();
    console.log('Project:', projectInfo.name, 'v' + projectInfo.version);
    1. apidoc.json (highest priority)
    2. package.json (apidoc field)
    3. Default values (lowest priority)

    4.0.0

    Index

    Constructors

    • Initialize the Reader instance

      Sets up the reader with application context including logger and options. The reader will use the provided configuration for file paths and processing options.

      Parameters

      • app: AppContext

        Application context containing logger, options, and other shared state

      Returns Reader

      const appContext: AppContext = {
      log: logger,
      options: { src: ['./src'], dest: './docs' },
      markdownParser: parser
      };
      const reader = new Reader(appContext);

    Properties

    app: AppContext
    log: any
    opt: any

    Methods

    • Reads and merges configuration from multiple sources

      This method searches for configuration files in the following order of precedence:

      1. apidoc.json - Dedicated APIDoc configuration file (highest priority)
      2. apidoc.config.js - JavaScript configuration file
      3. package.json - NPM package file with 'apidoc' field
      4. Default values - Built-in fallback configuration (lowest priority)

      The method also reads header and footer content files if specified in the configuration.

      Returns Config

      Merged configuration object containing:

      • Project metadata (name, version, description, etc.)
      • Header content and title (if specified)
      • Footer content and title (if specified)
      • API base URL and sample URL
      • Template and styling options

      When configuration files exist but contain invalid JSON

      // 1. apidoc.json (if exists)
      {
      "name": "My API",
      "version": "1.0.0",
      "header": { "filename": "header.md" }
      }

      // 2. package.json (if apidoc.json doesn't exist)
      {
      "name": "my-package",
      "version": "1.0.0",
      "apidoc": {
      "name": "My API Documentation"
      }
      }
      const config = reader.read();
      // Returns:
      {
      name: "My API",
      version: "1.0.0",
      description: "API documentation",
      header: {
      title: "Introduction",
      content: "<markdown content>"
      },
      footer: {
      title: "Contact",
      content: "<markdown content>"
      }
      }

      4.0.0

    • Search for API documentation configuration files in specified directories.

      Returns Config

      Merged configuration object

    • Get json.header / json.footer title and markdown content

      Retrieves and processes header and footer configurations by reading content from the specified files and rendering it with a Markdown parser if available.

      Parameters

      • config: Config

        Configuration object containing details about header and footer settings.

      Returns { header?: any; footer?: any }

      Object containing processed header and footer content, including their titles.

      If the header or footer file cannot be read.

    • Search for a configuration file in a specified directory.

      Parameters

      • filename: string

        Name of the configuration file to locate.

      • dir: string

        Directory to scan

      Returns Config

      Configuration data if the file is found, or an empty object if not found.

    • Look for a file in each of the input folders.

      If multiple files with the same name exist in different directories, the method returns the first valid file it finds.

      Parameters

      • filename: string

        Name of the file to search for

      Returns string

      Resolved path of the found file, or an empty string if not.