{"name":"directory-tree","version":"3.2.2","description":"Convert a directory tree to a JS object.","repository":{"type":"git","url":"git+https://github.com/mihneadb/node-directory-tree.git"},"keywords":["directory","tree"],"main":"lib/directory-tree.js","author":{"name":"Mihnea Dobrescu-Balaur"},"license":"MIT","bugs":{"url":"https://github.com/mihneadb/node-directory-tree/issues"},"homepage":"https://github.com/mihneadb/node-directory-tree","dependencies":{"command-line-args":"^5.2.0","command-line-usage":"^6.1.1"},"devDependencies":{"chai":"^2.3.0","mocha":"^8.3.2"},"bin":{"directory-tree":"bin/index.js"},"engines":{"node":">=10.0"},"scripts":{"test":"mocha"},"gitHead":"c82e4e636bdd1760adb62cfb40d8beacba5b0bb0","_id":"directory-tree@3.2.2","_nodeVersion":"12.18.3","_npmVersion":"7.9.0","dist":{"integrity":"sha512-4AuGTfhWD0xOTRGmOfOL5xBWgV/IXbpsNb1/R721u+ZwJo01QdaFOXLy/RJj2N7LmcvVvs8tzGgYdh+liudiAg==","shasum":"fe0cc6ddfcf8d6a873f30e3544d938a0e07ffb27","tarball":"http://registry-npm.ywwl.com/directory-tree/download/directory-tree-3.2.2.tgz","fileCount":11,"unpackedSize":17574,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiEyY/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqjcw//bhByGvFDkxdBdk4XzzwpkwHc5OSMhcV4UfqeQQedFU1HsOva\r\nwW2Lxjx0zgqDUPWD4MKoseEpf1+WjmVAXsiHv551YuADgQtcE99spKCSPBCB\r\nNApYwJRCKemltn6BtCt2rwsokjnWldrv2wLwH7wneOAg6nRfmfFB9XwzDh+/\r\nFpirxwW5HOhuUFVed18C+bfTCwuS+wj9Qxf9Iig6J411A60LBcNv42zIEuW2\r\nkyInAb/aSv0iO8eQ1aOQ7MyS5V1SoTlzduAdUlH+wjhyG28l+H787y6S+HVe\r\nO1dWrVEhLDG5DNEPiH8CgE9hNb+jkqR1qUGGON6jWRL15v/Gwxm1NpdM3cNX\r\nedcyk20viDlG1bLwnQ39tDw5oxkHNDerTCkGlVyDG17kcmCyrUwmFCOj+A/2\r\nYdNtNPMLaRzTFjclAqbS1mMMAzRAGv3OdY2uONNDJuS9LQRA+IdMG2e1SBz9\r\niKynD0Z857eI435HO7PC7THfCNG1lgTDZsvriTtyspghOKfxihAYNBykpTqo\r\neO2pK70PT2xELB6M024sebsTVojMBF6XVeHmkEB2sIfrBpZ+MC8KL7Y1EdDO\r\nvQCGI138ex+8pklDSpp2pCzBoxIhUTXz7Xe+qZNLX9SLPIbzjqzGanNHKMSN\r\n1toneLwPw1p3RwJwaK+xWY9yvOGhOUq9gbk=\r\n=recW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGDyCMW5hRFzaXfs0R/qSvRMUrlFrWX+9Z6duZucZAn1AiBG0gcWFTdwYE9S2xEtBudgdTX72o8XwoPFzeRaur09Dw=="}],"size":5907,"noattachment":false,"key":"/directory-tree/-/directory-tree-3.2.2.tgz"},"_npmUser":{"name":"mihneadb","email":"mihnea@linux.com"},"directories":{},"maintainers":[{"name":"mihneadb","email":"mihnea@linux.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/directory-tree_3.2.2_1645422143282_0.8838938841846091"},"_hasShrinkwrap":false,"readme":"# directory-tree\n\nCreates a JavaScript object representing a directory tree.\n\n## Install\n\n```bash\n$ npm install directory-tree\n```\n\n## Usage\n\n```js\nconst dirTree = require(\"directory-tree\");\nconst tree = dirTree(\"/some/path\");\n```\n\nAnd you can also filter by an extensions regex:\nThis is useful for including only certain types of files.\n\n```js\nconst dirTree = require(\"directory-tree\");\nconst filteredTree = dirTree(\"/some/path\", { extensions: /\\.txt/ });\n```\n\nExample for filtering multiple extensions with Regex.\n\n```js\nconst dirTree = require(\"directory-tree\");\nconst filteredTree = dirTree(\"/some/path\", {\n  extensions: /\\.(md|js|html|java|py|rb)$/\n});\n```\n\nYou can also exclude paths from the tree using a regex:\n\n```js\nconst dirTree = require(\"directory-tree\");\nconst filteredTree = dirTree(\"/some/path\", { exclude: /some_path_to_exclude/ });\n```\n\nYou can also specify which additional attributes you would like to be included about each file/directory:\n\n```js\nconst dirTree = require('directory-tree');\nconst filteredTree = dirTree('/some/path', {attributes:['mode', 'mtime']});\n```\n\nThe default attributes are `[name, path]` for Files and `[name, path, children]` for Directories\n\nA callback function can be executed with each file that matches the extensions provided:\n\n```js\nconst PATH = require('path');\nconst dirTree = require('directory-tree');\n\nconst tree = dirTree('./test/test_data', {extensions:/\\.txt$/}, (item, PATH, stats) => {\n  console.log(item);\n});\n```\n\nThe callback function takes the directory item (has path, name, size, and extension) and an instance of [node path](https://nodejs.org/api/path.html) and an instance of [node FS.stats](https://nodejs.org/api/fs.html#fs_class_fs_stats).\n\nYou can also pass a callback function for directories:\n```js\nconst PATH = require('path');\nconst dirTree = require('directory-tree');\n\nconst tree = dirTree('./test/test_data', {extensions:/\\.txt$/}, null, (item, PATH, stats) => {\n  console.log(item);\n});\n```\n\n## Options\n\n`exclude` : `RegExp|RegExp[]` - A RegExp or an array of RegExp to test for exclusion of directories.\n\n`extensions` : `RegExp` - A RegExp to test for exclusion of files with the matching extension.\n\n`attributes` : `string[]` - Array of [FS.stats](https://nodejs.org/api/fs.html#fs_class_fs_stats) attributes.\n\n`normalizePath` : `Boolean` - If true, windows style paths will be normalized to unix style pathes (/ instead of \\\\).\n\n`depth` : `number` - If presented, reads so many nested dirs as specified in argument. Usage of size attribute with depth option is prohibited.\n\n## Result\n\nGiven a directory structured like this:\n\n```\nphotos\n├── summer\n│   └── june\n│       └── windsurf.jpg\n└── winter\n    └── january\n        ├── ski.png\n        └── snowboard.jpg\n```\n\n`directory-tree` with `attributes: [\"size\", \"type\", \"extension\"]`  will return this JS object:\n\n```json\n{\n  \"path\": \"photos\",\n  \"name\": \"photos\",\n  \"size\": 600,\n  \"type\": \"directory\",\n  \"children\": [\n    {\n      \"path\": \"photos/summer\",\n      \"name\": \"summer\",\n      \"size\": 400,\n      \"type\": \"directory\",\n      \"children\": [\n        {\n          \"path\": \"photos/summer/june\",\n          \"name\": \"june\",\n          \"size\": 400,\n          \"type\": \"directory\",\n          \"children\": [\n            {\n              \"path\": \"photos/summer/june/windsurf.jpg\",\n              \"name\": \"windsurf.jpg\",\n              \"size\": 400,\n              \"type\": \"file\",\n              \"extension\": \".jpg\"\n            }\n          ]\n        }\n      ]\n    },\n    {\n      \"path\": \"photos/winter\",\n      \"name\": \"winter\",\n      \"size\": 200,\n      \"type\": \"directory\",\n      \"children\": [\n        {\n          \"path\": \"photos/winter/january\",\n          \"name\": \"january\",\n          \"size\": 200,\n          \"type\": \"directory\",\n          \"children\": [\n            {\n              \"path\": \"photos/winter/january/ski.png\",\n              \"name\": \"ski.png\",\n              \"size\": 100,\n              \"type\": \"file\",\n              \"extension\": \".png\"\n            },\n            {\n              \"path\": \"photos/winter/january/snowboard.jpg\",\n              \"name\": \"snowboard.jpg\",\n              \"size\": 100,\n              \"type\": \"file\",\n              \"extension\": \".jpg\"\n            }\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\n## Adding custom fields\nYou can easily extend a `DirectoryTree` object with custom fields by adding them to the custom field.\nFor example add an `id` based on the path of a `DirectoryTree` object for each directory and file like so:\n```\nimport { createHash } from 'crypto';\nimport * as directoryTree from 'directory-tree';\nimport { DirectoryTree, DirectoryTreeOptions, DirectoryTreeCallback } from 'directory-tree';\n\nconst callback: DirectoryTreeCallback = (\n            item: DirectoryTree,\n            path: string\n        ) => {\n            item.custom = {id: createHash('sha1').update(path).digest('base64')};\n        };\n\nconst dirTree: DirectoryTree & { id?: string } = directoryTree(\n    \"<your-directory-path>\",\n    {},\n    callback,\n    callback\n);\n\n// to explore the object with the new custom fields\nconsole.log(JSON.stringify(dirTree, null, 2));\n\n```\n\n## Note\n\nDevice, FIFO and socket files are ignored.\n\nFiles to which the user does not have permissions are included in the directory\ntree, however, directories to which the user does not have permissions, along\nwith all of its contained files, are completely ignored.\n\n## Dev\n\nTo run tests go the package root in your CLI and run,\n\n```bash\n$ npm test\n```\n\nMake sure you have the dev dependencies installed (e.g. `npm install .`)\n\n## Node version\n\nThis project requires at least Node v4.2.\nCheck out version `0.1.1` if you need support for older versions of Node.\n\n## CLI usage\n\nYou can use script directly from command line for generating json data.\n\n```bash\n$ npx directory-tree --help\n```\n```bash\n$ npx directory-tree --path /Users/user/target --attributes type,extension --pretty -o ./xz.json --depth 1 \n```\n\n### Available options\n-p, --path string      🗂 The input folder to process. Required.                                     \n-e, --exclude string   🐒 Exclude some folders from processing by regexp string. Ex -e \"test_data/some_dir$|js|.DS_Store\"                                            \n-o, --output string    📝 Put result into file provided by this options. Overwrites if exists.       \n-d, --depth number     ☞ Reads dirs in deep as specified. Usage of size attribute with depth option is prohibited.                                                                \n--attributes string    ℹ️ Grab file attributes. Example: --attributes size,type,extension. Usage of size attribute with depth option is prohibited                                \n--pretty               💎 Json pretty print\n","publish_time":1645422143437,"_cnpm_publish_time":1645422143437,"dist-tags":{"latest":"3.6.0"}}