Skip to content

privatenumber/fs.promises.exists

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

fs.promises.exists Latest version Monthly downloads Install size

The 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! โค๏ธ

๐Ÿ™‹โ€โ™‚๏ธ Why?

  • The fs Promises API doesn't have an 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.

๐Ÿš€ Install

npm i fs.promises.exists

๐Ÿ‘จ๐Ÿปโ€๐Ÿซ Examples

Basic check

import fsExists from 'fs.promises.exists'

await fsExists('./file-that-exists')
// => true

await fsExists('./file-that-doesnt-exist')
// => false

Case sensitive file path

import fsExists from 'fs.promises.exists'

await fsExists('./CASE-SENSITIVE-FILE-PATH', true)
// => true

await fsExists('./case-sensitive-file-path', true)
// => false

Case insensitive file path

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

fsExists(filePath, caseSensitive)

Returns: boolean | string

filePath

Type: string

Required

Path to the file to check the existence of.

caseSensitive

Type: boolean

Optional

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.

About

๐Ÿช The missing fs.promises.exists(). Also supports case-sensitive/insensitive file paths.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published