https://github.com/igorskyflyer/npm-pathexists
🧲 Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems. 🗺
https://github.com/igorskyflyer/npm-pathexists
back-end directory exists filesystem folder igorskyflyer nodejs npm package path posix storage unix windows
Last synced: 10 months ago
JSON representation
🧲 Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems. 🗺
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-pathexists
- Owner: igorskyflyer
- License: mit
- Created: 2021-07-11T19:56:00.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-30T16:52:59.000Z (11 months ago)
- Last Synced: 2025-09-30T19:41:51.038Z (10 months ago)
- Topics: back-end, directory, exists, filesystem, folder, igorskyflyer, nodejs, npm, package, path, posix, storage, unix, windows
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igorskyflyer/pathexists
- Size: 255 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
PathExists
🧲 Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems, using String manipulation techniques. 🗺
## 📃 Table of Contents
- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)
## 🤖 Features
- 🖥 OS‑aware checks - Adapts comparison rules for Windows or UNIX‑like systems
- 🔍 Path lookup - Quickly finds if a path exists in a given list
- 🛡 Case handling - Case‑insensitive on Windows, case‑sensitive on UNIX‑like
- ⚙️ Custom comparator - Plug in your own matching logic when needed
- 🔄 Reusable helpers - Separate functions for Windows, UNIX, and auto‑detect modes
- 📦 Lightweight - Minimal code, no heavy dependencies
- 🌍 Cross‑platform - Works consistently across different operating systems
> ⚠️ **WARNING**
>
> It does **NOT** actually check if the file/directory exists **on the disk**, it only checks if the given path exists in the list of paths. Useful when you have already obtained a list of files/directories and you want to check if a given path is eligible/available to, for example, create a new file at it.
>
## 🕵🏼 Usage
Install it by executing any of the following, depending on your preferred package manager:
```bash
pnpm add @igorskyflyer/pathexists
```
```bash
yarn add @igorskyflyer/pathexists
```
```bash
npm i @igorskyflyer/pathexists
```
## 🤹🏼 API
```ts
import { pathExists, pathExistsWindows, pathExistsUnix } from '@igorskyflyer/pathexists'
const allPaths: string[] = ['abc.js', 'etc.bak']
const winPaths: string[] = ['D:\\', 'D:\\Temp\\a.js']
const unixPaths: string[] = ['/home/user', '/home/user/a.js']
// #1 - host OS dependent mode - uses the appropriate function for each host OS
console.log(pathExists('abc.js', allPaths)) // prints true
// #1 - force Windows mode
console.log(pathExistsWindows('abc.js', allPaths)) // prints true
// #1 - force UNIX-like mode
console.log(pathExistsUnix('abc.js', allPaths)) // prints true
// #2 - force Windows mode
console.log(pathExistsWindows('abC.js', allPaths)) // prints true
// #2 - force UNIX-like mode
console.log(pathExistsUnix('abC.js', allPaths)) // prints false
// #3 - force Windows mode
console.log(pathExistsWindows('D:\\Temp\\A.js', winPaths)) // prints true
// #3 - force UNIX-like mode
console.log(pathExistsUnix('D:\\Temp\\A.js', unixPaths)) // prints false
// #4 - force Windows mode, custom Comparator
console.log(pathExistsWindows('Temp', winPaths, (entry, value) => entry.indexOf(value) > -1)) // prints true
// #4 - force UNIX-like mode, custom Comparator
console.log(pathExistsUnix('Temp', unixPaths, (entry, value) => entry.indexOf(value) > -1)) // prints true
```
## 📝 Changelog
📑 The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-pathexists/blob/main/CHANGELOG.md).
## 🪪 License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-pathexists/blob/main/LICENSE).
## 💖 Support
I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. ☕
Thank you for supporting my efforts! 🙏😊
## 🧬 Related
[@igorskyflyer/adblock-header-extract](https://www.npmjs.com/package/@igorskyflyer/adblock-header-extract)
> _✂️ An npm module that provides ways to extract header and metadata from an Adblock filter file. 📃_
[@igorskyflyer/upath](https://www.npmjs.com/package/@igorskyflyer/upath)
> _🎍 Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). 🧬_
[@igorskyflyer/uarray](https://www.npmjs.com/package/@igorskyflyer/uarray)
> _🎉 Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! 🙌_
[@igorskyflyer/git-repo-url](https://www.npmjs.com/package/@igorskyflyer/git-repo-url)
> _🌐 Gets the origin URL a local Git repository. 🗺️_
[@igorskyflyer/unc-path](https://www.npmjs.com/package/@igorskyflyer/unc-path)
> _🥽 Provides ways of parsing UNC paths and checking whether they are valid. 🎱_
## 👨🏻💻 Author
Created by **Igor Dimitrijević** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).