fs-tree-structure is a lightweight JavaScript/TypeScript utility designed to transform a flat list of file paths into a nested JavaScript object representing a directory tree structure. As of its current stable version, 0.0.5, it provides a single, focused function `makeTreeStructure` to perform this transformation. Due to its specific utility and low version number, its release cadence is likely stable but infrequent, implying minimal updates once its core functionality is mature. Key differentiators include its simplicity and direct focus on in-memory tree generation from string-based path arrays, rather than actual file system interaction. It includes TypeScript type definitions, ensuring type safety for TypeScript projects. The output is a plain JavaScript object, making it easily consumable by other parts of an application for purposes like documentation generation, build process analysis, or mock file system creation, providing a programmatic representation of a hierarchical file structure from flat input.
npm install fs-tree-structureVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `makeTreeStructure` with various file path inputs, including paths with different separators, and verifies the resulting nested object structure with `assert.deepStrictEqual`.
Ensure all elements in the input array `filePaths` are valid strings representing file paths.
After generating the tree, iterate through it or use a separate mapping to add custom metadata to file nodes.
Pre-process file paths using Node.js `path` module utilities (e.g., `path.normalize()`, `path.posix.normalize()`) to ensure consistent path separators and simplified paths before passing them to `makeTreeStructure`.
Filter or validate your input `filePaths` array to ensure all elements are valid string paths: `filePaths.filter(p => typeof p === 'string')`.
Review the input `filePaths` for conflicting entries (e.g., `a/b` and `a/b/c`). Ensure no path segment is both a file and a directory at the same level of the hierarchy. The library’s simple object merging will typically resolve 'file wins' or 'last write wins' for direct conflicts.
No dependency data recorded yet.