UNPKG

2.26 kBMarkdownView Raw
1# is-there
2A library to check if a file or directory exists in a given path.
3
4## Why? `fs.exists` already does the job!
5Because `fs.exists` and `fs.existsSync` will be deprecated and I still like and need them!
6
7> `fs.exists()` is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code.
8
9> In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to `fs.exists()` and `fs.open()`. Just open the file and handle the error when it's not there.
10
11> **`fs.exists()` will be deprecated.**
12
13> <sup>([Source](http://nodejs.org/api/fs.html#fs_fs_exists_path_callback), emphasis added)</sup>
14
15## Installation
16```sh
17$ npm install is-there
18```
19
20## Example
21```js
22// Dependencies
23var IsThere = require("is-there");
24
25// Async call
26IsThere("path/to/the/file/or/directory", function (exists) {
27 if (exists) {
28 // do something if it exists
29 } else {
30 // do something if it doesn't exist
31 }
32});
33
34// Sync call
35var exists = IsThere("path/to/the/file/or/directory")
36if (exists) {
37 // do something if it exists
38} else {
39 // do something if it doesn't exist
40}
41```
42
43## Documentation
44### `IsThere(path, callback)`
45Checks if a file or directory exists on given path.
46
47#### Params
48- **String** `path`: The path to the file or directory.
49- **Function** `callback`: The callback function called with a boolean value representing if the file or directory exists.
50
51#### Return
52- **IsThere** The `IsThere` function.
53
54### `sync(path)`
55The sync version of `IsThere`.
56
57#### Params
58- **String** `path`: The path to the file or directory.
59
60#### Return
61- **Boolean** A boolean value representing if the file or directory exists.
62
63
64## How to contribute
651. File an issue in the repository, using the bug tracker, describing the
66 contribution you'd like to make. This will help us to get you started on the
67 right foot.
682. Fork the project in your account and create a new branch:
69 `your-great-feature`.
703. Commit your changes in that branch.
714. Open a pull request, and reference the initial issue in the pull request
72 message.
73
74## License
75See the [LICENSE](./LICENSE) file.