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 windows file path has invalid characters.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
$ npm install --save is-invalid-path
Usage
const isInvalid = require('is-invalid-path');
console.log(isInvalid());
console.log(isInvalid('<abc'));
console.log(isInvalid('>abc'));
console.log(isInvalid(':abc'));
console.log(isInvalid('"abc'));
console.log(isInvalid('|abc'));
console.log(isInvalid('?abc'));
console.log(isInvalid('*abc'));
console.log(isInvalid('foo/abc', { file: true }));
console.log(isInvalid('foo\\abc', { file: true }));
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Related projects
You might also be interested in these projects:
- is-glob: Returns
true
if the given string looks like a glob pattern or an extglob pattern… more | homepage - is-windows: Returns true if the platform is windows. UMD module, works with node.js, commonjs, browser, AMD… more | homepage
Author
Jon Schlinkert
License
Copyright © 2018, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on April 19, 2018.