Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igorskyflyer/npm-valid-path
🧰 Provides ways of testing whether a given value can be a valid file/directory name. 🏜
https://github.com/igorskyflyer/npm-valid-path
back-end directory file file-system filesystem igorskyflyer javascript mocha node path storage validation
Last synced: 14 days ago
JSON representation
🧰 Provides ways of testing whether a given value can be a valid file/directory name. 🏜
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-valid-path
- Owner: igorskyflyer
- License: mit
- Created: 2021-07-17T00:56:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T23:10:54.000Z (over 1 year ago)
- Last Synced: 2024-12-17T15:24:22.775Z (21 days ago)
- Topics: back-end, directory, file, file-system, filesystem, igorskyflyer, javascript, mocha, node, path, storage, validation
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/valid-path
- Size: 278 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
## Valid Path
🧰 Provides ways of testing whether a given value can be a valid file/directory name. 🏜
> 💃 Since `v.1.1.0` this package provides both a CommonJS module and an ES module, thanks to [`Modern Module`](https://github.com/igorskyflyer/npm-modern-module).
>
> What do you need to do to use one or the other?
>
> Nothing. If you need a CommonJS module `require` it, if you need an ES module `import` it instead. Simple, right?
### Usage
Install it by running,
```shell
npm i "@igor.dvlpr/valid-path"
```
### API
```ts
function isValidPath(path: string, isFile = true): boolean
```Returns whether the given path can be a valid file/directory name on the host machine.
```ts
function isValidPathUnix(path: string, isFile = true): boolean
```Returns whether the given path can be a valid file/directory name on Unix and Unix-like OS'.
```ts
function isValidPathWin(path: string, isFile = true): boolean
```Returns whether the given path can be a valid file/directory name on Windows OS.
### Examples
```js
const { isValidPathUnix, isValidPathWin, isValidPath } = require('@igor.dvlpr/valid-path')console.log(isValidPathUnix('hello&world.js', true)) // prints true
console.log(isValidPathUnix('hello/world.js', true)) // prints false
console.log(isValidPathUnix('hello/world')) // prints falseconsole.log(isValidPathWin('hello/world.js', true)) // prints false
console.log(isValidPathWin('hello/world', false)) // prints false
console.log(isValidPathWin('CON7')) // prints true
console.log(isValidPathWin('COM7.txt')) // prints false
console.log(isValidPathWin('CONnection')) // prints true
console.log(isValidPathWin('lpt1')) // prints false
console.log(isValidPathWin('hello&world.js', true)) // prints true// isValidPath() internally uses the appropriate method for supported OS' (Unix-like and Windows)
```