file-exists-safe

Check if a file exists without try catch

Usage no npm install needed!

<script type="module">
  import fileExistsSafe from 'https://cdn.skypack.dev/file-exists-safe';
</script>

README


Check if a file exists without try catch.

  • Returns true if the path exists and is a file.
  • Returns false if the path is not a file, or does not exist.
  • Returns undefined on other errors (for example, permission denied) rather than throwing.

Installation

yarn add file-exists-safe
npm install file-exists-safe

API

import { fileExists, fileExistsSync, Options } from "file-exists-safe";

function fileExists(path: string, options?: Options): Promise<boolean | undefined>;

function fileExistsSync(path: string, options?: Options): boolean | undefined;

type Options = {
  /**
   * Return true if path is directory. Default: `false`
   */
  includeDirectories?: boolean;
}

Dev DependenciesDavid


License license

MIT


Related Packages

  • fs-safe: A simple fs wrapper that doesn't throw
  • dir-exists-safe: Check if a directory exists without a try catch