{"_id":"node-readfiles","_rev":"399102","name":"node-readfiles","description":"A lightweight Node.js module to recursively read files in a directory using ES6 Promises","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"time":{"modified":"2021-08-04T04:24:36.000Z","created":"2016-05-18T04:35:15.075Z","0.2.0":"2016-05-19T17:35:55.844Z","0.1.0":"2016-05-19T03:56:07.218Z","0.0.9":"2016-05-18T16:09:38.834Z","0.0.8":"2016-05-18T15:35:38.739Z","0.0.7":"2016-05-18T13:09:28.735Z","0.0.6":"2016-05-18T05:10:52.441Z","0.0.5":"2016-05-18T04:50:57.332Z","0.0.4":"2016-05-18T04:47:46.121Z","0.0.3":"2016-05-18T04:44:27.041Z","0.0.2":"2016-05-18T04:35:15.075Z"},"users":{"davidbwaters":true},"author":{"name":"Alejandro Gonzalez Sole"},"repository":{"type":"git","url":"git+https://github.com/guatedude2/node-readfiles.git"},"versions":{"0.2.0":{"name":"node-readfiles","version":"0.2.0","description":"A lightweight Node.js module to recursively read files in a directory using ES6 Promises","main":"index.js","scripts":{"start":"echo 'Not a runnable module' && exit 1","test":"mocha","lint":"eslint lib test","preversion":"npm run lint && npm test"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/guatedude2/node-readfiles.git"},"devDependencies":{"chai":"^3.5.0","eslint":"^2.10.2","mocha":"^2.4.5","mock-fs":"^3.9.0","sinon":"^1.17.4"},"dependencies":{"es6-promise":"^3.2.1"},"gitHead":"424a9fa1cbb49ee04ace128dea66f71ba924111b","bugs":{"url":"https://github.com/guatedude2/node-readfiles/issues"},"homepage":"https://github.com/guatedude2/node-readfiles#readme","_id":"node-readfiles@0.2.0","_shasum":"dbbd4af12134e2e635c245ef93ffcf6f60673a5d","_from":".","_npmVersion":"3.5.2","_nodeVersion":"4.2.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"dbbd4af12134e2e635c245ef93ffcf6f60673a5d","size":6493,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.2.0.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-readfiles-0.2.0.tgz_1463679353414_0.17859529424458742"},"directories":{},"publish_time":1463679355844,"_cnpm_publish_time":1463679355844,"_hasShrinkwrap":false},"0.1.0":{"name":"node-readfiles","version":"0.1.0","description":"A lightweight Node.js module to recursively read files in a directory using ES6 Promises","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/guatedude2/node-readfiles.git"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"dependencies":{"es6-promise":"^3.2.1"},"gitHead":"5dae40bf928bc09a2e65f49c19b29f72ae9b325d","bugs":{"url":"https://github.com/guatedude2/node-readfiles/issues"},"homepage":"https://github.com/guatedude2/node-readfiles#readme","_id":"node-readfiles@0.1.0","_shasum":"83a69921d390487dd89c0251dbf31457eb93fe74","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"83a69921d390487dd89c0251dbf31457eb93fe74","size":6185,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.1.0.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-readfiles-0.1.0.tgz_1463630164907_0.601460000500083"},"directories":{},"publish_time":1463630167218,"_cnpm_publish_time":1463630167218,"_hasShrinkwrap":false},"0.0.9":{"name":"node-readfiles","version":"0.0.9","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/guatedude2/node-readfiles.git"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"fbad7233ee964b10f39c6bb702b92b4a2d9d84e7","bugs":{"url":"https://github.com/guatedude2/node-readfiles/issues"},"homepage":"https://github.com/guatedude2/node-readfiles#readme","_id":"node-readfiles@0.0.9","_shasum":"6f7501827d2bdec5109eea609408c538a65875a5","_from":".","_npmVersion":"3.5.2","_nodeVersion":"4.2.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"6f7501827d2bdec5109eea609408c538a65875a5","size":6073,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.9.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.9.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.9.tgz_1463587775999_0.4389930502511561"},"directories":{},"publish_time":1463587778834,"_cnpm_publish_time":1463587778834,"_hasShrinkwrap":false},"0.0.8":{"name":"node-readfiles","version":"0.0.8","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/guatedude2/node-readfiles.git"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"5fbff39b6d14a0b2a78d7bc1a43777c9e2c37e72","bugs":{"url":"https://github.com/guatedude2/node-readfiles/issues"},"homepage":"https://github.com/guatedude2/node-readfiles#readme","_id":"node-readfiles@0.0.8","_shasum":"caa23c09463b457c1ca0912b598280637e542d17","_from":".","_npmVersion":"3.5.2","_nodeVersion":"4.2.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"caa23c09463b457c1ca0912b598280637e542d17","size":5858,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.8.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.8.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.8.tgz_1463585736178_0.15521592157892883"},"directories":{},"publish_time":1463585738739,"_cnpm_publish_time":1463585738739,"_hasShrinkwrap":false},"0.0.7":{"name":"node-readfiles","version":"0.0.7","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"d7dd26ec2fb8e84acc0df6756e44a7c72bb41ba6","_id":"node-readfiles@0.0.7","_shasum":"0656b8d6af66f73d598f1b23d507a2b840edbf43","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"0656b8d6af66f73d598f1b23d507a2b840edbf43","size":5845,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.7.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.7.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.7.tgz_1463576965911_0.6309957099147141"},"directories":{},"publish_time":1463576968735,"_cnpm_publish_time":1463576968735,"_hasShrinkwrap":false},"0.0.6":{"name":"node-readfiles","version":"0.0.6","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"4c34bcbe8d23082c53ab578bc1887c838c5a4c13","_id":"node-readfiles@0.0.6","_shasum":"5dfb3c0b750aa6324592b8dce50a0e063c65a04b","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"5dfb3c0b750aa6324592b8dce50a0e063c65a04b","size":5805,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.6.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.6.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.6.tgz_1463548249605_0.724565886426717"},"directories":{},"publish_time":1463548252441,"_cnpm_publish_time":1463548252441,"_hasShrinkwrap":false},"0.0.5":{"name":"node-readfiles","version":"0.0.5","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"e8dcaae152f9deb3fb519ef3de4d09df01f3f7f2","_id":"node-readfiles@0.0.5","_shasum":"6d38f37dc2c531f612933d4ea4d7dc27f9efbd5e","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"6d38f37dc2c531f612933d4ea4d7dc27f9efbd5e","size":5569,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.5.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.5.tgz_1463547054756_0.23959506675601006"},"directories":{},"publish_time":1463547057332,"_cnpm_publish_time":1463547057332,"_hasShrinkwrap":false},"0.0.4":{"name":"node-readfiles","version":"0.0.4","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"398a6b5bb55c7685e7ac46879ad141f92daf934e","_id":"node-readfiles@0.0.4","_shasum":"02ef1bb42560d2841592c81c8467d8689cb36ddc","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"02ef1bb42560d2841592c81c8467d8689cb36ddc","size":5564,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.4.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.4.tgz_1463546863676_0.6749484224710613"},"directories":{},"publish_time":1463546866121,"_cnpm_publish_time":1463546866121,"_hasShrinkwrap":false},"0.0.3":{"name":"node-readfiles","version":"0.0.3","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"11935ecde08f26e4685b0edaa42091507e505adb","_id":"node-readfiles@0.0.3","_shasum":"cc35825adaf418dfa260fac348a2d8767158d247","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"cc35825adaf418dfa260fac348a2d8767158d247","size":5557,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.3.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.3.tgz_1463546664405_0.7907962505705655"},"directories":{},"publish_time":1463546667041,"_cnpm_publish_time":1463546667041,"_hasShrinkwrap":false},"0.0.2":{"name":"node-readfiles","version":"0.0.2","description":"A lightweight Node.js module to recursively read files in a directory","main":"index.js","scripts":{"test":"mocha"},"keywords":["readfiles","read","readfile","readdir","dir","path","pattern","fs"],"author":{"name":"Alejandro Gonzalez Sole"},"license":"MIT","devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","mock-fs":"^3.9.0"},"gitHead":"54cb1bb8ec8552263eb389c9f725aafa9b029a1f","_id":"node-readfiles@0.0.2","_shasum":"e8fbe739927e8933b0901a7f9c267e46592346c6","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.1","_npmUser":{"name":"guatedude2","email":"guatedude@gmail.com"},"dist":{"shasum":"e8fbe739927e8933b0901a7f9c267e46592346c6","size":5546,"noattachment":false,"key":"/node-readfiles/-/node-readfiles-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-readfiles/download/node-readfiles-0.0.2.tgz"},"maintainers":[{"name":"guatedude2","email":"guatedude@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-readfiles-0.0.2.tgz_1463546112437_0.3232190776616335"},"directories":{},"publish_time":1463546115075,"_cnpm_publish_time":1463546115075,"_hasShrinkwrap":false}},"readme":"# node-readfiles\nA lightweight node.js module to recursively read files in a directory using ES6 Promises.\n\n## Installation\n\n    npm install node-readfiles\n\n## Usage\n\nYou can safely add `readfiles` anywhere in your project.\n\n```javascript\nvar readfiles = require('node-readfiles');\n```\n\n### _Promise(files):_ readfiles(dir, [options], [callback])\nAsynchronusly read the files in a directory returning a **Promise**.\n\n#### dir\nA relative or absolute path of the directory to read files.\n\n#### options\n\nAn optional object parameter with the following properties:\n\n* **reverse**: a bollean value that reverses the order of the list of files before traversing them (defaults to false)\n* **filenameFormat**: one of `readfiles.FULL_PATH`, `readfiles.RELATIVE`, or `readfiles.FILENAME`, wether the callback's returns the full-path, relative-path or only the filenames of the traversed files. (default is `readfiles.RELATIVE`)\n* **rejectOnError**: a bollean value wether to stop and trigger the \"doneCallback\" when an error occurs (defaults to true)\n* **filter**: a string, or an array of strings of path expression that match the files being read (defaults to '**')\n  * `?` matches one character\n  * `*` matches zero or more characters\n  * `**` matches zero or more 'directories' in a path\n* **readContents**: a boolean value wether to read the file contents when traversing the files <sup>[\\[1\\]](#read-files)</sup> (defaults to true)\n* **encoding**: a string with the encoding used when reading a file (defaults to 'utf8')\n* **depth**: an integer value which limits the number sub-directories levels to traverse for the given path where `-1` is infinte, and `0` is none (defaults to -1)\n* **hidden**: a boolean value wether to exclude hidden files prefixed with a `.` (defaults to true)\n\n\n### callback(err, filename, content, stat)\n\nThe optional callback function is triggered everytime a file is found. If there's an error while reading the file the `err` parameter will contain the error that occured, When `readContents` is true, the `contents` parameter will be populated with the contents of the file encoded using the `encoding` option. For convenience the `stat` result object is passed to the callback for you to use.\n\n<span id=\"read-files\">[1]</span> The `contents` parameter will be `null` when the `readContents` option is `false`.\n\n\n##### Asynchronous Callback\nWhen working with asynchronous operations, you can simply return a `function (next) { ... }` which will enabled you to completed your asynchronous operation until you call `next()`. \n\n```javascript\nreadfiles('/path/to/dir/', function (err, content, filename, stat) {\n  if (err) throw err;\n  return function (next) {\n    setTimeout(function () {\n      console.log('File ' + filename);\n      next();\n    }, 3000);\n  };\n});\n```\n\n\n### _Promise(files)_\n\nWhen calling `readfiles`, an ES6 Promise is returned with an array of all the files that were found. You can then call `then` or `catch` to see if `readfiles` encountered an error.\n\n```javascript\nvar readfiles = require('node-readfiles');\n\nreadfiles('/path/to/dir/', function (err, filename, contents) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n}).catch(function (err) {\n  console.log('Error reading files:', err.message);\n});\n```\n\n## Examples\n\nThe default behavior, is to recursively list all files in a directory. By default `readfiles` will exclude all dot files.\n\n```javascript\nreadfiles('/path/to/dir/', function (err, filename, contents) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n  console.log(files.join('\\n'));\n});\n```\n\nRead all files in a directory, excluding sub-directories.\n\n```javascript\nreadfiles('/path/to/dir/', {\n  depth: 0\n}, function (err, content, filename) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n  console.log(files.join('\\n'));\n});\n```\n\nThe above can also be accomplished using the `filter` option.\n\n```javascript\nreadfiles('/path/to/dir/', {\n  filter: '*' // instead of the default '**'\n}, function (err, content, filename) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n  console.log(files.join('\\n'));\n});\n```\n\nRecursively read all files with \"txt\" extension in a directory and display the contents.\n\n```javascript\nreadfiles('/path/to/dir/', {\n  filter: '*.txt'\n}, function (err, content, filename) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n});\n\n```\n\nRecursively read all files with that match \"t?t\" in a directory and display the contents.\n\n```javascript\nreadfiles('/path/to/dir/', {\n  filter: '*.t?t'\n}, function (err, content, filename) {\n  if (err) throw err;\n  console.log('File ' + filename + ':');\n  console.log(content);\n}).then(function (files) {\n  console.log('Read ' + files.length + ' file(s)');\n});\n\n```\n\nRecursively list all json files in a directory including all sub-directories, without reading the files.\n\n```javascript\nreadfiles('/path/to/dir/', {\n  filter: '*.json',\n  readContents: false\n}, function (err, content, filename) {\n  if (err) throw err;\n  console.log('File ' + filename);\n});\n\n```\n\n## License\nMIT licensed (See LICENSE.txt)\n","_attachments":{},"homepage":"https://github.com/guatedude2/node-readfiles#readme","bugs":{"url":"https://github.com/guatedude2/node-readfiles/issues"},"license":"MIT"}