{"_id":"@allmarkedup/dirscribe","_rev":"5-21409f64725795c60a2be22f204cd871","name":"@allmarkedup/dirscribe","description":"Describe a recursive directory structure as a nested JSON object","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"@allmarkedup/dirscribe","version":"0.1.0","description":"Describe a recursive directory structure as a nested JSON object","main":"index.js","scripts":{"test":"mocha --reporter spec","lint":"jscs index.js","lint:fix":"jscs index.js --fix"},"author":{"name":"Mark Perkins","email":"mark@allmarkedup.com","url":"http://allmarkedup.com"},"license":"MIT","dependencies":{"bluebird":"^3.1.5"},"devDependencies":{"chai":"^3.4.1","chai-as-promised":"^5.2.0","jscs":"^2.9.0","mocha":"^2.4.2"},"gitHead":"641dedc98db68436df8bcbd84f96b1e177e489e2","_id":"@allmarkedup/dirscribe@0.1.0","_shasum":"bc0befff1310865da75a27f30b8605ab56fb7a03","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"allmarkedup","email":"mark@allmarkedup.com"},"dist":{"shasum":"bc0befff1310865da75a27f30b8605ab56fb7a03","tarball":"https://registry.npmjs.org/@allmarkedup/dirscribe/-/dirscribe-0.1.0.tgz","integrity":"sha512-B/gt8nt2V+oCDOFjtUTonCx6QXf2vTTIIKjmo0o1PpTeMdbUyYJQ6CNxyiLtFO/KYQfq+JyyV94EQj1QUpeWew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDYrHmasmVjG44Omb2QcjCaFmKyzXr3tXn3QuzYyE/1bAiEAwK9vYxHqtB99dW6d5wEfxvggwK6bslOKAd35TIJyFI8="}]},"maintainers":[{"name":"allmarkedup","email":"mark@allmarkedup.com"}]},"0.1.1":{"name":"@allmarkedup/dirscribe","version":"0.1.1","description":"Describe a recursive directory structure as a nested JSON object","tags":["directory","JSON","recursive","describe"],"main":"index.js","scripts":{"test":"mocha --reporter spec","lint":"jscs index.js","lint:fix":"jscs index.js --fix"},"author":{"name":"Mark Perkins","email":"mark@allmarkedup.com","url":"http://allmarkedup.com"},"license":"MIT","dependencies":{"bluebird":"^3.1.5"},"engines":{"node":">= 4.0.0"},"devDependencies":{"chai":"^3.4.1","chai-as-promised":"^5.2.0","jscs":"^2.9.0","mocha":"^2.4.2"},"gitHead":"28adef34ab0e9f857c84a2c13ec62aa017ba8709","_id":"@allmarkedup/dirscribe@0.1.1","_shasum":"b071417a1544d0d74585faa835ff1eaac2c9ee25","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"allmarkedup","email":"mark@allmarkedup.com"},"dist":{"shasum":"b071417a1544d0d74585faa835ff1eaac2c9ee25","tarball":"https://registry.npmjs.org/@allmarkedup/dirscribe/-/dirscribe-0.1.1.tgz","integrity":"sha512-V+ane9VEZOm7gj8VOcJ1UCXbdh78ZMX6P8c3hlMu68ldJSFWOIUq9SfdulIUkk5P+vCc1b9WJ0R9Ri3fMK3xCg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0arb/VvcdShFPB2HRtr/1TgDrDXmXvqcLctRbzfOZSQIgdrZhLs5Ls7m5Xf7KC+Zf1g2j/LdfID7lEEr5u3X2mJU="}]},"maintainers":[{"name":"allmarkedup","email":"mark@allmarkedup.com"}]},"1.0.0":{"name":"@allmarkedup/dirscribe","version":"1.0.0","description":"Describe a recursive directory structure as a nested JSON object","tags":["directory","JSON","recursive","describe"],"main":"index.js","scripts":{"test":"mocha --reporter spec","lint":"jscs index.js","lint:fix":"jscs index.js --fix"},"author":{"name":"Mark Perkins","email":"mark@allmarkedup.com","url":"http://allmarkedup.com"},"license":"MIT","dependencies":{"bluebird":"^3.1.5"},"engines":{"node":">= 4.0.0"},"devDependencies":{"chai":"^3.4.1","chai-as-promised":"^5.2.0","jscs":"^2.9.0","mocha":"^2.4.2"},"gitHead":"7288547657a74077f8825adddcac588d1360b282","_id":"@allmarkedup/dirscribe@1.0.0","_shasum":"a4038303740ec9a1a5f70df60af0931c21c25b02","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"allmarkedup","email":"mark@allmarkedup.com"},"dist":{"shasum":"a4038303740ec9a1a5f70df60af0931c21c25b02","tarball":"https://registry.npmjs.org/@allmarkedup/dirscribe/-/dirscribe-1.0.0.tgz","integrity":"sha512-GbyPY9r3QNZo4VvvGgoLchBTCwx6V4OI1bC8x4jQBJzMn9MnECYcx6iI747t+y+fHOnggJwzbr/N+iK3LBO3PA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDLgb4vYKUK427FQ0SmxHgaCCZ92aiRriVfE5yPQxhB1QIgca+AthHyQoew8A4aHR8QPXsKM3ApMJBuxn7CrOJq7Qw="}]},"maintainers":[{"name":"allmarkedup","email":"mark@allmarkedup.com"}],"_npmOperationalInternal":{"host":"packages-5-east.internal.npmjs.com","tmp":"tmp/dirscribe-1.0.0.tgz_1454404665192_0.036341064143925905"}}},"readme":"# Dirscribe\n\nDescribe a recursive directory structure as a nested JSON object.\n\nSupports filtering, post-processing and the ability to supply a custom callback to determine the structure of the JSON objects.\n\n## Installation\n\n```shell\n$ npm install @allmarkedup/dirscribe --save\n```\n\n## Usage\n\nThe `dirscribe` module exports a single function with the following signature:\n\n```js\ndirscribe(<path-to-directory> [,opts]);\n```\nAnd returns a promise. Internally, dirscribe uses [Bluebird](http://bluebirdjs.com/) for promise creation.\n\n### Basic example\n\n```js\nconst dirscribe = require('@allmarkedup/dirscribe');\n\nconst fileTree = dirscribe('test/fixtures/root-directory'); // returns a Promise\n\nfileTree.then(tree => console.dir(tree));\n\n// Outputs:\n// { root: '',\n//   dir: 'test/fixtures',\n//   base: 'root-directory',\n//   ext: '',\n//   name: 'root-directory',\n//   path: 'test/fixtures/root-directory',\n//   stat:\n//    { dev: 16777220,\n//      mode: 16877,\n//      nlink: 5,\n//      uid: 501,\n//      gid: 20,\n//      ... },\n//   children:\n//    [ { root: '',\n//        dir: 'test/fixtures/root-directory',\n//        base: 'file-1.md',\n//        ext: '.md',\n//        name: 'file-1',\n//        path: 'test/fixtures/root-directory/file-1.md',\n//        stat: [Object]\n//      },\n//      { root: '',\n//        dir: 'test/fixtures/root-directory',\n//        base: 'sub-directory-1',\n//        ext: '',\n//        name: 'sub-directory-1',\n//        path: 'test/fixtures/root-directory/sub-directory-1',\n//        stat: [Object],\n//        children: [Object]},\n//      { root: '',\n//        dir: 'test/fixtures/root-directory',\n//        base: 'sub-directory-2',\n//        ext: '',\n//        name: 'sub-directory-2',\n//        path: 'test/fixtures/root-directory/sub-directory-2',\n//        stat: [Object],\n//        children: [Object] } ] }\n```\n\n### Example with options\n\n```js\nconst dirscribe = require('@allmarkedup/dirscribe');\n\nconst fileTree = dirscribe('test/fixtures/root-directory', {\n    build: (filePath, stat) => ({\n        path:     filePath,\n        modified: new Date(stat.mtime).getTime(),\n        type:     stat.isDirectory() ? 'dir' : 'file'\n    }),\n    after: items => items.sort((a, b) =>  b.modified - a.modified )\n});\n\nfileTree.then(tree => console.dir(tree));\n\n// Outputs:\n// { path: 'test/fixtures/root-directory',\n//   modified: 1453901431000,\n//   type: 'dir',\n//   children:\n//    [ { path: 'test/fixtures/root-directory/sub-directory-2',\n//        modified: 1453901475000,\n//        type: 'dir',\n//        children: [Object] },\n//      { path: 'test/fixtures/root-directory/sub-directory-1',\n//        modified: 1453901444000,\n//        type: 'dir',\n//        children: [Object] },\n//      { path: 'test/fixtures/root-directory/file-1.md',\n//        modified: 1453899612000,\n//        type: 'file' } ] }\n```\n\n## Options\n\n### opts.filter\n\nA callback filter function that is called with the filePath as it's only argument. This is called before the build function.\n\n```js\nconst opts = {\n    filter: filePath => ! (/(^|\\/)\\.[^\\/\\.]/g).test(filePath), // ignore hidden files\n};\n```\n\n### opts.build\n\nA function that gets called for each item and must return a JSON representation of that item. Function is called with the file path and the [stat object](https://nodejs.org/api/fs.html#fs_class_fs_stats) for that file.\n\nThis can be used to customise the properties you want on each of the JSON objects representing a file/directory.\n\nNote that for directories, children are appended to the returned object after the build function has been called.\n\n```js\nconst opts = {\n    build: (filePath, stat) => ({\n        path:     filePath,\n        modified: new Date(stat.mtime).getTime(),\n        type:     stat.isDirectory() ? 'dir' : 'file'\n    })\n};\n```\n\nThe default build function looks as follows:\n\n```js\nfunction build(filePath, stat) {\n    const p = Path.parse(filePath);\n    p.path = filePath;\n    p.stat = stat;\n    return p;\n}\n```\n\n### opts.after\n\nA callback function to be run after each directories items have been converted into JSON objects. Receives an array of JSON objects representing the contents of that directory. The function should return the final list of objects.\n\nThis is a good place to do any sorting or post-filtering of items.\n\n```js\nconst opts = {\n    after: items => items.slice(0, 3), // limit results to three per directory\n};\n```\n\n### opts.recursive\n\nWhether to recurse down through directories or not. Defaults to `true`.\n\n```js\nconst opts = {\n    recursive: false, // only runs through the top level directory\n};\n```\n\n### opts.childrenKey\n\nThe key to use for the array of children that gets appended to objects representing directories.\n\n```js\nconst opts = {\n    childrenKey: 'kids',\n};\n\n// {\n//     path: 'path/to/directory'\n//     kids: [\n//         {\n//             path: 'path/to/directory/foo.txt'\n//             ...\n//         }\n//     ]\n// }\n```\n\n## Tests\n\nUse `npm test` to run tests.\n","maintainers":[{"name":"allmarkedup","email":"mark@allmarkedup.com"}],"time":{"modified":"2022-06-12T14:33:55.843Z","created":"2016-01-27T14:44:31.613Z","0.1.0":"2016-01-27T14:44:31.613Z","0.1.1":"2016-01-28T10:30:57.262Z","1.0.0":"2016-02-02T09:17:46.318Z"},"author":{"name":"Mark Perkins","email":"mark@allmarkedup.com","url":"http://allmarkedup.com"},"license":"MIT","readmeFilename":"README.md"}