-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
82516fa
commit 3e66105
Showing
8 changed files
with
50 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
import fs, {promises as fsPromises} from 'node:fs'; | ||
|
||
module.exports = async path => { | ||
export async function pathExists(path) { | ||
try { | ||
await fs.promises.access(path); | ||
await fsPromises.access(path); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
module.exports.sync = path => { | ||
export function pathExistsSync(path) { | ||
try { | ||
fs.accessSync(path); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {expectType} from 'tsd'; | ||
import pathExists = require('.'); | ||
import {pathExists, pathExistsSync} from './index.js'; | ||
|
||
expectType<Promise<boolean>>(pathExists('foo.ts')); | ||
expectType<boolean>(pathExists.sync('foo.ts')); | ||
expectType<boolean>(pathExistsSync('foo.ts')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import test from 'ava'; | ||
import pathExists from '.'; | ||
import {pathExists, pathExistsSync} from './index.js'; | ||
|
||
test('async', async t => { | ||
t.true(await pathExists('test.js')); | ||
t.false(await pathExists('fail')); | ||
}); | ||
|
||
test('sync', t => { | ||
t.true(pathExists.sync('test.js')); | ||
t.false(pathExists.sync('fail')); | ||
t.true(pathExistsSync('test.js')); | ||
t.false(pathExistsSync('fail')); | ||
}); |