What is is-invalid-path?
The is-invalid-path npm package is a utility that helps determine if a given file path is invalid. It is useful for validating file paths in various environments and ensuring that paths conform to the expected format.
What are is-invalid-path's main functionalities?
Basic Path Validation
This feature allows you to check if a given path is invalid. The function returns true if the path is invalid and false if it is valid.
const isInvalidPath = require('is-invalid-path');
const path1 = 'C:\invalid|path';
const path2 = '/valid/path';
console.log(isInvalidPath(path1)); // true
console.log(isInvalidPath(path2)); // false
Custom Invalid Characters
This feature allows you to specify custom invalid characters for path validation. The function will check the path against these custom characters and return true if the path contains any of them.
const isInvalidPath = require('is-invalid-path');
const customInvalidChars = ['*', '?', '<', '>', '|'];
const path1 = 'C:\invalid*path';
const path2 = '/valid/path';
console.log(isInvalidPath(path1, customInvalidChars)); // true
console.log(isInvalidPath(path2, customInvalidChars)); // false
Other packages similar to is-invalid-path
valid-path
The valid-path package is another alternative that checks for the validity of file paths. It focuses on ensuring that paths do not contain invalid characters and are properly formatted. It is similar to is-invalid-path but may have different rules for what constitutes an invalid path.
is-invalid-path
Returns true if a file path has invalid characters.
Install with npm
npm i is-invalid-path --save
Usage
var isInvalid = require('is-invalid-path');
isInvalid('abc.js');
isInvalid('abc/def/ghi.js');
isInvalid('foo.js');
isInvalid();
isInvalid(null);
isInvalid('!foo.js');
isInvalid('*.js');
isInvalid('**/abc.js');
isInvalid('abc/*.js');
isInvalid('abc/(aaa|bbb).js');
isInvalid('abc/[a-z].js');
isInvalid('abc/{a,b}.js');
isInvalid('abc/?.js');
Related
- is-glob: Returns
true
if the given string looks like a glob pattern. - is-git-url: Regex to validate that a URL is a git url.
- micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… more
- parse-glob: Parse a glob pattern into an object of tokens.
Run tests
Install dev dependencies:
npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on May 06, 2015.