Skip to main content

Understanding FileMap and DirMap

BeDoc uses FileMap and DirMap as structured representations of files and directories. These objects provide a consistent interface for handling paths, metadata, and relationships between files and directories.

DirMap (Directory Representation)

A DirMap represents a directory and contains essential metadata about it, including separator information for cross-platform compatibility.

A DirMap represents a directory and contains essential metadata about it.

Properties

PropertyTypeDescription
pathstringThe relative path to the directory
uristringThe URI representation of the directory
absolutePathstringThe absolute path to the directory
absoluteUristringThe absolute URI representation of the directory
namestringThe name of the directory
separatorstringThe directory separator (/ or \)
absoluteUristringThe absolute URI representation of the directory
isFilefalseAlways false since this is a directory
isDirectorytrueAlways true since this is a directory

FileMap (File Representation)

A FileMap represents a file, extending the information provided by a DirMap by including file-specific metadata, such as the absolute URI and separator.

A FileMap represents a file, extending the information provided by a DirMap by including file-specific metadata.

Properties

PropertyTypeDescription
pathstringThe relative path to the file
uristringThe URI representation of the file
absolutePathstringThe absolute path to the file
absoluteUristringThe absolute URI representation of the file
namestringThe name of the file (with extension)
modulestringThe file name without its extension
extensionstringThe file extension (e.g., .js, .txt)
isFiletrueAlways true since this is a file
isDirectoryfalseAlways false since this is a file
directoryDirMapThe directory containing this file
absoluteUristringThe absolute URI representation of the file
separatorstringThe directory separator (/ or \)

Relationship Between FileMap and DirMap

Every FileMap contains a DirMap, ensuring that every file is associated with a directory, allowing BeDoc to efficiently track which directory a file belongs to. This ensures structured file handling within BeDoc workflows.

For example:

const myFile = {
path: "examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js",
uri: "file:///d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js",
absolutePath: "d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js",
absoluteUri: "file:///d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer/bedoc-markdown-printer.js",
name: "bedoc-markdown-printer.js",
module: "bedoc-markdown-printer",
extension: ".js",
isFile: true,
isDirectory: false,
separator: "\",
directory: {
path: "examples/node_modules_test/bedoc-markdown-printer",
uri: "file:///d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer",
absolutePath: "d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer",
absoluteUri: "file:///d:/git/BeDoc/examples/node_modules_test/bedoc-markdown-printer",
name: "bedoc-markdown-printer",
separator: "\",
isFile: false,
isDirectory: true
}
};

This structure allows for easy traversal and management of files and directories in BeDoc.