Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 18 days 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T23:10:34.000Z (over 1 year ago)
- Last Synced: 2024-11-06T02:14:40.421Z (2 months ago)
- Topics: back-end, directory, exists, filesystem, folder, igorskyflyer, nodejs, npm, package, path, posix, storage, unix, windows
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/pathexists
- Size: 138 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, read more below. 🗺
> âš 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.
✨ Since `v.2.0.0` `pathexists` is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to [Modern Module](https://github.com/igorskyflyer/npm-modern-module).
### Usage
Install it first, by doing:
```shell
npm i "@igor.dvlpr/pathexists"
```and then...
```js
const { pathExists, pathExistsWindows, pathExistsUnix } = require('@igor.dvlpr/pathexists')const allPaths = ['abc.js', 'etc.bak']
const winPaths = ['D:\\', 'D:\\Temp\\a.js']
const unixPaths = ['/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
```