Draxt.js
Draxt.js

Draxt is an open-source utility module for selecting and manipulating filesystem objects in a Node.js environment. It uses glob patterns as its "selector engine" to select filesytem objects (files, directories, ...).

Draxt.js (version 0.4.6) is an open-source utility module for selecting and manipulating filesystem objects in a Node.js environment. It provides DOM-like and jQuery-like interfaces to simplify the process of navigating, reading, and modifying files and directories.

The main features of this library include:

  • jQuery-Like Glob Selector Engine: The main draxt constructor function works as a factory that accepts a standard glob pattern (e.g., '/app/**') to query the filesystem. It translates matching paths into a collection of node instances wrapped in a draxt collection.

  • DOM-Like Node Hierarchy: Every item matched by a query is analyzed and converted into a specific class instance depending on its type. These classes include File, Directory, and SymbolicLink, all of which inherit from a common Node base class.

  • Dual Sync and Async Capabilities: To accommodate different application architectures, every asynchronous method in Draxt has a corresponding synchronous counterpart (such as node.siblings() and node.siblingsSync()).

  • Method Chaining for Sync Operations: Synchronous methods that do not serve as getters (for example, node.chmodSync(), node.appendToSync(), or file.ensureSync()) are chainable, allowing you to perform complex pipeline modifications on a single line of code.

  • Array and Collection Traversal Utilities: The draxt collection provides standard array-like helper methods including filter(), forEach() (or its alias each()), map(), mapAsync(), some(), sort(), reverse(), and slice() to manage files in bulk. You can also instantly filter collections using specialized helper methods like directories(), files(), and symlinks().

  • Powerful Directory-Specific API: Directory instances come with specialized tools for directory manipulation, such as recursively locating descendants (find()), listing direct contents (children()), checking if a directory is vacant (isEmpty()), and automatically creating or emptying directories without deleting the root folder itself (ensure() and empty()).

  • Rich File and Link Operations: File instances provide promisified wrappers for standard operations like read(), write(), append(), and truncate(). Similarly, SymbolicLink instances feature helper methods like isBroken() to easily detect dead symlinks.

  • Minimal Dependencies & High Extensibility: The library is built with only two core dependencies: glob and fs-extra. Developers can easily extend or overwrite its core functionality using the prototype property (or its fn alias) or by calling the static draxt.extend() method.