# is-subdir

> Return whether a directory is a subdirectory of another directory

Latest version **2.0.0** (published 2026-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-subdir
pnpm add is-subdir
yarn add is-subdir
bun add is-subdir
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-03-11 |
| First published | 2017-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=22.13 |
| Dependencies | 1 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 104 |
| Author | Zoltan Kochan |
| Maintainers | zkochan |
| Keywords | subdirectory, subfolder, subpath, directory, folder, path |

## Links

- npm: https://www.npmjs.com/package/is-subdir
- Repository: https://github.com/zkochan/packages/tree/main/is-subdir
- Homepage: https://github.com/zkochan/packages/tree/main/is-subdir#readme
- npm.io page: https://npm.io/package/is-subdir

## Dependencies (1)

- [better-path-resolve](https://npm.io/package/better-path-resolve.md) ^2.0.0

## 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

- 2.0.0 (latest) — 2026-03-11
- 1.1.1 (next) — 2019-10-06
- 1.2.0 — 2021-01-05
- 1.0.3 — 2019-03-01
- 1.0.2 — 2017-09-30
- 1.0.1 — 2017-07-16
- 1.0.0 — 2017-04-14

## README

# is-subdir

> Return whether a directory is a subdirectory of another directory

<!--@shields('npm')-->
[![npm version](https://img.shields.io/npm/v/is-subdir.svg)](https://www.npmjs.com/package/is-subdir)
<!--/@-->

Cross-platform. Works correctly on Windows, where directory paths can start with disk drive letters in different casings. Like `c:\foo` and `C:\foo\bar`.

Returns `true` when the directories match. The `isSubdir.strict()` variant only returns true if the second parameter is a strict subdir of the first and not the same.

## Installation

```sh
<npm|yarn|pnpm> add is-subdir
```

## Usage

```js
'use strict'
const path = require('path')
const isSubdir = require('is-subdir')

console.log(isSubdir(process.cwd(), path.resolve('node_modules')))
//> true
console.log(isSubdir.strict('node_modules/tape', '../tape'))
//> false
```

## API

### `isSubdir(parentDir, subdir): boolean`
### `isSubdir.strict(parentDir, subdir): boolean`

## License

[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io)

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