1.2.0 • Published 6 years ago

qm-dir-tree v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

qm-dir-tree

Normalized dir tree.

:warning: Disclaimer:

This module is published in good faith and for learning purpose only. The code is not production-ready, so any usage of it is strictly at your own risk :see_no_evil:.

Installation

npm i -S qm-dir-tree

Usage

const { dirTree } = require("qm-dir-tree");

(async () => {
  const id = "11";
  const tree = dirTree({ path: "some/path" }); // => { walk, entries, tree }

  const nodes = dirTree.getChildrensOfNode({ id, filter });
  // filter: "all" //default
  // filter: "files" / "dirs"
  // => [{tree node item}, ...]

  const entries = dirTree.getChildrensEntries({ id, filter, entryMapper });
  // when specified
  // returns childrens entries of the tree e.g.:
  // entryMapper: (entry => entry.name)
  // => [name, ...]
})();

Results

tree:

{
  "root": "/mnt/h/.../test/fixtures",
  "childrens": [
    {
      "item": "0",
      "childrens": [
        {
          "item": "1",
          "childrens": [
            {
              "item": "2"
            },
            {
              "item": "3"
            },
...

entries:

{
    "0": {
    "id": 0,
    "name": "threads",
    "path": "/mnt/h/.../test/fixtures/threads",
    "stats": {
      "dev": 21,
      ...
      "isFile": false,
      "isDirectory": true,
    },
    "cwd": "/mnt/h/.../test/fixtures",
    "crown": "/threads",
    "parent": "fixtures",
    "isFile": false
  },
}

For more info read the source code, examples and test files :page_facing_up:.

License

MIT © qaraluch