Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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't

await rmf('a.jpg'); //=> true
await rmf('b.jpg'); //=> false

await rmf(process.cwd());
// rejected with Error: EPERM: operation not permitted, unlink '/Users/shinnn/'
})();
```

## License

[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe