You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constvalidPath=require('validPath');constmyPath=validPath('string/to/check');if(myPath.valid){// ...}else{console.log(`Error in ${myPath.data.input}: ${myPath.error}`);}
If true, valid-path will accept drive letter in provided path and will add a note in notes array of returned object (Object.data.notes).
Drive letter can have single and doubled separator (C:/a/b or C://a/b). In case of doubled separator you do not need to set allowSepDuplications option to true: valid path will accept the duplication just for drive letter.
By default valid-path does not accept file and folder names that are forbidden in Windows: nul, prn, con, lpt[0-9], com[0-9]. Set to true to accept these names.
Default
Expects
false
boolean
Example
input
a/b/lpt3
a/b/lpt3
options
{ // default }
{ allowForbiddenWindowsNames: true }
output
{ valid: false, error: 'Input string contains file or folder name, that is forbidden in Windows (lpt3)', data: { input: 'a/b/lpt3', notes: [] } }
{ valid: true, error: null, data: { input: 'a/b/lpt3', notes: [ 'Input string contains file or folder name, that is forbidden in Windows (lpt3)' ] } }
options.allowFobiddenWindowsChars
By default valid-path does not accept characters in path items that are forbidden in Windows: /, \, <, >, :, ", *, ?, |. Set to true to accept these characters.
Default
Expects
false
boolean
Example
input
a/b:c/d
a/b:c/d
options
{ // default }
{ allowFobiddenWindowsChars: true }
output
{ valid: false, error: 'Input string contains characters, that are forbidden in Windows (b:c)', data: { input: 'a/b:c/d', notes: [] } }
{ valid: true, error: null, data: { input: 'a/b:c/d', notes: [ 'Input string contains characters, that are forbidden in Windows (b:c)' ] } }
options.allowForbiddenUnixChars
By default valid-path does not accept characters in path items that are forbidden in Unix: \0 (NULL byte), /. Set to true to accept these characters.
Default
Expects
false
boolean
Example
input
a/\0b/c
a/\0b/c
options
{ // default }
{ allowForbiddenUnixChars: true }
output
{ valid: false, error: 'Input string contains characters, that are forbidden in Unix (\x00b)', data: { input: 'a/\x00b/c', notes: [] } }
{ valid: true, error: null, data: { input: 'a/\x00b/c', notes: [ 'Input string contains characters, that are forbidden in Unix (\x00b)' ] } }
About
Returns an object, that tells if provided string is a valid path, or describes got problem.