Skip to content

Commit 2230a19

Browse files
committed
Require Node.js 8
Fixes #11
1 parent 26a5cf1 commit 2230a19

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ node_js:
33
- '12'
44
- '10'
55
- '8'
6-
- '6'

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
Check if a path is inside another path.
33
4+
Note that relative paths are resolved against `process.cwd()` to make them absolute.
5+
46
@example
57
```
68
import isPathInside = require('is-path-inside');

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const path = require('path');
3-
const pathIsInside = require('path-is-inside');
43

54
module.exports = (childPath, parentPath) => {
65
childPath = path.resolve(childPath);
@@ -15,5 +14,5 @@ module.exports = (childPath, parentPath) => {
1514
return false;
1615
}
1716

18-
return pathIsInside(childPath, parentPath);
17+
return childPath.startsWith(parentPath);
1918
};

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6"
13+
"node": ">=8"
1414
},
1515
"scripts": {
1616
"test": "xo && ava && tsd"
@@ -28,11 +28,8 @@
2828
"file",
2929
"resolve"
3030
],
31-
"dependencies": {
32-
"path-is-inside": "^1.0.2"
33-
},
3431
"devDependencies": {
35-
"ava": "^1.4.1",
32+
"ava": "^2.1.0",
3633
"tsd": "^0.7.2",
3734
"xo": "^0.24.0"
3835
}

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ isPathInside('/Users/sindresorhus/dev/unicorn', '/Users/sindresorhus');
2929
```
3030

3131

32+
## API
33+
34+
### isPathInside(childPath, parentPath)
35+
36+
Note that relative paths are resolved against `process.cwd()` to make them absolute.
37+
38+
#### childPath
39+
40+
Type: `string`
41+
42+
The path that should be inside `parentPath`.
43+
44+
#### parentPath
45+
46+
Type: `string`
47+
48+
The path that should contain `childPath`.
49+
50+
3251
---
3352

3453
<div align="center">

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import isPathInside from '.';
44

55
test('main', t => {
66
t.true(isPathInside('a/b/c', 'a/b'));
7+
t.true(isPathInside('a/b/c/', 'a/b/'));
8+
t.true(isPathInside('a/b/c', 'a/b/'));
9+
t.true(isPathInside('a/b/c/', 'a/b'));
710
t.true(isPathInside('/a/b/c', '/a/b'));
811
t.false(isPathInside('a/b', 'a/b'));
912
t.false(isPathInside('/a/b', '/a/b'));
13+
t.false(isPathInside('A/b/c', 'a/b'));
1014
});
1115

1216
test('win32', t => {
@@ -16,6 +20,10 @@ test('win32', t => {
1620
Object.defineProperty(process, 'platform', {value: 'win32'});
1721
Object.defineProperty(path, 'sep', {value: '\\'});
1822

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\\'));
1927
t.true(isPathInside('A\\b\\c', 'a\\b'));
2028
t.false(isPathInside('A\\b', 'a\\b'));
2129
t.true(isPathInside('c:\\a\\b\\c\\d', 'C:\\a\\b\\c'));

0 commit comments

Comments
 (0)