2.2.1 ā€¢ Published 2 years ago

@igor.dvlpr/valid-path v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.

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,

npm i "@igor.dvlpr/valid-path"

API

function isValidPath(path: string, isFile = true): boolean

Returns whether the given path can be a valid file/directory name on the host machine.

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'.

function isValidPathWin(path: string, isFile = true): boolean

Returns whether the given path can be a valid file/directory name on Windows OS.

Examples

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 false

console.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)