├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── appveyor.yml ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - iojs 9 | - '7' 10 | - '6' 11 | - '5' 12 | - '4' 13 | - '0.12' 14 | - '0.10' 15 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## HEADS UP! 2 | 3 | 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). 4 | 5 | ## Usage 6 | 7 | ```js 8 | var containsPath = require('{%= name %}'); 9 | 10 | containsPath('foo/bar', 'foo'); //=> true 11 | containsPath('foo/bar', 'bar'); //=> true 12 | containsPath('foo/bar', 'qux'); //=> false 13 | 14 | // returns false for partial matches 15 | containsPath('foobar', 'foo'); //=> false 16 | containsPath('foo.bar', 'foo'); //=> false 17 | containsPath('foo.bar', 'bar'); //=> false 18 | 19 | // prefix with "./" to match from beginning of filepath 20 | containsPath('bar/foo', 'foo'); //=> true 21 | containsPath('bar/foo', './foo'); //=> false 22 | ``` 23 | 24 | ## Negation 25 | 26 | Prefix with `!` to invert matching behavior: 27 | 28 | ```js 29 | containsPath('foo/bar', '!foo'); //=> false 30 | containsPath('foo/bar', '!qux'); //=> true 31 | ``` 32 | 33 | ## Options 34 | 35 | ### options.nocase 36 | 37 | 38 | **Type**: `boolean` 39 | 40 | **Default**: `false` 41 | 42 | Disable case sensitivity. 43 | 44 | ```js 45 | containsPath('foo/bar', 'FOO'); //=> false 46 | containsPath('foo/bar', 'FOO', {nocase: true}); //=> true 47 | ``` 48 | 49 | ### options.partialMatch 50 | 51 | **Type**: `boolean` 52 | 53 | **Default**: `false` 54 | 55 | Allow "partial" matches: 56 | 57 | ```js 58 | containsPath('foobar', 'foo'); //=> false 59 | containsPath('foobar', 'foo', {partialMatch: true}); //=> true 60 | 61 | containsPath('foo.bar', 'foo'); //=> false 62 | containsPath('foo.bar', 'foo', {partialMatch: true}); //=> true 63 | ``` 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, 2017, Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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._ -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Test against this version of Node.js 2 | environment: 3 | matrix: 4 | # node.js 5 | - nodejs_version: "7.0" 6 | - nodejs_version: "6.0" 7 | - nodejs_version: "5.0" 8 | - nodejs_version: "4.0" 9 | - nodejs_version: "0.12" 10 | - nodejs_version: "0.10" 11 | 12 | # Install scripts. (runs after repo cloning) 13 | install: 14 | # Get the latest stable version of Node.js or io.js 15 | - ps: Install-Product node $env:nodejs_version 16 | # install modules 17 | - npm install 18 | 19 | # Post-install test scripts. 20 | test_script: 21 | # Output useful info for debugging. 22 | - node --version 23 | - npm --version 24 | # run tests 25 | - npm test 26 | 27 | # Don't actually build. 28 | build: off 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var startsWith = require('path-starts-with'); 4 | var normalizePath = require('normalize-path'); 5 | 6 | function containsPath(filepath, substr, options) { 7 | if (typeof filepath !== 'string') { 8 | throw new TypeError('expected filepath to be a string'); 9 | } 10 | if (typeof substr !== 'string') { 11 | throw new TypeError('expected substring to be a string'); 12 | } 13 | 14 | if (substr === '') { 15 | return false; 16 | } 17 | 18 | // return true if the given strings are an exact match 19 | if (filepath === substr) { 20 | return true; 21 | } 22 | 23 | if (substr.charAt(0) === '!') { 24 | return !containsPath(filepath, substr.slice(1), options); 25 | } 26 | 27 | options = options || {}; 28 | if (options.nocase === true) { 29 | filepath = filepath.toLowerCase(); 30 | substr = substr.toLowerCase(); 31 | } 32 | 33 | var fp = normalize(filepath, false); 34 | var str = normalize(substr, false); 35 | 36 | // return false if the normalized substring is only a slash 37 | if (str === '/') { 38 | return false; 39 | } 40 | 41 | // if normalized strings are equal, return true 42 | if (fp === str) { 43 | return true; 44 | } 45 | 46 | if (startsWith(filepath, substr, options)) { 47 | return true; 48 | } 49 | 50 | var idx = fp.indexOf(str); 51 | var prefix = substr.slice(0, 2); 52 | 53 | // if the original substring started with "./", we'll 54 | // assume it should match from the beginning of the string 55 | if (prefix === './' || prefix === '.\\') { 56 | return idx === 0; 57 | } 58 | 59 | if (idx !== -1) { 60 | if (options.partialMatch === true) { 61 | return true; 62 | } 63 | 64 | // if the first character in the substring is a 65 | // dot or slash, we can consider this a match 66 | var ch = str.charAt(0); 67 | if (ch === '/') { 68 | return true; 69 | } 70 | 71 | // since partial matches were not enabled, we only consider 72 | // this a match if the next character is a dot or a slash 73 | var before = fp.charAt(idx - 1); 74 | var after = fp.charAt(idx + str.length); 75 | return (before === '' || before === '/') 76 | && (after === '' || after === '/'); 77 | } 78 | 79 | return false; 80 | } 81 | 82 | /** 83 | * Normalize paths 84 | */ 85 | 86 | function normalize(str) { 87 | str = normalizePath(str, false); 88 | if (str.slice(0, 2) === './') { 89 | str = str.slice(2); 90 | } 91 | return str; 92 | } 93 | 94 | /** 95 | * Expose `containsPath` 96 | */ 97 | 98 | module.exports = containsPath; 99 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contains-path", 3 | "description": "Return true if a file path contains the given path.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/jonschlinkert/contains-path", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Gerard (https://github.com/germtb)", 9 | "Jon Schlinkert (http://twitter.com/jonschlinkert)" 10 | ], 11 | "repository": "jonschlinkert/contains-path", 12 | "bugs": { 13 | "url": "https://github.com/jonschlinkert/contains-path/issues" 14 | }, 15 | "license": "MIT", 16 | "files": [ 17 | "index.js" 18 | ], 19 | "main": "index.js", 20 | "engines": { 21 | "node": ">=0.10.0" 22 | }, 23 | "scripts": { 24 | "test": "mocha" 25 | }, 26 | "dependencies": { 27 | "normalize-path": "^2.1.1", 28 | "path-starts-with": "^1.0.0" 29 | }, 30 | "devDependencies": { 31 | "gulp-format-md": "^0.1.12", 32 | "mocha": "^3.2.0" 33 | }, 34 | "keywords": [ 35 | "contains", 36 | "directory", 37 | "dirname", 38 | "exec", 39 | "ext", 40 | "extname", 41 | "file", 42 | "filepath", 43 | "fp", 44 | "has", 45 | "match", 46 | "matches", 47 | "path", 48 | "regex", 49 | "test" 50 | ], 51 | "verb": { 52 | "related": { 53 | "list": [ 54 | "ends-with", 55 | "normalize-path", 56 | "path-ends-with", 57 | "unixify" 58 | ] 59 | }, 60 | "toc": false, 61 | "layout": "default", 62 | "tasks": [ 63 | "readme" 64 | ], 65 | "plugins": [ 66 | "gulp-format-md" 67 | ], 68 | "lint": { 69 | "reflinks": true 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var containsPath = require('./'); 6 | 7 | describe('containsPath', function() { 8 | it('should throw an error when invalid args are passed', function() { 9 | assert.throws(function() { 10 | containsPath(); 11 | }, /expected/); 12 | 13 | assert.throws(function() { 14 | containsPath({}); 15 | }, /expected/); 16 | 17 | assert.throws(function() { 18 | containsPath([]); 19 | }, /expected/); 20 | 21 | assert.throws(function() { 22 | containsPath(null); 23 | }, /expected/); 24 | }); 25 | 26 | it('should be false when the value is an empty string', function() { 27 | assert(!containsPath('foo', '')); 28 | }); 29 | 30 | it('should be false when the value is only slashes', function() { 31 | assert(!containsPath('/foo', '/')); 32 | assert(!containsPath('/foo', '//')); 33 | assert(!containsPath('/foo', '///')); 34 | assert(!containsPath('foo/', '/')); 35 | assert(!containsPath('foo/', '//')); 36 | assert(!containsPath('foo/', '///')); 37 | assert(!containsPath('/foo/', '/')); 38 | assert(!containsPath('/foo/', '//')); 39 | assert(!containsPath('/foo/', '///')); 40 | 41 | assert(!containsPath('\\foo', '\\')); 42 | assert(!containsPath('\\foo', '\\\\')); 43 | assert(!containsPath('\\foo', '\\\\\\')); 44 | assert(!containsPath('foo\\', '\\')); 45 | assert(!containsPath('foo\\', '\\\\')); 46 | assert(!containsPath('foo\\', '\\\\\\')); 47 | assert(!containsPath('\\foo\\', '\\')); 48 | assert(!containsPath('\\foo\\', '\\\\')); 49 | assert(!containsPath('\\foo\\', '\\\\\\')); 50 | }); 51 | 52 | it('should return true when a path contains another path', function() { 53 | assert(!containsPath('./bar/foo/bar/baz', './foo')); 54 | assert(!containsPath('./bar/foo/bar/baz', './foo/bar')); 55 | assert(!containsPath('abc', 'foo.md')); 56 | assert(containsPath('/foo/bar/baz', 'foo/bar')); 57 | assert(containsPath('aa/foo.md', 'foo.md')); 58 | assert(containsPath('foo', 'foo')); 59 | assert(containsPath('foo/bar/baz', 'foo')); 60 | 61 | // windows paths 62 | assert(!containsPath('.\\bar\\foo\\bar\\baz', './foo')); 63 | assert(!containsPath('.\\bar\\foo\\bar\\baz', './foo/bar')); 64 | assert(containsPath('\\foo\\bar\\baz', 'foo/bar')); 65 | assert(containsPath('aa\\foo.md', 'foo.md')); 66 | assert(containsPath('foo\\bar\\baz', 'foo')); 67 | 68 | assert(!containsPath('.\\bar\\foo\\bar\\baz', '.\\foo')); 69 | assert(!containsPath('.\\bar\\foo\\bar\\baz', '.\\foo\\bar')); 70 | assert(containsPath('\\foo\\bar\\baz', 'foo\\bar')); 71 | assert(containsPath('aa\\foo.md', 'foo.md')); 72 | assert(containsPath('foo\\bar\\baz', 'foo')); 73 | }); 74 | 75 | it('should work with windows drive letters', function() { 76 | assert(!containsPath('C:/foo/bar', 'C:/bar')); 77 | assert(containsPath('C:/foo/bar', 'C:/foo')); 78 | assert(containsPath('C:/foo/bar', 'foo/bar')); 79 | 80 | assert(!containsPath('C:\\foo\\bar', 'C:\\bar')); 81 | assert(containsPath('C:\\foo\\bar', 'C:\\foo')); 82 | assert(containsPath('C:\\foo\\bar', 'foo\\bar')); 83 | }); 84 | 85 | it('should match any path part when prefixed with "/"', function() { 86 | assert(!containsPath('./bar/baz/qux', '/bar')); 87 | assert(!containsPath('bar/baz/qux', '/bar')); 88 | assert(containsPath('./bar/foo/bar/baz', '/foo/bar')); 89 | assert(containsPath('/bar/baz/qux', '/bar')); 90 | assert(containsPath('/bar/foo/bar/baz', '/foo/bar')); 91 | assert(containsPath('/foo/bar/baz', '/foo/bar')); 92 | assert(containsPath('foo/bar/baz', '/baz')); 93 | 94 | assert(!containsPath('.\\bar\\baz\\qux', '\\bar')); 95 | assert(!containsPath('bar\\baz\\qux', '\\bar')); 96 | assert(containsPath('.\\bar\\foo\\bar\\baz', '\\foo\\bar')); 97 | assert(containsPath('\\bar\\baz\\qux', '\\bar')); 98 | assert(containsPath('\\bar\\foo\\bar\\baz', '\\foo\\bar')); 99 | assert(containsPath('\\foo\\bar\\baz', '\\foo\\bar')); 100 | assert(containsPath('foo\\bar\\baz', '\\baz')); 101 | }); 102 | 103 | it('should match from bos when starts with "./"', function() { 104 | assert(!containsPath('/bar/foo/bar/baz', './bar')); 105 | assert(containsPath('./bar/foo/bar/baz', './bar')); 106 | assert(containsPath('./bar/foo/bar/baz', 'foo/bar')); 107 | assert(containsPath('./foo/bar/baz', 'foo')); 108 | assert(containsPath('./foo/bar/baz', 'foo/bar')); 109 | assert(containsPath('bar/foo/bar/baz', './bar')); 110 | 111 | // windows paths 112 | assert(!containsPath('\\bar\\foo\\bar\\baz', '.\\bar')); 113 | assert(containsPath('.\\bar\\foo\\bar\\baz', '.\\bar')); 114 | assert(containsPath('.\\bar\\foo\\bar\\baz', 'foo\\bar')); 115 | assert(containsPath('.\\foo\\bar\\baz', 'foo')); 116 | assert(containsPath('.\\foo\\bar\\baz', 'foo\\bar')); 117 | assert(containsPath('bar\\foo\\bar\\baz', '.\\bar')); 118 | }); 119 | 120 | it('should be true when the path ends with a string', function() { 121 | assert(!containsPath('foo/bar.md/baz', '.md')); 122 | assert(containsPath('foo/.git/baz', '.git')); 123 | assert(containsPath('foo/bar/baz', 'bar/baz')); 124 | assert(containsPath('foo/bar/baz', 'baz')); 125 | assert(containsPath('foo/bar/baz.md', 'bar/baz.md')); 126 | assert(containsPath('foo/bar/baz.md', 'baz.md')); 127 | 128 | // windows paths 129 | assert(!containsPath('foo\\bar.md\\baz', '.md')); 130 | assert(containsPath('foo\\.git\\baz', '.git')); 131 | assert(containsPath('foo\\bar\\baz', 'bar\\baz')); 132 | assert(containsPath('foo\\bar\\baz', 'baz')); 133 | assert(containsPath('foo\\bar\\baz.md', 'bar\\baz.md')); 134 | assert(containsPath('foo\\bar\\baz.md', 'baz.md')); 135 | }); 136 | 137 | it('should return false for partial matches', function() { 138 | assert(!containsPath('abc', 'foo')); 139 | assert(!containsPath('aaa', 'foo')); 140 | assert(!containsPath('aaa.md', 'foo.md')); 141 | }); 142 | 143 | it('should be false when the path does not contain the string', function() { 144 | assert(!containsPath('foo/bar/baz.md', 'baz')); 145 | assert(!containsPath('foo\\bar\\baz.md', 'baz')); 146 | }); 147 | 148 | it('should be false when the string is a "partial" match', function() { 149 | assert(!containsPath('foo/bar/baz.md', '.md')); 150 | assert(!containsPath('foo/bar/baz.md', 'baz')); 151 | assert(!containsPath('foo/bar/baz.md', 'baz/')); 152 | assert(!containsPath('foo/bar/baz.md', 'md')); 153 | assert(!containsPath('foo/bar/baz.md', 'z.md')); 154 | assert(!containsPath('foo/bar/bazqux', 'qux')); 155 | 156 | // windows paths 157 | assert(!containsPath('foo\\bar\\baz.md', '.md')); 158 | assert(!containsPath('foo\\bar\\baz.md', 'baz')); 159 | assert(!containsPath('foo\\bar\\baz.md', 'baz\\')); 160 | assert(!containsPath('foo\\bar\\baz.md', 'md')); 161 | assert(!containsPath('foo\\bar\\baz.md', 'z.md')); 162 | assert(!containsPath('foo\\bar\\bazqux', 'qux')); 163 | }); 164 | }); 165 | --------------------------------------------------------------------------------