{"_id":"@databyss-org/find-remove","_rev":"2-2bfe76d6b16a67c6b9c53f9fe9d67a9a","name":"@databyss-org/find-remove","dist-tags":{"latest":"3.1.0-b1"},"versions":{"3.1.0-b1":{"name":"@databyss-org/find-remove","version":"3.1.0-b1","description":"recursively finds files and/or directories by filter options from a start directory onwards and deletes these according to plenty of options you can configure. useful if you want to clean up stuff within a directory in your node.js app.","main":"dist/find-remove.js","author":{"name":"Michael Heuberger","email":"michael.heuberger@binarykitchen.com"},"keywords":["file","remove","rmdir","unlink","find","filter","recursive","fs","delete","extension","file stats"],"dependencies":{"fmerge":"1.2.0","rimraf":"3.0.2"},"devDependencies":{"@babel/cli":"7.13.16","@babel/core":"7.13.16","@babel/eslint-parser":"7.13.14","@babel/node":"7.13.13","@babel/preset-env":"7.13.15","eslint":"7.25.0","eslint-config-standard":"16.0.2","eslint-plugin-import":"2.22.1","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"5.1.0","microbundle":"0.13.0","mkdirp":"1.0.4","nodeunit":"0.11.3","prettier":"2.2.1","randomstring":"1.1.5"},"engines":{"node":">=14.4.0","yarn":"^1.17.0"},"source":"src/index.js","module":"dist/find-remove.mjs","unpkg":"dist/find-remove.umd.js","scripts":{"test":"nodeunit tests/basics.js","lint":"eslint ./src ./tests","lint-fix":"yarn --silent lint --fix; exit 0","prettier":"prettier --check ./src ./tests","prettier-fix":"prettier --write ./src ./tests","build":"microbundle"},"repository":{"type":"git","url":"https://github.com/binarykitchen/find-remove.git"},"license":"MIT","licenseText":"Copyright (c) 2013 - 2020 Michael Heuberger\n\nPermission is hereby granted, free of charge,\nto any person obtaining a copy of this software and\nassociated documentation files (the \"Software\"), to\ndeal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify,\nmerge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom\nthe Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice\nshall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\nANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"@databyss-org/find-remove@3.1.0-b1","dist":{"shasum":"d7a01a583d853e137606035fa6f46e71bb5f2200","integrity":"sha512-HFWImXkiIhWu1r8YE0xUS2tZ2qpiAP6TNg+PUJZZbu9Y2iVg+2TiXL6iiw3Ijchg7rdJb1b3gRgHIfjlXME9jw==","tarball":"https://registry.npmjs.org/@databyss-org/find-remove/-/find-remove-3.1.0-b1.tgz","fileCount":21,"unpackedSize":99725,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2Dt5CRA9TVsSAnZWagAAUmgQAJpaETKhWXgkt1pP/Og3\nAm6M7TQxEe/xyenL+lhke5qITkOHCT2QFyOpgx89ij/IsUxRTXHDubC5s1ks\nnhCXxJ/VNOte4hhON1ik1meU9N7KuW4yjSo3d0WWv5KWRKEx5ziD/PJB0atl\njwdpW0IuncSMbKhTArqd5fg5EzjFXT1Mla7oYxpeYXuxbzmdONnKgUt3Msmp\nM0VAZGokm4+hOhOzv9LDEpZYfN/ZaPXsrxk1k3cplPiepoVf0toJaTD5rWW9\nP7DJmzxaEgC6y6XSfPUST3/jg3lrU1pP4pXz0u6gT0KNuyhF6zJuHjWNexGv\nxrI3/JotoUBCsAExNjM7WIJdsgY2AVsKXrdPKOOo+KQNei/pLFXyEMiug61C\n5B+OxZfx4KBsc6t2x9kA2zEvAmKmXLNYRcPMsegn75eqQTlYbw9j0QZtT+M2\n9U+WM4IRWYNrrdj3LWUXxdEX3Cypk2l982+IsLQecaoITHUy4Kko4dxpiw74\ngYlK7dj3jqOEHY8E8tj8DMU73SYR33pOAiAZ/qhP4nmuUf0TtThFhnuR6YPg\ndE1puhQPlT34UVSLm+pMS9BzOEykaIwg8VLSCu2fYweFm0kGo3r2bIIYp7Yi\nGYlAgsfObELHQHM692lG/0ZZMuvmKB791bNP+Xlj5YmpM5TLANDX2LlTyYta\nhPnO\r\n=K0zQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCFpqUUAqMFaRFPzpZyAAilgIZUU0pUvJjqgNr86gqPMAIhALCuqSuKST4zjLrtA+8Sbq39KsPMr5zvoIU2sTIVe3Cu"}]},"_npmUser":{"name":"pzhine","email":"paul@hine.works"},"directories":{},"maintainers":[{"name":"pzhine","email":"paul@hine.works"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/find-remove_3.1.0-b1_1635166145345_0.4865317393849462"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-25T12:49:05.298Z","3.1.0-b1":"2021-10-25T12:49:05.561Z","modified":"2022-04-05T02:51:43.889Z"},"maintainers":[{"name":"pzhine","email":"paul@hine.works"}],"description":"recursively finds files and/or directories by filter options from a start directory onwards and deletes these according to plenty of options you can configure. useful if you want to clean up stuff within a directory in your node.js app.","keywords":["file","remove","rmdir","unlink","find","filter","recursive","fs","delete","extension","file stats"],"repository":{"type":"git","url":"https://github.com/binarykitchen/find-remove.git"},"author":{"name":"Michael Heuberger","email":"michael.heuberger@binarykitchen.com"},"license":"MIT","readme":"# find-remove\n\n[![Build Status](https://travis-ci.org/binarykitchen/find-remove.png?branch=master)](https://travis-ci.org/binarykitchen/find-remove)\n\nrecursively finds files by filter options from a start directory onwards and deletes only those which meet conditions you can define. useful if you want to clean up a directory in your node.js app.\n\nyou can filter by extensions, names, level in directory structure, file creation date and ignore by name, yeah!\n\n## installation\n\nto install find-remove, use [npm](http://github.com/isaacs/npm):\n\n    $ npm install -S find-remove\n\nthen in your node.js app, get reference to the function like that:\n\n```javascript\nconst findRemoveSync = require('find-remove')\n```\n\n## quick examples\n\n### 1. delete all _.bak or _.log files within the /temp/ directory\n\n```javascript\nconst result = findRemoveSync('/temp', { extensions: ['.bak', '.log'] })\n```\n\nthe return value `result` is a json object with successfully deleted files. if you output `result` to the console, you will get something like this:\n\n```\n{\n    '/tmp/haumiblau.bak': true,\n    '/tmp/dump.log': true\n}\n```\n\n### 2. delete all files called 'dump.log' within the /temp/ directory and within its subfolders\n\n```javascript\nvar result = findRemoveSync('/temp', { files: 'dump.log' })\n```\n\n### 3. same as above, but also deletes any subfolders\n\n```javascript\nvar result = findRemoveSync('/temp', { files: 'dump.log', dir: '*' })\n```\n\n### 4. delete all \\*.bak files but not file 'haumiblau.bak'\n\n```javascript\nvar result = findRemoveSync('/temp', { extensions: ['.bak'], ignore: 'haumiblau.bak' })\n```\n\n### 5. delete recursively any subdirectory called 'CVS' within /dist/\n\n```javascript\nvar result = findRemoveSync('/dist', { dir: 'CVS' })\n```\n\n### 6. delete all jpg files older than one hour with limit of 100 files deletion per operation\n\n```javascript\nvar result = findRemoveSync('/tmp', {\n  age: { seconds: 3600 },\n  extensions: '.jpg',\n  limit: 100\n})\n```\n\n### 7. delete all files with prefix 'filenamestartswith'\n\n```javascript\nvar result = findRemoveSync('/tmp', { prefix: 'filenamestartswith' })\n```\n\n### 8. apply filter options only for two levels inside the /temp directory for all tmp files\n\n```javascript\nvar result = findRemoveSync('/tmp', { maxLevel: 2, extensions: '.tmp' })\n```\n\nthis deletes any `.tmp` files up to two levels, for example: `/tmp/level1/level2/a.tmp`\n\nbut not `/tmp/level1/level2/level3/b.tmp`\n\nwhy the heck do we have this `maxLevel` option? because of performance. if you care about deep subfolders, apply that option to get a speed boost.\n\n### 9. delete everything recursively (hey, who needs that when you can use nodejs' fs.unlink?)\n\n```javascript\nvar result = findRemoveSync(rootDirectory, { dir: '*', files: '*.*' })\n```\n\n### 9. delete all files that match a regular expression\n\n```javascript\nvar result = findRemoveSync(rootDirectory, { files: 'example[1-3]', regex: true })\n```\n\nthis deletes files `example1.txt`, `example2.txt`, and `example3.txt`, but not `example8.txt`.\n\n### 10. delete all directories that match a regular expression\n\n```javascript\nvar result = findRemoveSync(rootDirectory, { dir: '^assets_', regex: true })\n```\n\nthis deletes all directories that start with `assets_`.\n\n## api\n\n### findRemoveSync(dir, options)\n\nfindRemoveSync takes any start directory and searches files from there for removal. the selection of files for removal depends on the given options. and at last, it deletes the selected files/directories.\n\n**arguments**\n\n- `dir` - any directory to search for files and/or directories for deletion (does not delete that directory itself)\n- options - currently those properties are supported:\n  - `files` - can be a string or an array of files you want to delete within `dir`.\n  - `dir` - can be a string or an array of directories you want to delete within `dir`.\n  - `extensions` - this too, can be a string or an array of file extentions you want to delete within `dir`.\n  - `ignore` - useful to exclude some files. again, can be a string or an array of file names you do NOT want to delete within `dir`\n  - `age.seconds` - can be any float number. findRemoveSync then compares it with the file stats and deletes those with modification times older than `age.seconds`\n  - `limit` - can be any integer number. Will limit the number of <b>files</b> to be deleted at single operation to be `limit`\n  - `prefix` - can be any string. Will delete any files that start with `prefix`.\n  - `maxLevel` - advanced: limits filtering to a certain level. useful for performance. recommended for crawling huge directory trees.\n  - `test` - advanced: set to true for a test run, meaning it does not delete anything but returns a JSON of files/directories it would have deleted. useful for testing.\n  - `regex` - set to true to treat `files` or `dir` option strings as regular expression patterns.\n\nas a precaution, nothing happens when there are no options.\n\nthe unit tests are good examples on how to use the above arguments.\n\n**returns**\n\nJSON of files/directories that were deleted. For limit option - will only return number of files deleted.\n\n## todo\n\n- needs a rewrite\n- add more filtering options (e.g. combinations)\n- have an asynchronous solution\n- use streams instead\n\n## license\n\nMIT\n","readmeFilename":"README.md"}