metadata-helper

Provides functions to get metadata for various file types.
Description:
  • Provides functions to get metadata for various file types.
Source:

Members

(inner, constant) handlers :Object.<string, function()>

Description:
  • A map of MIME type prefixes to their corresponding metadata handler functions.
Source:
A map of MIME type prefixes to their corresponding metadata handler functions.
Type:
  • Object.<string, function()>

Methods

(async, inner) getMetadata(filepath, mimeTypeopt) → {Promise.<object>}

Description:
  • Fetches metadata for a given file. It first tries to determine the file type and then uses the appropriate handler. If no specific handler is found, it uses a fallback handler.
Source:
Parameters:
Name Type Attributes Description
filepath string The path to the file.
mimeType string <optional>
Optional MIME type to bypass file type detection.
Returns:
A promise that resolves to an object containing the file's metadata.
Type
Promise.<object>

(async, inner) handleBinary(filepath) → {Promise.<binaryData>}

Description:
  • A fallback handler that uses the system's 'file' command to get generic information.
Source:
Parameters:
Name Type Description
filepath string The path to the binary file.
Returns:
A promise that resolves to the file's platform info.
Type
Promise.<binaryData>

(async, inner) handleExcel(filepath) → {Promise.<excelData>}

Description:
  • Parses an Excel file to get the number of sheets and their names.
Source:
Parameters:
Name Type Description
filepath string The path to the Excel file.
Returns:
A promise that resolves to the Excel metadata.
Type
Promise.<excelData>

(async, inner) handleImage(filepath) → {Promise.<imageData>}

Description:
  • Uses the `image-size` library to extract image properties.
Source:
Parameters:
Name Type Description
filepath string The path to the image file.
Returns:
A promise that resolves to the image metadata.
Type
Promise.<imageData>

(async, inner) handleMedia(filepath) → {Promise.<mediaData>}

Description:
  • Uses `ffprobe` to extract metadata for video and audio files.
Source:
Parameters:
Name Type Description
filepath string The path to the media file.
Returns:
A promise that resolves to the media metadata.
Type
Promise.<mediaData>

(async, inner) handlePdf(filepath) → {Promise.<pdfData>}

Description:
  • Parses a PDF file to extract page count and document info.
Source:
Parameters:
Name Type Description
filepath string The path to the PDF file.
Returns:
A promise that resolves to the PDF metadata.
Type
Promise.<pdfData>

(async, inner) handlePowerPoint(filepath) → {Promise.<powerPointData>}

Description:
  • Parses a PowerPoint file to get the number of slides.
Source:
Parameters:
Name Type Description
filepath string The path to the PowerPoint file.
Returns:
A promise that resolves to the PowerPoint metadata.
Type
Promise.<powerPointData>

(async, inner) handleText(filepath) → {Promise.<textData>}

Description:
  • Reads a text file and extracts basic statistics.
Source:
Parameters:
Name Type Description
filepath string The path to the text file.
Returns:
A promise that resolves to the text file metadata.
Type
Promise.<textData>

(async, inner) handleWord(filepath) → {Promise.<wordData>}

Description:
  • Extracts raw text from a Word document to get word and character counts.
Source:
Parameters:
Name Type Description
filepath string The path to the Word file.
Returns:
A promise that resolves to the Word document metadata.
Type
Promise.<wordData>

Type Definitions

binaryData

Source:
Properties:
Name Type Description
platformInfo string A descriptive string about the file from the 'file' command.
Type:
  • object

excelData

Source:
Properties:
Name Type Description
sheets number The number of sheets in the Excel workbook.
sheetNames Array.<string> An array of the names of the worksheets.
Type:
  • object

imageData

Source:
Properties:
Name Type Description
width number The width of the image in pixels.
height number The height of the image in pixels.
orientation string The image orientation ('portrait' or 'landscape').
type string The file extension of the image (e.g., 'png', 'jpeg').
Type:
  • object

mediaData

Source:
Properties:
Name Type Attributes Description
duration number | null The duration of the media in seconds, or null if unavailable.
container string The format name of the media container.
video object <optional>
Video stream metadata.
Properties
Name Type Attributes Description
width number <optional>
The width of the video.
height number <optional>
The height of the video.
codec string <optional>
The video codec name.
audio object <optional>
Audio stream metadata.
Properties
Name Type Attributes Description
codec string <optional>
The audio codec name.
bit_rate number | null <optional>
The audio bitrate in bits per second, or null if unavailable.
Type:
  • object

pdfData

Source:
Properties:
Name Type Description
pages number The number of pages in the PDF.
info object The PDF document's info dictionary (e.g., title, author).
Type:
  • object

powerPointData

Source:
Properties:
Name Type Description
slidesCount number | null The number of slides in the presentation, or null if unable to parse.
Type:
  • object

textData

Source:
Properties:
Name Type Description
lines number The number of lines in the text file.
charCount number The number of characters in the text file.
firstLine string The first 100 characters of the first line of the file.
Type:
  • object

wordData

Source:
Properties:
Name Type Description
wordCount number The number of words in the document.
charCount number The number of characters in the document.
Type:
  • object