path-type
Advanced tools
Comparing version 4.0.0 to 5.0.0
export type PathTypeFunction = (path: string) => Promise<boolean>; | ||
/** | ||
* Check whether the passed `path` is a file. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a file. | ||
*/ | ||
Check whether the passed `path` is a file. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a file. | ||
*/ | ||
export const isFile: PathTypeFunction; | ||
/** | ||
* Check whether the passed `path` is a directory. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
Check whether the passed `path` is a directory. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a directory. | ||
*/ | ||
export const isDirectory: PathTypeFunction; | ||
/** | ||
* Check whether the passed `path` is a symlink. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a symlink. | ||
*/ | ||
Check whether the passed `path` is a symlink. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a symlink. | ||
*/ | ||
export const isSymlink: PathTypeFunction; | ||
@@ -30,23 +30,23 @@ | ||
/** | ||
* Synchronously check whether the passed `path` is a file. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a file. | ||
*/ | ||
Synchronously check whether the passed `path` is a file. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a file. | ||
*/ | ||
export const isFileSync: PathTypeSyncFunction; | ||
/** | ||
* Synchronously check whether the passed `path` is a directory. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
Synchronously check whether the passed `path` is a directory. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a directory. | ||
*/ | ||
export const isDirectorySync: PathTypeSyncFunction; | ||
/** | ||
* Synchronously check whether the passed `path` is a symlink. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
Synchronously check whether the passed `path` is a symlink. | ||
@param path - The path to check. | ||
@returns Whether the `path` is a directory. | ||
*/ | ||
export const isSymlinkSync: PathTypeSyncFunction; |
18
index.js
@@ -1,4 +0,2 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const fs = require('fs'); | ||
import fs, {promises as fsPromises} from 'fs'; | ||
@@ -11,3 +9,3 @@ async function isType(fsStatType, statsMethodName, filePath) { | ||
try { | ||
const stats = await promisify(fs[fsStatType])(filePath); | ||
const stats = await fsPromises[fsStatType](filePath); | ||
return stats[statsMethodName](); | ||
@@ -39,7 +37,7 @@ } catch (error) { | ||
exports.isFile = isType.bind(null, 'stat', 'isFile'); | ||
exports.isDirectory = isType.bind(null, 'stat', 'isDirectory'); | ||
exports.isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink'); | ||
exports.isFileSync = isTypeSync.bind(null, 'statSync', 'isFile'); | ||
exports.isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory'); | ||
exports.isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink'); | ||
export const isFile = isType.bind(null, 'stat', 'isFile'); | ||
export const isDirectory = isType.bind(null, 'stat', 'isDirectory'); | ||
export const isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink'); | ||
export const isFileSync = isTypeSync.bind(null, 'statSync', 'isFile'); | ||
export const isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory'); | ||
export const isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink'); |
{ | ||
"name": "path-type", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Check if a path is a file, directory, or symlink", | ||
"license": "MIT", | ||
"repository": "sindresorhus/path-type", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "xo && nyc ava && tsd-check" | ||
"test": "xo && nyc ava && tsd" | ||
}, | ||
@@ -29,3 +32,2 @@ "files": [ | ||
"directory", | ||
"dir", | ||
"file", | ||
@@ -41,7 +43,7 @@ "filepath", | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"nyc": "^13.3.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"nyc": "^15.1.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.37.1" | ||
} | ||
} |
@@ -1,6 +0,5 @@ | ||
# path-type [![Build Status](https://travis-ci.org/sindresorhus/path-type.svg?branch=master)](https://travis-ci.org/sindresorhus/path-type) | ||
# path-type | ||
> Check if a path is a file, directory, or symlink | ||
## Install | ||
@@ -12,15 +11,11 @@ | ||
## Usage | ||
```js | ||
const {isFile} = require('path-type'); | ||
import {isFile} from 'path-type'; | ||
(async () => { | ||
console.log(await isFile('package.json')); | ||
//=> true | ||
})(); | ||
console.log(await isFile('package.json')); | ||
//=> true | ||
``` | ||
## API | ||
@@ -70,5 +65,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-path-type?utm_source=npm-path-type&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
5645
75
Yes
72