All Projects → ramhejazi → Draxt

ramhejazi / Draxt

Licence: mit
draxt.js – NodeList/jQuery-like package for File System (node.js)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Draxt

Fast Glob
🚀 It's a very fast and efficient glob library for Node.js
Stars: ✭ 1,150 (+498.96%)
Mutual labels:  fs, filesystem, glob
Fdir
⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
Stars: ✭ 777 (+304.69%)
Mutual labels:  fs, filesystem, glob
Tiny Glob
Super tiny and ~350% faster alternative to node-glob
Stars: ✭ 710 (+269.79%)
Mutual labels:  filesystem, glob
Node Ntfs
Windows NT File System (NTFS) file system driver
Stars: ✭ 18 (-90.62%)
Mutual labels:  fs, filesystem
Memfs
In-memory filesystem with Node's API
Stars: ✭ 854 (+344.79%)
Mutual labels:  fs, filesystem
Filer
Node-like file system for browsers
Stars: ✭ 389 (+102.6%)
Mutual labels:  fs, filesystem
Electron Filesystem
FileSystem for windows
Stars: ✭ 409 (+113.02%)
Mutual labels:  fs, filesystem
FSMon
File system monitoring utility written in plain PHP
Stars: ✭ 12 (-93.75%)
Mutual labels:  utility, filesystem
Glob
Glob for C++17
Stars: ✭ 74 (-61.46%)
Mutual labels:  filesystem, glob
Flint
Fast and configurable filesystem (file and directory names) linter
Stars: ✭ 115 (-40.1%)
Mutual labels:  fs, filesystem
Litfs
A FUSE file system in Go extended with persistent file storage
Stars: ✭ 116 (-39.58%)
Mutual labels:  fs, filesystem
Chonky
😸 A File Browser component for React.
Stars: ✭ 313 (+63.02%)
Mutual labels:  fs, filesystem
Anymatch
‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions
Stars: ✭ 289 (+50.52%)
Mutual labels:  fs, glob
Rm Protection
A safe alternative for "rm".
Stars: ✭ 416 (+116.67%)
Mutual labels:  utility, filesystem
Tfs
Mirror of https://gitlab.redox-os.org/redox-os/tfs
Stars: ✭ 2,890 (+1405.21%)
Mutual labels:  fs, filesystem
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+1516.15%)
Mutual labels:  utility, filesystem
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-89.06%)
Mutual labels:  filesystem, glob
mongoose-gridfs
mongoose gridfs on top of new gridfs api
Stars: ✭ 79 (-58.85%)
Mutual labels:  filesystem, fs
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (+517.19%)
Mutual labels:  fs, filesystem
Xcv
✂️ Cut, Copy and Paste files with Bash
Stars: ✭ 144 (-25%)
Mutual labels:  filesystem, glob
draxt.js logo
draxt license npm-link draxt build state draxt coverage status dependencies status

draxt is a utility module for selecting and manipulating filesystem objects in a Node.js environment. It uses glob patterns as its "selector engine". draxt also provides several DOM-like interfaces representing filesystem objects which build on promisified APIs for the fs and fs-extra modules.

draxt means tree in the Pahlavi language.

/app/
 ├── controllers/
 │   └── index.js
 ├── public/
 │   ├── script.js
 │   └── style.css
 └── views/
     └── index.njk
// Let's use a familiar variable name!
const $ = require('draxt');

(async () => {
  // Select `/app` directory contents and create a new `draxt` collection.
  const $app = await $('/app/**');
  $app
    // Let's filter js files:
    .filter(node => node.extension === 'js')
    // Now we have a new `draxt` collection with 2 nodes.
    .forEach(async (node, index, allNodes) => {
      // `node` is instance of `File` class. Because it's a file!
      console.log(node.pathName);
      // → '/app/controllers/index.js' for the first node!

      console.log(node instanceof $.File); // → `true`

      // Let's get contents of the node. `file.read` returns a promise object.
      const content = await node.read('utf8');

      // Let's use some synchronous methods!
      node.appendSync('\na new line!')
          .chmodSync('765')
          // move the file into another directory!
          .appendToSync('/hell') // or `.moveToSync('/hell')`

      console.log(node.pathName);
      // → '/hell/index.js' for the first node in the list!

      // get the parent directory of the node.
      // returns a `Directory` instance with the pathName of '/hell'!
      const parentNode = node.parentSync(); // or `await node.parent()`

      // is the directory empty?
      console.log(parentNode.isEmptySync()); // → `false`
  });
})();

Key notes:

  • draxt has only 2 dependencies: glob and fs-extra modules.
  • draxt uses glob patterns to select filesystem objects.
  • Each item in a draxt collection is an instance of a File, Directory, or SymbolicLink class, which is a subclass of Node.
  • Every asynchronous method has a synchronous version. E.g., node.siblingsSync() for node.siblings().
  • draxt is a simple constructor function. You can extend/overwrite its methods via its prototype property (or its fn alias) or by using the draxt.extend method.
const draxt = require('draxt');
// Add a method (`images`) for filtering image files.
draxt.fn.images = function() {
    const imgExtensions = ['jpeg', 'jpg', 'png', 'git', ...];
    return this.filter(node => {
       return node.isFile() && imgExtensions.indexOf(node.extension) > -1;
    });
}

Install

Installing via npm:

$ npm i draxt

Via yarn:

$ yarn add draxt

Docs

Test

$ npm test

License

Licensed under MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].