rmby ("remove by") is a zero-dependency Node.js library with a fluent interface for removing files asynchronously by certain aspects.
Node.js v12 or higher is required
$ npm i --save rmby
$ yarn add rmby
The remove
function is all you need. You can navigate yourself through the API by chaining functions, since the API provides a fluent interface. On the API section you can see more details about the usage.
// JavaScript
const { remove } = require("rmby");
// TypeScript
import { remove } from "rmby";
In order to run your remove query, you have to call the run()
method at the end of your function chain. This function will remove all files that match with your filter criteria and will return a Promise<string[]>
containing every file path that has been removed. If your filter cannot find matches, it will just return an empty array and do nothing.
Files can be removed by a time difference in milliseconds, seconds, minutes or hours. The time difference is always checked against the current time.
// Remove all files that are older than 12 hours
remove().from("/some/path/to/dir").byTime().olderThan(12).hours().run();
Files can be removed regarding its name without considering the file extension. You can remove files that match exactly, start with, end with, or include the name that you provide.
// Remove all files that start with "React"
remove().from("/some/path/to/dir").byName().thatStartsWith("React").run();
Files can be removed regarding their file extension. You can remove files that match exactly with the file extension you provide.
// Remove all .log files
remove().from("/some/path/to/dir").byExtension(".log").run();
Files can be removed by combining the available filters. Therefore you can create more specific filters for your use case.
// Remove all log files that start with "app" and are older than 12 hours
remove()
.from("/some/path/to/dir")
.byName()
.thatStartsWith("app")
.and()
.byExtension(".log")
.and()
.byTime()
.olderThan(12)
.hours()
.run();
rmby is developed with TypeScript. The master
branch is used for development. Stable releases are always tagged with the latest version.
rmby is using Jest as a JavaScript Testing Framework. For testing, run npm test
. For code coverage, run npm run test:cov
. We have currently 100% code coverage and aim to stick with it.
The philosophy is to provide an easy to use library for file removal in Node.js, without dependencies and with a very declarative API. The fluent interface should guide the user through its use case.
rmby is currently maintained by Yadullah Duman