pax_global_header00006660000000000000000000000064134416747420014526gustar00rootroot0000000000000052 comment=b60678846423629b1293955d88a41f7e1d87c338 path-type-4.0.0/000077500000000000000000000000001344167474200134425ustar00rootroot00000000000000path-type-4.0.0/.editorconfig000066400000000000000000000002571344167474200161230ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 path-type-4.0.0/.gitattributes000066400000000000000000000000231344167474200163300ustar00rootroot00000000000000* text=auto eol=lf path-type-4.0.0/.gitignore000066400000000000000000000000541344167474200154310ustar00rootroot00000000000000node_modules yarn.lock .nyc_output coverage path-type-4.0.0/.npmrc000066400000000000000000000000231344167474200145550ustar00rootroot00000000000000package-lock=false path-type-4.0.0/.travis.yml000066400000000000000000000001161344167474200155510ustar00rootroot00000000000000os: - osx - linux - windows language: node_js node_js: - '10' - '8' path-type-4.0.0/index.d.ts000066400000000000000000000024201344167474200153410ustar00rootroot00000000000000export type PathTypeFunction = (path: string) => Promise; /** * 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. */ 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. */ export const isSymlink: PathTypeFunction; export type PathTypeSyncFunction = (path: string) => boolean; /** * 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. */ 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. */ export const isSymlinkSync: PathTypeSyncFunction; path-type-4.0.0/index.js000066400000000000000000000022301344167474200151040ustar00rootroot00000000000000'use strict'; const {promisify} = require('util'); const fs = require('fs'); async function isType(fsStatType, statsMethodName, filePath) { if (typeof filePath !== 'string') { throw new TypeError(`Expected a string, got ${typeof filePath}`); } try { const stats = await promisify(fs[fsStatType])(filePath); return stats[statsMethodName](); } catch (error) { if (error.code === 'ENOENT') { return false; } throw error; } } function isTypeSync(fsStatType, statsMethodName, filePath) { if (typeof filePath !== 'string') { throw new TypeError(`Expected a string, got ${typeof filePath}`); } try { return fs[fsStatType](filePath)[statsMethodName](); } catch (error) { if (error.code === 'ENOENT') { return false; } throw 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'); path-type-4.0.0/index.test-d.ts000066400000000000000000000007231344167474200163220ustar00rootroot00000000000000import {expectType} from 'tsd-check'; import { isFile, isDirectory, isSymlink, isFileSync, isDirectorySync, isSymlinkSync } from '.'; expectType>(isFile('package.json')); expectType>(isDirectory('package.json')); expectType>(isSymlink('package.json')); expectType(isFileSync('package.json')); expectType(isDirectorySync('package.json')); expectType(isSymlinkSync('package.json')); path-type-4.0.0/license000066400000000000000000000021251344167474200150070ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. path-type-4.0.0/package.json000066400000000000000000000013121344167474200157250ustar00rootroot00000000000000{ "name": "path-type", "version": "4.0.0", "description": "Check if a path is a file, directory, or symlink", "license": "MIT", "repository": "sindresorhus/path-type", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && nyc ava && tsd-check" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "path", "fs", "type", "is", "check", "directory", "dir", "file", "filepath", "symlink", "symbolic", "link", "stat", "stats", "filesystem" ], "devDependencies": { "ava": "^1.3.1", "nyc": "^13.3.0", "tsd-check": "^0.3.0", "xo": "^0.24.0" } } path-type-4.0.0/readme.md000066400000000000000000000021301344167474200152150ustar00rootroot00000000000000# path-type [![Build Status](https://travis-ci.org/sindresorhus/path-type.svg?branch=master)](https://travis-ci.org/sindresorhus/path-type) > Check if a path is a file, directory, or symlink ## Install ``` $ npm install path-type ``` ## Usage ```js const {isFile} = require('path-type'); (async () => { console.log(await isFile('package.json')); //=> true })(); ``` ## API ### isFile(path) Check whether the passed `path` is a file. Returns a `Promise`. #### path Type: `string` The path to check. ### isDirectory(path) Check whether the passed `path` is a directory. Returns a `Promise`. ### isSymlink(path) Check whether the passed `path` is a symlink. Returns a `Promise`. ### isFileSync(path) Synchronously check whether the passed `path` is a file. Returns a `boolean`. ### isDirectorySync(path) Synchronously check whether the passed `path` is a directory. Returns a `boolean`. ### isSymlinkSync(path) Synchronously check whether the passed `path` is a symlink. Returns a `boolean`. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) path-type-4.0.0/symlink000077700000000000000000000000001344167474200163632test.jsustar00rootroot00000000000000path-type-4.0.0/test/000077500000000000000000000000001344167474200144215ustar00rootroot00000000000000path-type-4.0.0/test/eacces.js000066400000000000000000000011001344167474200161720ustar00rootroot00000000000000import fs from 'fs'; import test from 'ava'; import pathType from '..'; function fakeError(fp) { const error = new Error(`EACCES: permission denied, stat '${fp}'`); error.code = 'EACCES'; return error; } Object.defineProperties(fs, { stat: { value(fp, cb) { cb(fakeError(fp)); } }, statSync: { value(fp) { throw fakeError(fp); } } }); test('throws on EACCES error - async', async t => { await t.throwsAsync(pathType.isFile('/root/private')); }); test('throws on EACCES error - sync', t => { t.throws(() => pathType.isFileSync('/root/private')); }); path-type-4.0.0/test/nominal.js000066400000000000000000000022221344167474200164120ustar00rootroot00000000000000import test from 'ava'; import pathType from '..'; test('.file()', async t => { t.true(await pathType.isFile('package.json')); await t.throwsAsync(pathType.isFile(false)); }); test('.dir()', async t => { t.true(await pathType.isDirectory('.')); await t.throwsAsync(pathType.isDirectory(false)); }); if (process.platform !== 'win32') { test('.symlink()', async t => { t.true(await pathType.isSymlink('symlink')); await t.throwsAsync(pathType.isSymlink(false)); }); } test('.fileSync()', t => { t.true(pathType.isFileSync('package.json')); }); test('.dirSync()', t => { t.true(pathType.isDirectorySync('.')); }); if (process.platform !== 'win32') { test('.symlinkSync()', t => { t.true(pathType.isSymlinkSync('symlink')); }); } test('return false if path doesn\'t exist - async', async t => { t.false(await pathType.isFile('unicorn')); }); test('return false if path doesn\'t exist - sync', t => { t.false(pathType.isFileSync('unicorn')); }); test('throws invalid argument - async', async t => { await t.throwsAsync(pathType.isFile(false)); }); test('throws on invalid argument - sync', t => { t.throws(() => pathType.isFileSync(false)); });