{"id":13563184,"url":"https://github.com/ramhejazi/draxt","last_synced_at":"2025-04-03T19:32:30.509Z","repository":{"id":32729092,"uuid":"139286919","full_name":"ramhejazi/draxt","owner":"ramhejazi","description":"draxt.js – NodeList/jQuery-like package for File System (node.js) ","archived":false,"fork":false,"pushed_at":"2023-12-11T13:36:12.000Z","size":544,"stargazers_count":190,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-03-14T20:21:21.373Z","etag":null,"topics":["filesystem","fs","fs-extra","glob","node","nodejs","utility"],"latest_commit_sha":null,"homepage":"https://ramhejazi.github.io/draxt/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ramhejazi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-30T23:20:38.000Z","updated_at":"2024-02-01T17:56:38.000Z","dependencies_parsed_at":"2024-01-14T09:59:55.638Z","dependency_job_id":"0ee36a76-3ab0-40c2-a39e-7763fb1d32c7","html_url":"https://github.com/ramhejazi/draxt","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":"0.11267605633802813","last_synced_commit":"6962352988e128cb3545f9ccfc136841c90d3ffa"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramhejazi%2Fdraxt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramhejazi%2Fdraxt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramhejazi%2Fdraxt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramhejazi%2Fdraxt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramhejazi","download_url":"https://codeload.github.com/ramhejazi/draxt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247065417,"owners_count":20877773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","fs","fs-extra","glob","node","nodejs","utility"],"created_at":"2024-08-01T13:01:16.077Z","updated_at":"2025-04-03T19:32:30.215Z","avatar_url":"https://github.com/ramhejazi.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"text-align:center\"\u003e\n\u003ca link=\"https://github.com/ramhejazi/draxt\"\u003e\u003cimg width=\"300px\" style=\"padding: 20px\" alt=\"draxt.js logo\" src=\"draxt-logo.svg\"\u003e\u003c/a\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/ramhejazi/draxt/blob/master/LICENSE\"\u003e\u003cimg alt=\"draxt license\" src=\"https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/draxt\"\u003e\u003cimg alt=\"npm-link\" src=\"https://img.shields.io/npm/v/draxt.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/ramhejazi/draxt\"\u003e\u003cimg alt=\"draxt coverage status\" src=\"https://img.shields.io/coveralls/github/ramhejazi/draxt.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\n`draxt` is a utility module for selecting and manipulating filesystem objects in a Node.js environment.\nIt 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.\n\n**Example directory structure:**\n\n```\n/app/\n ├── controllers/\n │   └── index.js\n ├── public/\n │   ├── script.js\n │   └── style.css\n └── views/\n     └── index.html\n```\n\n```js\nconst $ = require('draxt');\n\n(async () =\u003e {\n    // Select `/app` directory content and create a new `draxt` collection.\n    const $app = await $('/app/**');\n    $app\n        // Let's filter js files:\n        .filter((node) =\u003e node.extension === 'js')\n        // Now we have a new `draxt` collection with 2 nodes.\n        .forEach(async (node, index, allNodes) =\u003e {\n            // `node` is instance of `File` class. Because it's a file!\n            console.log(node.pathName);\n            // → '/app/controllers/index.js' for the first node!\n\n            console.log(node instanceof $.File); // → `true`\n\n            // Let's get contents of the node. `file.read` returns a promise object.\n            const content = await node.read('utf8');\n\n            // Let's use some synchronous methods!\n            node.appendSync('\\na new line!')\n                .chmodSync('765')\n                // move the file into another directory!\n                .appendToSync('/tmp'); // or `.moveToSync('/tmp')`\n\n            console.log(node.pathName);\n            // → '/hell/index.js' for the first node in the list!\n\n            // get the parent directory of the node.\n            // returns a `Directory` instance with the pathName of '/tmp'!\n            const parentNode = node.parentSync(); // or `await node.parent()`\n\n            // is the directory empty?\n            console.log(parentNode.isEmptySync()); // → `false`\n        });\n})();\n```\n\n**Key notes**:\n\n-   `draxt` has only 2 dependencies: [`glob`] and [`fs-extra`] modules.\n-   `draxt` uses `glob` patterns to select filesystem objects.\n-   Each item in a `draxt` collection is an instance of a [`File`], [`Directory`], or [`SymbolicLink`] class, which is a subclass of [`Node`].\n-   Every asynchronous method has a synchronous version. E.g., [`node.siblingsSync()`] for [`node.siblings()`].\n-   `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.\n\n```js\nconst draxt = require('draxt');\n// Add a method (`images`) for filtering image files.\ndraxt.fn.images = function() {\n    const imgExtensions = ['jpeg', 'jpg', 'png', 'git', ...];\n    return this.filter(node =\u003e {\n       return node.isFile() \u0026\u0026 imgExtensions.indexOf(node.extension) \u003e -1;\n    });\n}\n```\n\n## Install\n\nInstalling via [npm]:\n\n```bash\n$ npm i draxt\n```\n\nVia [yarn]:\n\n```bash\n$ yarn add draxt\n```\n\n## Docs\n\n-   [`draxt` APIs][draxt-doc]\n-   Interfaces\n    -   [`Node`]\n    -   [`File`]\n    -   [`Directory`]\n    -   [`SymbolicLink`]\n\n## Test\n\nIn the past, mock-fs was used for mocking test file system, but since the package is not compatible with\nnewer versions of node.js, now regular linux cmds like `mkdir` and `echo` are used for creating test files and\nfolders. The test fs structure are created in `/tmp` directory. That being said, for now, tests only work on Linux!\n\n```bash\n$ npm run test\n```\n\n## License\n\n[Licensed under MIT.][license]\n\n[repo]: https://github.com/ramhejazi/draxt\n[logo]: draxt-logo.jpg\n[license]: https://github.com/ramhejazi/draxt/blob/master/LICENSE\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n[coverall]: https://coveralls.io/github/ramhejazi/draxt\n[coverall-badge]: https://img.shields.io/coveralls/github/ramhejazi/draxt.svg?style=flat-square\n[npm-link]: https://www.npmjs.com/package/draxt\n[npm-badge]: https://img.shields.io/npm/v/draxt.svg?style=flat-square\n[travis-link]: https://travis-ci.org/ramhejazi/draxt\n[travis-badge]: https://img.shields.io/travis/ramhejazi/draxt.svg?style=flat-square\n[deps-status-link]: https://david-dm.org/ramhejazi/draxt\n[deps-status-badge]: https://david-dm.org/ramhejazi/draxt.svg?style=flat-square\n[npm]: https://docs.npmjs.com/getting-started/what-is-npm\n[yarn]: https://yarnpkg.com/en/\n[glob]: https://en.wikipedia.org/wiki/Glob_(programming)\n[`fs`]: https://nodejs.org/api/fs.html\n[`fs-extra`]: https://github.com/jprichardson/node-fs-extra\n[`glob`]: https://github.com/isaacs/node-glob\n[Pahlavi language]: https://en.wikipedia.org/wiki/Middle_Persian\n[draxt-doc]: https://ramhejazi.github.io/draxt#draxt\n[`Node`]: https://ramhejazi.github.io/draxt#interfaces-node\n[`File`]: https://ramhejazi.github.io/draxt#interfaces-file\n[`Directory`]: https://ramhejazi.github.io/draxt#interfaces-directory\n[`SymbolicLink`]: https://ramhejazi.github.io/draxt#interfaces-symboliclink\n[`draxt.extend`]: https://ramhejazi.github.io/draxt#draxt-extend\n[`node.siblingsSync()`]: https://ramhejazi.github.io/draxt#node-siblings\n[`node.siblings()`]: https://ramhejazi.github.io/draxt#node-siblings\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framhejazi%2Fdraxt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framhejazi%2Fdraxt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framhejazi%2Fdraxt/lists"}