@flex-development/fst-util-from-fs v1.0.0-alpha.1
fst-util-from-fs
fst utility to create trees from file systems
Contents
What is this?
This package is a utility to create file system trees.
This utility that uses file system adapters to recursively read a directory, and create a tree from its contents.
Install
This package is ESM only.
In Node.js (version 18+) with yarn:
yarn add @flex-development/fst-util-from-fsIn Deno with esm.sh:
import { fromFileSystem } from 'https://esm.sh/@flex-development/fst-util-from-fs'In browsers with esm.sh:
<script type="module">
import { fromFileSystem } from 'https://esm.sh/@flex-development/fst-util-from-fs'
</script>Use
TODO: use
API
This package exports the following identifiers:
There is no default export.
fromFileSystem([options])
Create a file system tree.
Parameters
options(Options, optional) — tree options
Returns
(Root) file system tree
Options
Options for creating a file system tree (TypeScript interface).
Properties
content(boolean, optional) — include file content (populates thevaluefield of eachfilenode)depth(number, optional) — maximum search depth (inclusive). a search depth less than0will produce an empty treeextensions(Extensions, optional) — list of file extensions to filter matched files byfilters(Filters, optional) — path filters to determine if nodes should be added to the treefs(Partial<FileSystem>, optional) — file system adapterhandles(Handles, optional) — node handlersroot(URL | string, optional) — module id of root directory- default:
pathe.cwd() + pathe.sep
- default:
sort(Sort, optional) — function used to sort child nodes
Dirent
Directory content entry (TypeScript interface).
This interface can be augmented to register custom methods and properties.
declare module '@flex-development/fst-util-from-fs' {
interface Dirent {
parentPath: string
}
}Properties
isDirectory((this: void) => boolean) — check if the dirent describes a directoryname(string) — directory content name. if the dirent refers to a file, the file extension should be included
Extensions
Union of options to filter matched files by file extension (TypeScript type).
type Extensions = Set<string> | readonly string[] | stringFileSystem
File system adapter (TypeScript interface).
Properties
readFileSync((this: void, path: string, encoding: 'utf8') => string, optional) — get the contents of the file atpathreaddirSync((this: void, path: string, options: { withFileTypes: true }) => readonly Dirent[]) — read the contents of the directory atpath
Filter
Determine if a node for x should be added to a file system tree.
Parameters
x(string) — path to directory or file
Returns
(boolean) true if node for x should be added, false otherwise
Filters
Path filters to determine if nodes should be added to the tree (TypeScript type).
Properties
directory(Filter, optional) — determine if adirectorynode should be added to the treefile(Filter, optional) — determine if afilenode should be added to the tree
Handle<[T]>
Handle node.
Type Parameters
Parameters
node(T) — directory or file nodedirent(Dirent) — dirent object representing directory or fileparent(Parent) — parent nodetree(Root) — file system treefs(FileSystem) — file system adapter
Returns
(null | undefined | void) nothing
Handles
Path filters to determine if nodes should be added to the tree (TypeScript type).
Properties
directory(Handle<Directory>, optional) — directory node handlerfile(Handle<File>, optional) — file node handler
Sort
Compare node a to b.
Parameters
Returns
(number) comparison result
Syntax tree
The syntax tree is fst.
Types
This package is fully typed with TypeScript.
Contribute
See CONTRIBUTING.md.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
11 months ago