### Install Dree via npm Source: https://github.com/euberdeveloper/dree/blob/main/README.md Installs the dree module either locally for a project or globally for system-wide access. This is the initial step to using the dree package in your Node.js applications. ```bash npm install dree ``` ```bash npm install -g dree ``` -------------------------------- ### CLI: Get Help and Options (Bash) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Displays help information and all available options for the dree CLI commands 'scan' and 'parse'. Options can be specified as command arguments or via a JSON file. ```bash $ dree --help --all-options ``` -------------------------------- ### Get Directory Tree as String (JavaScript) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Parses a directory into a string representation of its tree structure. Can be used with default or custom options, including followLinks, depth, exclude, and extensions. The asynchronous version is also available for non-blocking operations. ```javascript const dree = require('dree'); const string = dree.parse('./folder'); ``` ```javascript const dree = require('dree'); const options = { followLinks: true, depth: 5, exclude: /dir_to_exclude/, extensions: [ 'txt', 'jpg' ], symbols: dree.ASCII_SYMBOLS }; const string = dree.parse('./folder', options); ``` ```javascript const dree = require('dree'); const tree = dree.scan('./folder'); const options = { followLinks: true, depth: 5, exclude: /dir_to_exclude/, extensions: [ 'txt', 'jpg' ] }; const string = dree.parseTree(tree, options); ``` ```javascript const dree = require('dree'); const options = { followLinks: true, depth: 5, exclude: /dir_to_exclude/, extensions: [ 'txt', 'jpg' ] }; dree.parseAsync('./folder', options) .then(function (string) { console.log(string); }); ``` -------------------------------- ### Bundle Library with esbuild Source: https://github.com/euberdeveloper/dree/blob/main/README.md Executes the npm script 'bundle' to package the library using esbuild. The bundled code will be available in the 'bundled' folder. ```bash $ npm run bundle ``` -------------------------------- ### Dree Scan Async Function Syntax Source: https://github.com/euberdeveloper/dree/blob/main/README.md Demonstrates the syntax for the `scanAsync` function, which asynchronously scans a directory and returns a promise for the directory tree object. It accepts a path, optional options, and optional callbacks for files and directories. ```javascript dree.scanAsync(path: string, options?: object, fileCallback?: Function, dirCallback?: Function): Promise ``` -------------------------------- ### Dree Configuration Options Source: https://github.com/euberdeveloper/dree/blob/main/README.md Defines the configurable options for the Dree library, such as controlling child node sorting, expanding home directory shortcuts, and skipping permission errors during directory scanning. ```javascript { postSorted: false, // Enables or disables sorting of child nodes. homeShortcut: false, // Enables or disables expansion of '~' to the user's home directory. skipErrors: true // Enables or disables skipping folders with permission errors. } ``` -------------------------------- ### Run Tests with Mocha Source: https://github.com/euberdeveloper/dree/blob/main/README.md Executes the npm script 'test' to run the project's tests using Mocha. Ensure that the code has been transpiled before running this command. ```bash $ npm test ``` -------------------------------- ### CLI: Parse Directory into String (Bash) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Uses the dree CLI to parse a source directory into a string representation of its tree. The output can be printed to stdout or saved to a file. The --show option can be used to display the output on stdout even when saving to a file. ```bash $ dree parse ``` ```bash $ dree parse --dest ./output/result.txt ``` ```bash $ dree parse --dest ./output/result.txt --show ``` -------------------------------- ### CLI: Scan Directory into Object (Bash) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Uses the dree CLI to scan a source directory and output the resulting object. The output can be printed directly to stdout or saved to a specified destination file. ```bash $ dree scan ``` ```bash $ dree scan --dest ./output/result.json ``` -------------------------------- ### Scan Directory with File and Directory Callbacks Source: https://github.com/euberdeveloper/dree/blob/main/README.md Scans a directory and executes custom callback functions for each file and directory encountered. This allows for dynamic processing of directory elements during the scan. ```javascript const dree = require('dree'); const options = { stat: false }; const fileCallback = function (element, stat) { console.log('Found file named ' + element.name + ' created on ' + stat.ctime); }; const dirCallback = function (element, stat) { console.log('Found file named ' + element.name + ' created on ' + stat.ctime); }; const tree = dree.scan('./folder', options, fileCallback, dirCallback); ``` -------------------------------- ### TypeScript Directory Scan with Custom Types Source: https://github.com/euberdeveloper/dree/blob/main/README.md Demonstrates scanning a directory using dree with TypeScript, including custom types for the returned tree nodes and specific callbacks for files and directories. This enables type-safe handling of directory structures. ```typescript import * as dree from 'dree'; interface CustomResult extends dree.Dree { description: string; } const options: dree.Options = { stat: false }; const fileCallback: dree.Callback = function (node, stat) { node.description = `${node.name} (${node.size})`; }; const dirCallback: dree.Callback = function (node, stat) { node.description = `${node.name} (${node.size})`; }; const tree: CustomResult = dree.scan('./folder', options, fileCallback, dirCallback); ``` -------------------------------- ### Scan Directory to Object (Simple) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Scans a specified directory and returns its structure as a JavaScript object. This is the most basic usage, without any custom options or callbacks. ```javascript const dree = require('dree'); const tree = dree.scan('./folder'); ``` -------------------------------- ### Transpile TypeScript to JavaScript Source: https://github.com/euberdeveloper/dree/blob/main/README.md Executes the npm script 'transpile' to convert TypeScript code into JavaScript. The transpiled output will be located in the 'dist' folder. ```bash $ npm run transpile ``` -------------------------------- ### CLI: Generate Shell Code Completion (Bash) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Generates shell code completion scripts for dree commands. This output can be appended to shell configuration files like .bashrc or .zshrc for command-line autocompletion. ```bash $ dree completion ``` ```bash $ dree completion >> ~/.bashrc ``` -------------------------------- ### Scan Directory with Custom Options Source: https://github.com/euberdeveloper/dree/blob/main/README.md Scans a directory using dree with a predefined set of options to control the scanning process. Options include file stat, normalization, link following, size, hash, depth, exclusion patterns, and extension filtering. ```javascript const dree = require('dree'); const options = { stat: false, normalize: true, followLinks: true, size: true, hash: true, depth: 5, exclude: /dir_to_exclude/, extensions: [ 'txt', 'jpg' ] }; const tree = dree.scan('./folder', options); ``` -------------------------------- ### Parse Directory Tree Asynchronously with dree Source: https://github.com/euberdeveloper/dree/blob/main/README.md Parses a directory tree object into a string representation asynchronously. It accepts the directory tree object and optional options for customization. The output is a promise that resolves to a string, with folders indicated by '>' and symbolic links by '>>'. Note potential issues with symbolic link detection on Windows. ```javascript dree.parseTreeAsync(dirTree, options) ``` -------------------------------- ### ASCII Symbols for Dree Source: https://github.com/euberdeveloper/dree/blob/main/README.md Provides an alternative set of ASCII-based symbols for dree's directory tree representation, offering a simpler visual style. ```typescript { dirChild: '-\ ', fileChild: '-- ', forkChild: '|', lastChild: '`', linkChild: '->', tabIndent: ' ', pipeIndent: '| ' } ``` -------------------------------- ### parseTreeAsync - Async Directory Tree Parser Source: https://github.com/euberdeveloper/dree/blob/main/README.md Asynchronously parses a directory tree object into a formatted string representation. This function takes a directory tree object previously generated by the scan function and converts it into a human-readable string format with folder and symbolic link indicators. ```APIDOC ## parseTreeAsync ### Description Asynchronously parses a directory tree object (returned by `scan` function) into a formatted string representation. Folders are preceded by `>` and symbolic links by `>>`. ### Syntax ``` dree.parseTreeAsync(dirTree, options) ``` ### Parameters #### Required Parameters - **dirTree** (object) - Required - The object representing a Directory Tree returned by the `scan` function that you want to parse into a string. #### Optional Parameters - **options** (object) - Optional - Customization object for function behavior. Supports all parameters from `parse` function plus the additional `skipErrors` parameter. ### Options Parameters - **skipErrors** (boolean) - Optional - Same parameter available in `scan` options. Controls error handling during parsing. - **hash** (boolean) - Optional - Include hash values in tree representation. - **size** (boolean) - Optional - Include file sizes in tree representation. - **exclude** (array) - Optional - Patterns to exclude from the tree. - **followLinks** (boolean) - Optional - Whether to follow symbolic links. Affects stat computation. - **symbolicLinks** (boolean) - Optional - Whether to detect symbolic links. ### Return Value **Type:** Promise Returns a promise that resolves to a string representing the Directory Tree structure of the object provided as the first parameter. ### Response Format ``` dree ├── file1.txt ├── file2.js ├─> directory1 │ └── nested-file.txt └─>> symbolic-link ``` - `├──` Regular files and folders - `├─>` Folders (preceded by `>`) - `└─>>` Symbolic links (preceded by `>>`) ### Important Notes #### Windows Compatibility On Windows, symbolic links may not be detected properly due to node fs module limitations. When `symbolicLinks` is true, `isSymbolicLink` may return false for all nodes. When `followLinks` is true, symbolic links may not be followed. #### Callback Parameters Callbacks receive tree representation and stat parameters: - Tree parameter reflects the options given to `scan` - If `hash` is false, tree won't include hash values - Stat parameter depends on `followLinks` option: - If true: result of `fs.stat` - If false: result of `fs.lstat` #### Computed Properties - **hash** and **size** are computed only for non-filtered nodes - Folder sizes may differ from actual sizes if inner files are excluded by filters - Hash of identical content nodes may differ because node names are considered #### Async Differences The asynchronous version may return a different object than the synchronous version because directories are read in different orders. ### Usage Example ```javascript const dree = require('dree'); // First scan the directory const dirTree = await dree.scanAsync('./my-directory', { hash: true, size: true, followLinks: true }); // Then parse it asynchronously const treeString = await dree.parseTreeAsync(dirTree, { skipErrors: true }); console.log(treeString); ``` ``` -------------------------------- ### Default Symbols for Dree Source: https://github.com/euberdeveloper/dree/blob/main/README.md Defines the default set of symbols used by the dree library to visually represent directory structures, including forks, last children, links, and indentation. ```typescript { dirChild: '─> ', fileChild: '── ', forkChild: '├', lastChild: '└', linkChild: '>>', tabIndent: ' ', pipeIndent: '│ ' } ``` -------------------------------- ### Dree Predefined Sorting Methods Source: https://github.com/euberdeveloper/dree/blob/main/README.md Enumerates the predefined methods for sorting directory entries. These methods are used to control the order of child nodes when `postSorted` is enabled. Available in JavaScript as an object and in TypeScript as an enum. ```javascript const SortMethodPredefined = { ALPHABETICAL: 'alphabetical', ALPHABETICAL_REVERSE: 'alphabeticalReverse', ALPHABETICAL_INSENSITIVE: 'alphabeticalInsensitive', ALPHABETICAL_INSENSITIVE_REVERSE: 'alphabeticalInsensitiveReverse' }; ``` ```typescript enum SortMethodPredefined { ALPHABETICAL, ALPHABETICAL_REVERSE, ALPHABETICAL_INSENSITIVE, ALPHABETICAL_INSENSITIVE_REVERSE } ``` -------------------------------- ### Asynchronous Directory Scan Source: https://github.com/euberdeveloper/dree/blob/main/README.md Performs an asynchronous scan of a directory using dree, returning a Promise that resolves with the directory tree object. This is suitable for non-blocking operations in Node.js applications. ```javascript const dree = require('dree'); const options = { stat: false, normalize: true, followLinks: true, size: true, hash: true, depth: 5, exclude: /dir_to_exclude/, extensions: [ 'txt', 'jpg' ] }; dree.scanAsync('./folder', options) .then(function (tree) { console.log(tree); }); ``` -------------------------------- ### Dree ParseTree Function (Synchronous) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Parses a pre-existing directory tree object (typically obtained from a `scan` function) into a string format. This function is synchronous and allows customization through an options object, similar to the `parse` function. ```typescript dree.parseTree(dirTree, options) ``` -------------------------------- ### Dree Parse Function (Synchronous) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Parses a given file or directory path to generate a string representation of its directory tree. This function operates synchronously and accepts an options object to customize the output. It's useful for immediate tree generation. ```typescript dree.parse(path, options) ``` -------------------------------- ### Dree Result Object Structure Source: https://github.com/euberdeveloper/dree/blob/main/README.md Details the structure of the objects returned by Dree's scanning functions, representing nodes within a directory tree. Includes properties like name, path, type, size, and children. ```javascript { name: 'string', path: 'string', relativePath: 'string', type: 'file' | 'directory', isSymbolicLink: 'boolean', sizeInBytes?: 'number', size?: 'string', hash?: 'string', extension?: 'string', isEmpty?: 'boolean', descendants?: 'number', stat?: 'object', children?: 'Array' } ``` -------------------------------- ### Dree Parse Function (Asynchronous) Source: https://github.com/euberdeveloper/dree/blob/main/README.md Asynchronously parses a file or directory path to create a string representation of its directory tree. It returns a promise that resolves to the tree string. This is suitable for non-blocking operations in applications. ```typescript dree.parseAsync(path, options) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.