ramhejazi / Draxt
Licence: mit
draxt.js – NodeList/jQuery-like package for File System (node.js)
Stars: ✭ 192
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
FSMon
File system monitoring utility written in plain PHP
Stars: ✭ 12 (-93.75%)
Mutual labels: utility, filesystem
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
Anymatch
‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions
Stars: ✭ 289 (+50.52%)
Mutual labels: fs, glob
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
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
andfs-extra
modules. -
draxt
usesglob
patterns to select filesystem objects. - Each item in a
draxt
collection is an instance of aFile
,Directory
, orSymbolicLink
class, which is a subclass ofNode
. - Every asynchronous method has a synchronous version. E.g.,
node.siblingsSync()
fornode.siblings()
. -
draxt
is a simple constructor function. You can extend/overwrite its methods via itsprototype
property (or itsfn
alias) or by using thedraxt.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
draxt
APIs- Interfaces
Test
$ npm test
License
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].