We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 26a5cf1 commit 2230a19Copy full SHA for 2230a19
.travis.yml
@@ -3,4 +3,3 @@ node_js:
3
- '12'
4
- '10'
5
- '8'
6
- - '6'
index.d.ts
@@ -1,6 +1,8 @@
1
/**
2
Check if a path is inside another path.
+Note that relative paths are resolved against `process.cwd()` to make them absolute.
+
@example
7
```
8
import isPathInside = require('is-path-inside');
index.js
@@ -1,6 +1,5 @@
'use strict';
const path = require('path');
-const pathIsInside = require('path-is-inside');
module.exports = (childPath, parentPath) => {
childPath = path.resolve(childPath);
@@ -15,5 +14,5 @@ module.exports = (childPath, parentPath) => {
15
14
return false;
16
}
17
18
- return pathIsInside(childPath, parentPath);
+ return childPath.startsWith(parentPath);
19
};
package.json
@@ -10,7 +10,7 @@
10
"url": "sindresorhus.com"
11
},
12
"engines": {
13
- "node": ">=6"
+ "node": ">=8"
"scripts": {
"test": "xo && ava && tsd"
@@ -28,11 +28,8 @@
28
"file",
29
"resolve"
30
],
31
- "dependencies": {
32
- "path-is-inside": "^1.0.2"
33
- },
34
"devDependencies": {
35
- "ava": "^1.4.1",
+ "ava": "^2.1.0",
36
"tsd": "^0.7.2",
37
"xo": "^0.24.0"
38
readme.md
@@ -29,6 +29,25 @@ isPathInside('/Users/sindresorhus/dev/unicorn', '/Users/sindresorhus');
+## API
+### isPathInside(childPath, parentPath)
+#### childPath
39
40
+Type: `string`
41
42
+The path that should be inside `parentPath`.
43
44
+#### parentPath
45
46
47
48
+The path that should contain `childPath`.
49
50
51
---
52
53
<div align="center">
test.js
@@ -4,9 +4,13 @@ import isPathInside from '.';
test('main', t => {
t.true(isPathInside('a/b/c', 'a/b'));
+ t.true(isPathInside('a/b/c/', 'a/b/'));
+ t.true(isPathInside('a/b/c', 'a/b/'));
9
+ t.true(isPathInside('a/b/c/', 'a/b'));
t.true(isPathInside('/a/b/c', '/a/b'));
t.false(isPathInside('a/b', 'a/b'));
t.false(isPathInside('/a/b', '/a/b'));
+ t.false(isPathInside('A/b/c', 'a/b'));
});
test('win32', t => {
@@ -16,6 +20,10 @@ test('win32', t => {
20
Object.defineProperty(process, 'platform', {value: 'win32'});
21
Object.defineProperty(path, 'sep', {value: '\\'});
22
23
+ t.true(isPathInside('a\\b\\c', 'a\\b'));
24
+ t.true(isPathInside('a\\b\\c\\', 'a\\b'));
25
+ t.true(isPathInside('a\\b\\c', 'a\\b\\'));
26
+ t.true(isPathInside('a\\b\\c\\', 'a\\b\\'));
27
t.true(isPathInside('A\\b\\c', 'a\\b'));
t.false(isPathInside('A\\b', 'a\\b'));
t.true(isPathInside('c:\\a\\b\\c\\d', 'C:\\a\\b\\c'));
0 commit comments