path-exists
Advanced tools
Comparing version 4.0.0 to 5.0.0
@@ -1,28 +0,31 @@ | ||
declare const pathExists: { | ||
/** | ||
Check if a path exists. | ||
/** | ||
Check if a path exists. | ||
@returns Whether the path exists. | ||
@returns Whether the path exists. | ||
@example | ||
``` | ||
// foo.ts | ||
import pathExists = require('path-exists'); | ||
@example | ||
``` | ||
// foo.ts | ||
import {pathExists} from 'path-exists'; | ||
(async () => { | ||
console.log(await pathExists('foo.ts')); | ||
//=> true | ||
})(); | ||
``` | ||
*/ | ||
(path: string): Promise<boolean>; | ||
console.log(await pathExists('foo.ts')); | ||
//=> true | ||
``` | ||
*/ | ||
export function pathExists(path: string): Promise<boolean>; | ||
/** | ||
Synchronously check if a path exists. | ||
/** | ||
Synchronously check if a path exists. | ||
@returns Whether the path exists. | ||
*/ | ||
sync(path: string): boolean; | ||
}; | ||
@returns Whether the path exists. | ||
export = pathExists; | ||
@example | ||
``` | ||
// foo.ts | ||
import {pathExistsSync} from 'path-exists'; | ||
console.log(pathExistsSync('foo.ts')); | ||
//=> true | ||
``` | ||
*/ | ||
export function pathExistsSync(path: string): boolean; |
20
index.js
@@ -1,23 +0,19 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const {promisify} = require('util'); | ||
import fs, {promises as fsPromises} from 'node:fs'; | ||
const pAccess = promisify(fs.access); | ||
module.exports = async path => { | ||
export async function pathExists(path) { | ||
try { | ||
await pAccess(path); | ||
await fsPromises.access(path); | ||
return true; | ||
} catch (_) { | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
} | ||
module.exports.sync = path => { | ||
export function pathExistsSync(path) { | ||
try { | ||
fs.accessSync(path); | ||
return true; | ||
} catch (_) { | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
} |
{ | ||
"name": "path-exists", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Check if a path exists", | ||
@@ -10,6 +10,8 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -36,6 +38,6 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# path-exists [![Build Status](https://travis-ci.org/sindresorhus/path-exists.svg?branch=master)](https://travis-ci.org/sindresorhus/path-exists) | ||
# path-exists | ||
@@ -7,4 +7,2 @@ > Check if a path exists | ||
While [`fs.exists()`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback) is being [deprecated](https://github.com/iojs/io.js/issues/103), there's still a genuine use-case of being able to check if a path exists for other purposes than doing IO with it. | ||
Never use this before handling a file though: | ||
@@ -14,3 +12,2 @@ | ||
## Install | ||
@@ -22,3 +19,2 @@ | ||
## Usage | ||
@@ -28,11 +24,8 @@ | ||
// foo.js | ||
const pathExists = require('path-exists'); | ||
import {pathExists} from 'path-exists'; | ||
(async () => { | ||
console.log(await pathExists('foo.js')); | ||
//=> true | ||
})(); | ||
console.log(await pathExists('foo.js')); | ||
//=> true | ||
``` | ||
## API | ||
@@ -44,14 +37,21 @@ | ||
### pathExists.sync(path) | ||
### pathExistsSync(path) | ||
Returns a `boolean` of whether the path exists. | ||
## Related | ||
- [path-exists-cli](https://github.com/sindresorhus/path-exists-cli) - CLI for this module | ||
- [path-type](https://github.com/sindresorhus/path-type) - Check if a path exists and whether it's a file, directory, or symlink | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-path-exists?utm_source=npm-path-exists&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4118
1
Yes
41