{"id":14483739,"url":"https://github.com/traviswimer/dir-to-json","last_synced_at":"2025-04-09T22:31:52.157Z","repository":{"id":21383044,"uuid":"24700653","full_name":"traviswimer/dir-to-json","owner":"traviswimer","description":"Asynchronously convert directory tree structure into a javascript object.","archived":false,"fork":false,"pushed_at":"2022-07-04T13:08:12.000Z","size":168,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T13:11:23.374Z","etag":null,"topics":["directory","javascript","json","nodejs","npm","npm-package"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/traviswimer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-02T00:27:43.000Z","updated_at":"2023-09-08T12:51:29.000Z","dependencies_parsed_at":"2022-07-08T01:05:50.262Z","dependency_job_id":null,"html_url":"https://github.com/traviswimer/dir-to-json","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fdir-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fdir-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fdir-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fdir-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traviswimer","download_url":"https://codeload.github.com/traviswimer/dir-to-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123726,"owners_count":21051520,"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":["directory","javascript","json","nodejs","npm","npm-package"],"created_at":"2024-09-03T00:02:04.521Z","updated_at":"2025-04-09T22:31:51.564Z","avatar_url":"https://github.com/traviswimer.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# dir-to-json ![Tests](https://github.com/traviswimer/dir-to-json/actions/workflows/node.js.yml/badge.svg)\n\n\u003e Asynchronously convert directory tree structure into a JavaScript object.\n\n## Getting Started\n\n### Install\n\n**Yarn:**\n\n```shell\nyarn add dir-to-json\n```\n\n**NPM:**\n\n```shell\nnpm install dir-to-json --save\n```\n\n### Usage\n\n```javascript\nimport dirToJson from \"dir-to-json\";\n\ndirToJson(\"./path/to/my/dir\", { sortType: true })\n\t.then(function (dirTree) {\n\t\tconsole.log(dirTree);\n\t})\n\t.catch(function (err) {\n\t\tthrow err;\n\t});\n```\n\n#### Callback syntax\n\nThe callback syntax has been split into another module in version `1.0.0`. If you would still like to use it, just change your import to `dir-to-json/callback`:\n\n```javascript\nimport dirToJson from \"dir-to-json/callback\";\n\ndirToJson(\"./path/to/my/dir\", function (err, dirTree) {\n\tif (err) {\n\t\tthrow err;\n\t} else {\n\t\tconsole.log(dirTree);\n\t}\n});\n```\n\n### Requirements\n\n- NodeJS version 14 or higher\n\n\u003e Since Version 1.0.0 of `dir-to-json`, the lowest supported version of NodeJS is `14`. If you are using an older version of Node, try installing `dir-to-json@0.0.3`\n\n## API\n\n`dirToJson( path [, options ] [, callback ] )`\n\n### path\n\n- type: string\n- description: Path to the directory you would like to obtain a tree object from.\n\n### options _(optional)_\n\n- type: object\n- description: Allows output to be customized.\n- Accepted properties:\n  - **sortType** _boolean_ (Default: `true`) - If `true`, directories will be listed before files in all `children` arrays. If `false`, array contents will be listed in the order which they are returned from `fs.readdir()`.\n\n### callback( err, directoryTree ) _(optional)_\n\n- type: function\n- description: Callback function\n  - err - Error object on fail. `null` on success.\n  - directoryTree - Object containing heirarchical directory data.\n\n## Structure of output\n\n```javascript\n{\n\t\"parent\": \"..\",\n\t\"path\": \"\",\n\t\"name\": \"coverage\",\n\t\"type\": \"directory\",\n\t\"children\": [{\n\t\t\"parent\": \"\",\n\t\t\"path\": \"coverage-final.json\",\n\t\t\"name\": \"coverage-final.json\",\n\t\t\"type\": \"file\"\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"index.html\",\n\t\t\"name\": \"index.html\",\n\t\t\"type\": \"file\"\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"lcov-report\",\n\t\t\"name\": \"lcov-report\",\n\t\t\"type\": \"directory\",\n\t\t\"children\": [{\n\t\t\t\"parent\": \"lcov-report\",\n\t\t\t\"path\": \"lcov-report/index.html\",\n\t\t\t\"name\": \"index.html\",\n\t\t\t\"type\": \"file\"\n\t\t}, {\n\t\t\t\"parent\": \"lcov-report\",\n\t\t\t\"path\": \"lcov-report/prettify.css\",\n\t\t\t\"name\": \"prettify.css\",\n\t\t\t\"type\": \"file\"\n\t\t}, {\n\t\t\t\"parent\": \"lcov-report\",\n\t\t\t\"path\": \"lcov-report/prettify.js\",\n\t\t\t\"name\": \"prettify.js\",\n\t\t\t\"type\": \"file\"\n\t\t}, {\n\t\t\t\"parent\": \"lcov-report\",\n\t\t\t\"path\": \"lcov-report/src\",\n\t\t\t\"name\": \"src\",\n\t\t\t\"type\": \"directory\",\n\t\t\t\"children\": [{\n\t\t\t\t\"parent\": \"lcov-report/src\",\n\t\t\t\t\"path\": \"lcov-report/src/createDirectoryObject.js.html\",\n\t\t\t\t\"name\": \"createDirectoryObject.js.html\",\n\t\t\t\t\"type\": \"file\"\n\t\t\t}, {\n\t\t\t\t\"parent\": \"lcov-report/src\",\n\t\t\t\t\"path\": \"lcov-report/src/index.html\",\n\t\t\t\t\"name\": \"index.html\",\n\t\t\t\t\"type\": \"file\"\n\t\t\t}, {\n\t\t\t\t\"parent\": \"lcov-report/src\",\n\t\t\t\t\"path\": \"lcov-report/src/main.js.html\",\n\t\t\t\t\"name\": \"main.js.html\",\n\t\t\t\t\"type\": \"file\"\n\t\t\t}]\n\t\t}]\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"lcov.info\",\n\t\t\"name\": \"lcov.info\",\n\t\t\"type\": \"file\"\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"prettify.css\",\n\t\t\"name\": \"prettify.css\",\n\t\t\"type\": \"file\"\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"prettify.js\",\n\t\t\"name\": \"prettify.js\",\n\t\t\"type\": \"file\"\n\t}, {\n\t\t\"parent\": \"\",\n\t\t\"path\": \"src\",\n\t\t\"name\": \"src\",\n\t\t\"type\": \"directory\",\n\t\t\"children\": [{\n\t\t\t\"parent\": \"src\",\n\t\t\t\"path\": \"src/createDirectoryObject.js.html\",\n\t\t\t\"name\": \"createDirectoryObject.js.html\",\n\t\t\t\"type\": \"file\"\n\t\t}, {\n\t\t\t\"parent\": \"src\",\n\t\t\t\"path\": \"src/index.html\",\n\t\t\t\"name\": \"index.html\",\n\t\t\t\"type\": \"file\"\n\t\t}, {\n\t\t\t\"parent\": \"src\",\n\t\t\t\"path\": \"src/main.js.html\",\n\t\t\t\"name\": \"main.js.html\",\n\t\t\t\"type\": \"file\"\n\t\t}]\n\t}]\n}\n```\n\n## Project Links\n\n- [NPM](https://www.npmjs.com/package/dir-to-json)\n- [GitHub](https://github.com/traviswimer/dir-to-json)\n\n## Author\n\n#### Travis Wimer\n\n- \u003ca href=\"https://traviswimer.com/developer-portfolio\" title=\"React Native, React, NodeJS, UI/UX Developer\" target=\"_blank\"\u003eDeveloper Portfolio\u003c/a\u003e\n- \u003ca href=\"https://traviswimer.com/blog\" title=\"React Native, React, NodeJS, UI/UX Blog\" target=\"_blank\"\u003eMy Blog\u003c/a\u003e\n- \u003ca href=\"https://traviswimer.com/developer-portfolio/dir-to-json\" title=\"dir-to-json | Travis Wimer\" target=\"_blank\"\u003eDir-To-Json Portfolio Page\u003c/a\u003e\n\n## License\n\nMIT. Copyright © 2022 Travis Wimer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraviswimer%2Fdir-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraviswimer%2Fdir-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraviswimer%2Fdir-to-json/lists"}