]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/path-is-inside/README.md
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / path-is-inside / README.md
1 # Is This Path Inside This Other Path?
2
3 It turns out this question isn't trivial to answer using Node's built-in path APIs. A naive `indexOf`-based solution will fail sometimes on Windows, which is case-insensitive (see e.g. [isaacs/npm#4214][]). You might then think to be clever with `path.resolve`, but you have to be careful to account for situations whether the paths have different drive letters, or else you'll cause bugs like [isaacs/npm#4313][]. And let's not even get started on trailing slashes.
4
5 The **path-is-inside** package will give you a robust, cross-platform way of detecting whether a given path is inside another path.
6
7 ## Usage
8
9 Pretty simple. First the path being tested; then the potential parent. Like so:
10
11 ```js
12 var pathIsInside = require("path-is-inside");
13
14 pathIsInside("/x/y/z", "/x/y") // true
15 pathIsInside("/x/y", "/x/y/z") // false
16 ```
17
18 ## OS-Specific Behavior
19
20 Like Node's built-in path module, path-is-inside treats all file paths on Windows as case-insensitive, whereas it treats all file paths on *-nix operating systems as case-sensitive. Keep this in mind especially when working on a Mac, where, despite Node's defaults, the OS usually treats paths case-insensitively.
21
22 In practice, this means:
23
24 ```js
25 // On Windows
26
27 pathIsInside("C:\\X\\Y\\Z", "C:\\x\\y") // true
28
29 // On *-nix, including Mac OS X
30
31 pathIsInside("/X/Y/Z", "/x/y") // false
32 ```
33
34 [isaacs/npm#4214]: https://github.com/isaacs/npm/pull/4214
35 [isaacs/npm#4313]: https://github.com/isaacs/npm/issues/4313