JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q46441F
  • License ISC

Remove a file or symbolic link without throwing an error when the target does not exist

Package Exports

  • rmf

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rmf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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