What is contains-path?
The contains-path npm package is used to determine if a given path is inside another path. It is a simple utility that can be used to check if a file or directory is contained within another directory, which can be useful for ensuring proper file structure, security checks, and more.
What are contains-path's main functionalities?
Check if a path contains another path
This feature allows you to check if one path is contained within another. It returns true if the first path is inside the second path, otherwise false.
const containsPath = require('contains-path');
console.log(containsPath('/a/b/c', '/a/b')); // true
console.log(containsPath('/a/b/c', '/x/y')); // false
Other packages similar to contains-path
path-is-inside
This package provides similar functionality to contains-path. It allows you to check if one path is inside another path. The API might differ slightly, but the core functionality is the same.
is-path-inside
Another package that checks if a path is inside another path. It compares to contains-path in terms of functionality but may have different implementation details or additional features.
contains-path
Return true if a file path contains the given path.
Install
Install with npm
$ npm i contains-path --save
Usage
var contains = require('contains-path');
true
All of the following return true
:
containsPath('./a/b/c', 'a');
containsPath('./a/b/c', 'a/b');
containsPath('./b/a/b/c', 'a/b');
containsPath('/a/b/c', '/a/b');
containsPath('/a/b/c', 'a/b');
containsPath('a', 'a');
containsPath('a/b/c', 'a');
false
All of the following return false
:
containsPath('abc', 'a');
containsPath('abc', 'a.md');
containsPath('./b/a/b/c', './a/b');
containsPath('./b/a/b/c', './a');
containsPath('./b/a/b/c', '/a/b');
containsPath('/b/a/b/c', '/a/b');
Related projects
- ends-with: Returns
true
if the given string
or array
ends with suffix
using strict equality for… more - is-absolute: Return true if a file path is absolute.
- is-relative: Returns
true
if the path appears to be relative. - path-ends-with: Return
true
if a file path ends with the given string/suffix. - path-segments: Get n specific segments of a file path, e.g. first 2, last 3, etc.
- parse-filepath: Parse a filepath into an object, yielding predictable results for basename and extname.
Running 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 © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on July 07, 2015.