2.0.0 • Published 6 years ago

rmf v2.0.0

Weekly downloads
36
License
ISC
Repository
github
Last release
6 years ago

rmf

npm version Build Status Coverage Status

Remove a file or symbolic link without throwing an error when the target does not exist, as UNIX rm -f does

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 npm.

npm install rmf

API

const rmf = require('rmf');

rmf(filePath)

filePath: string Buffer Uint8Array URL
Return: Promise<boolean>

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.

(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 © 2018 Shinnosuke Watanabe

2.0.0

6 years ago

2.0.0-5

6 years ago

2.0.0-4

6 years ago

2.0.0-3

6 years ago

2.0.0-2

6 years ago

2.0.0-1

6 years ago

2.0.0-0

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago