The missing fs.promises.exists()
npm install fs.promises.existsThe missing fs.promises.exists(). Also supports case-sensitive/insensitive file paths.
If you like this project, please star it & follow me to see what other cool projects I'm working on! ❤️
exists() method that replaces existsSync().- Depending on how the file-system is configured, file paths can be case-sensitive or insensitive. This module lets you specify case regardless of the file-system configuration.
sh
npm i fs.promises.exists
`👨🏻🏫 Examples
$3
`js
import fsExists from 'fs.promises.exists'await fsExists('./file-that-exists')
// => true
await fsExists('./file-that-doesnt-exist')
// => false
`
$3
`js
import fsExists from 'fs.promises.exists'await fsExists('./CASE-SENSITIVE-FILE-PATH', true)
// => true
await fsExists('./case-sensitive-file-path', true)
// => false
`$3
`js
import fsExists from 'fs.promises.exists'await fsExists('./CASE-SENSITIVE-FILE-PATH', false)
// => ./CASE-SENSITIVE-FILE-PATH ← Retruns truthy case-preserved match
await fsExists('./case-sensitive-file-path', false)
// => ./CASE-SENSITIVE-FILE-PATH ← Retruns truthy case-preserved match
`⚙️ API
$3
Returns:
boolean | string
#### filePath
Type: stringRequired
Path to the file to check the existence of.
#### caseSensitive
Type:
booleanOptional
Whether to check the existence of the path case-sensitively or not.
-
true - Enforce case sensitive path checking.
- false - Enforce case insensitive path checking. On match, it returns the case senstive path as a string.
- undefined - Default behavior is based on the disk formatting of the environment. Specifically, this is the HFS+ file system personality. Most default setups (such as macOS) defaults to being case insensitive. That means checking whether
./does-file-exist and ./DoEs-FiLe-ExIsT` are equivalent.