@igorskyflyer/valid-path
v3.0.0
Published
🧰 Determines whether a given value can be a valid file/directory name. 🏜
Downloads
14
Maintainers
Readme
📃 Table of Contents
🤖 Features
- 🧠 Detects if a file or folder name is valid for the system
- 🖥 Works on Windows and Unix like systems
- 🎯 Validates both file and directory names
- 🚫 Blocks names with reserved words or illegal characters
- 📏 Enforces system specific length limits
- ⚡ Returns a clear
trueorfalseresult instantly
🕵🏼 Usage
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/valid-pathyarn add @igorskyflyer/valid-pathnpm i @igorskyflyer/valid-path🤹🏼 API
function isValidPath(path: string, isFile = true): booleanReturns whether the given path can be a valid file/directory name on the host machine.
function isValidPathUnix(path: string, isFile = true): booleanReturns whether the given path can be a valid file/directory name on Unix and Unix-like OS'.
function isValidPathWin(path: string, isFile = true): booleanReturns whether the given path can be a valid file/directory name on Windows OS.
🗒️ Examples
import { isValidPathUnix, isValidPathWin, isValidPath } from '@igorskyflyer/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 false
console.log(isValidPathWin('hello/world.js', true)) // prints false
console.log(isValidPathWin('hello/world', false)) // prints true
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)
// so no need for separate testing📝 Changelog
📑 The changelog is available here, CHANGELOG.md.
🪪 License
Licensed under the MIT license which is available here, MIT license.
💖 Support
🧬 Related
🎍 Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). 🧬
🍃 Provides ways of checking whether a path is a legacy Windows device. 💾
🧰 Provides ways of testing whether a given value can be a valid file/directory name. 🏜
@igorskyflyer/registry-apppaths
🪀 A Node.js module for reading the AppPaths registry key on Windows. Useful for retrieving applications that can be launched from the command prompt. 🗃
🕶️ Reads a JSON file into a Map. 🌻
👨🏻💻 Author
Created by Igor Dimitrijević (@igorskyflyer).
