# path-is-inside

> Tests whether one path is inside another path

Latest version **1.0.2** (published 2016-09-10) · (WTFPL OR MIT) license · 0 weekly downloads

## Install

```sh
npm install path-is-inside
pnpm add path-is-inside
yarn add path-is-inside
bun add path-is-inside
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-09-10 |
| First published | 2013-12-14 |
| Weekly downloads | 0 |
| License | (WTFPL OR MIT) |
| TypeScript types | separate (@types/path-is-inside) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | Domenic Denicola |
| Maintainers | domenic |
| Keywords | path, directory, folder, inside, relative |

## Links

- npm: https://www.npmjs.com/package/path-is-inside
- Repository: https://github.com/domenic/path-is-inside
- Homepage: https://github.com/domenic/path-is-inside#readme
- Issues: https://github.com/domenic/path-is-inside/issues
- npm.io page: https://npm.io/package/path-is-inside

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-09-10
- 1.0.1 — 2014-03-01
- 1.0.0 — 2013-12-14

## README

# Is This Path Inside This Other Path?

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.

The **path-is-inside** package will give you a robust, cross-platform way of detecting whether a given path is inside another path.

## Usage

Pretty simple. First the path being tested; then the potential parent. Like so:

```js
var pathIsInside = require("path-is-inside");

pathIsInside("/x/y/z", "/x/y") // true
pathIsInside("/x/y", "/x/y/z") // false
```

Paths are considered to be inside themselves:

```js
pathIsInside("/x/y", "/x/y"); // true
```

## OS-Specific Behavior

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.

In practice, this means:

```js
// On Windows

pathIsInside("C:\\X\\Y\\Z", "C:\\x\\y") // true

// On *-nix, including Mac OS X

pathIsInside("/X/Y/Z", "/x/y") // false
```

[isaacs/npm#4214]: https://github.com/isaacs/npm/pull/4214
[isaacs/npm#4313]: https://github.com/isaacs/npm/issues/4313

---
_Source: https://npm.io/package/path-is-inside · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
