Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/rmf
Remove a file or symbolic link without throwing an error when the target does not exist, as UNIX `rm -f` does
https://github.com/shinnn/rmf
async deletion force javascript nodejs promise removal remove rm unlink
Last synced: 27 days ago
JSON representation
Remove a file or symbolic link without throwing an error when the target does not exist, as UNIX `rm -f` does
- Host: GitHub
- URL: https://github.com/shinnn/rmf
- Owner: shinnn
- License: isc
- Created: 2016-05-12T10:31:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-18T02:03:11.000Z (about 6 years ago)
- Last Synced: 2024-10-12T09:02:09.359Z (about 1 month ago)
- Topics: async, deletion, force, javascript, nodejs, promise, removal, remove, rm, unlink
- Language: JavaScript
- Homepage:
- Size: 109 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rmf
[![npm version](https://img.shields.io/npm/v/rmf.svg)](https://www.npmjs.com/package/rmf)
[![Build Status](https://travis-ci.org/shinnn/rmf.svg?branch=master)](https://travis-ci.org/shinnn/rmf)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/rmf.svg)](https://coveralls.io/github/shinnn/rmf?branch=master)Remove a file or symbolic link without throwing an error when the target does not exist, as UNIX `rm -f` does
```javascript
const {unlink} = require('fs').promises;
const rmf = require('rmf');// file.txt does not exist
(async () => {
await unlink('file.txt');
// will be rejected with Error: ENOENT: no such file or directory, unlink 'file.txt'await rmf('file.txt');
//=> won't be rejected
})();
```This library helps removing temporary files generated by test scripts, as they would not exist before the first execution.
## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install rmf
```## API
```javascript
const rmf = require('rmf');
```### rmf(*filePath*)
*filePath*: `string` `Buffer` `Uint8Array` `URL`
Return: `Promise`It removes a file or symbolic link.
When it successfully remove the target, the `Promise` will be resolved with `true`. When the target doesn't exist, the `Promise` will be resolved with `false`.
When the operation fails with another reason, for example the target is a directory, the `Promise` will be rejected.
```javascript
(async () => {
// A file a.jpg exists, but b.jpg doesn'tawait rmf('a.jpg'); //=> true
await rmf('b.jpg'); //=> falseawait rmf(process.cwd());
// rejected with Error: EPERM: operation not permitted, unlink '/Users/shinnn/'
})();
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe