1 | # contains-path [![NPM version](https://img.shields.io/npm/v/contains-path.svg?style=flat)](https://www.npmjs.com/package/contains-path) [![NPM monthly downloads](https://img.shields.io/npm/dm/contains-path.svg?style=flat)](https://npmjs.org/package/contains-path) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/contains-path.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/contains-path) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/contains-path.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/contains-path)
|
2 |
|
3 | > Return true if a file path contains the given path.
|
4 |
|
5 | ## Install
|
6 |
|
7 | Install with [npm](https://www.npmjs.com/):
|
8 |
|
9 | ```sh
|
10 | $ npm install --save contains-path
|
11 | ```
|
12 |
|
13 | Install with [yarn](https://yarnpkg.com):
|
14 |
|
15 | ```sh
|
16 | $ yarn add contains-path
|
17 | ```
|
18 |
|
19 | ## HEADS UP!
|
20 |
|
21 | As of v1.0.0, this library no longer uses regex for matching. Please do not hesitate to [report any issues or regressiosn](../../issues/new).
|
22 |
|
23 | ## Usage
|
24 |
|
25 | ```js
|
26 | var containsPath = require('contains-path');
|
27 |
|
28 | containsPath('foo/bar', 'foo'); //=> true
|
29 | containsPath('foo/bar', 'bar'); //=> true
|
30 | containsPath('foo/bar', 'qux'); //=> false
|
31 |
|
32 | // returns false for partial matches
|
33 | containsPath('foobar', 'foo'); //=> false
|
34 | containsPath('foo.bar', 'foo'); //=> false
|
35 | containsPath('foo.bar', 'bar'); //=> false
|
36 |
|
37 | // prefix with "./" to match from beginning of filepath
|
38 | containsPath('bar/foo', 'foo'); //=> true
|
39 | containsPath('bar/foo', './foo'); //=> false
|
40 | ```
|
41 |
|
42 | ## Negation
|
43 |
|
44 | Prefix with `!` to invert matching behavior:
|
45 |
|
46 | ```js
|
47 | containsPath('foo/bar', '!foo'); //=> false
|
48 | containsPath('foo/bar', '!qux'); //=> true
|
49 | ```
|
50 |
|
51 | ## Options
|
52 |
|
53 | ### options.nocase
|
54 |
|
55 | **Type**: `boolean`
|
56 |
|
57 | **Default**: `false`
|
58 |
|
59 | Disable case sensitivity.
|
60 |
|
61 | ```js
|
62 | containsPath('foo/bar', 'FOO'); //=> false
|
63 | containsPath('foo/bar', 'FOO', {nocase: true}); //=> true
|
64 | ```
|
65 |
|
66 | ### options.partialMatch
|
67 |
|
68 | **Type**: `boolean`
|
69 |
|
70 | **Default**: `false`
|
71 |
|
72 | Allow "partial" matches:
|
73 |
|
74 | ```js
|
75 | containsPath('foobar', 'foo'); //=> false
|
76 | containsPath('foobar', 'foo', {partialMatch: true}); //=> true
|
77 |
|
78 | containsPath('foo.bar', 'foo'); //=> false
|
79 | containsPath('foo.bar', 'foo', {partialMatch: true}); //=> true
|
80 | ```
|
81 |
|
82 | ## About
|
83 |
|
84 | ### Related projects
|
85 |
|
86 | * [ends-with](https://www.npmjs.com/package/ends-with): Returns `true` if the given `string` or `array` ends with `suffix` using strict equality for… [more](https://github.com/jonschlinkert/ends-with) | [homepage](https://github.com/jonschlinkert/ends-with "Returns `true` if the given `string` or `array` ends with `suffix` using strict equality for comparisons.")
|
87 | * [normalize-path](https://www.npmjs.com/package/normalize-path): Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a… [more](https://github.com/jonschlinkert/normalize-path) | [homepage](https://github.com/jonschlinkert/normalize-path "Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes unless disabled.")
|
88 | * [path-ends-with](https://www.npmjs.com/package/path-ends-with): Return `true` if a file path ends with the given string/suffix. | [homepage](https://github.com/jonschlinkert/path-ends-with "Return `true` if a file path ends with the given string/suffix.")
|
89 | * [unixify](https://www.npmjs.com/package/unixify): Convert Windows file paths to unix paths. | [homepage](https://github.com/jonschlinkert/unixify "Convert Windows file paths to unix paths.")
|
90 |
|
91 | ### Contributing
|
92 |
|
93 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
94 |
|
95 | ### Contributors
|
96 |
|
97 | | **Commits** | **Contributor** |
|
98 | | --- | --- |
|
99 | | 2 | [jonschlinkert](https://github.com/jonschlinkert) |
|
100 | | 1 | [germtb](https://github.com/germtb) |
|
101 |
|
102 | ### Building docs
|
103 |
|
104 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
105 |
|
106 | To generate the readme, run the following command:
|
107 |
|
108 | ```sh
|
109 | $ npm install -g verbose/verb#dev verb-generate-readme && verb
|
110 | ```
|
111 |
|
112 | ### Running tests
|
113 |
|
114 | 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:
|
115 |
|
116 | ```sh
|
117 | $ npm install && npm test
|
118 | ```
|
119 |
|
120 | ### Author
|
121 |
|
122 | **Jon Schlinkert**
|
123 |
|
124 | * [github/jonschlinkert](https://github.com/jonschlinkert)
|
125 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
126 |
|
127 | ### License
|
128 |
|
129 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
|
130 | Released under the [MIT License](LICENSE).
|
131 |
|
132 | ***
|
133 |
|
134 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 17, 2017._ |
\ | No newline at end of file |