# parse-cwd

> Convert relative path or URL to full path

Latest version **1.1.2** (published 2025-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-cwd
pnpm add parse-cwd
yarn add parse-cwd
bun add parse-cwd
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2025-02-17 |
| First published | 2022-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | JacobLey |
| Maintainers | jacobley |
| Keywords | cwd, resolve, file path |

## Links

- npm: https://www.npmjs.com/package/parse-cwd
- Repository: https://github.com/JacobLey/leyman
- Homepage: https://github.com/JacobLey/leyman/tree/main/tools/parse-cwd#readme
- Issues: https://github.com/JacobLey/leyman/issues
- npm.io page: https://npm.io/package/parse-cwd

## 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.1.2 (latest) — 2025-02-17
- 1.0.8-dev.2f7534ef97b0381ef060f948856242887d7e8940b26a66b74bc8df2cfeef313a (dev) — 2022-08-15
- 1.1.1 — 2025-01-05
- 1.1.0 — 2024-12-31
- 1.0.13 — 2024-11-01
- 1.0.12 — 2024-10-26
- 1.0.11 — 2024-10-23
- 1.0.10 — 2024-08-08
- 1.0.9 — 2024-08-04
- 1.0.8 — 2022-08-15
- 1.0.8-dev.1e6fb2eb001cea38d49407180d13e11c4ed1c25c — 2022-08-15
- 1.0.8-dev.579b83c9a3ad3b58da7f9887c9bafcb6cef7ee59827e7c13c49b125f74dfc666 — 2022-08-14
- 1.0.8-dev.6d40ad53c428177f21d8b184fccd23db6500aa4c — 2022-08-14
- 1.0.7-dev.8a4e51c2ad335ee7b9d03789e7549ca44eb9093e67a162b9d21d9c0e5738deb7 — 2022-08-10
- 1.0.7-dev.6150c44a1e003315375046a34cb8cb25c1c54c47 — 2022-08-10
- … 34 more at https://npm.io/package/parse-cwd/versions

## README

<div style="text-align:center">

# >parse-cwd
Parse full current working directory from relative path or URL.

[![npm package](https://badge.fury.io/js/parse-cwd.svg)](https://www.npmjs.com/package/parse-cwd)
[![License](https://img.shields.io/npm/l/parse-cwd.svg)](https://github.com/JacobLey/leyman/blob/main/tools/parse-cwd/LICENSE)

</div>

## Contents
- [Introduction](#introduction)
- [Install](#install)
- [Example](#example)
- [Usage](#usage)
- [API](#api)
  - [parseCwd](#parsecwdcwd)

## Introduction

Parses the full path to current working directory.

Validates that directory actually exists.

## Install

```sh
npm i parse-cwd
```

## Example

```ts
import { parseCwd } from 'parse-cwd';

console.log(process.cwd()); // /path/to/cwd
console.log(import.meta.url); // file:///path/to/cwd/foo/bar/my-file.js

console.log(await parseCwd()); // /path/to/cwd
console.log(await parseCwd(process.cwd())); // /path/to/cwd
console.log(await parseCwd('foo/bar/my-file.js')); // /path/to/cwd/foo/bar
console.log(await parseCwd('./foo/bar/my-file.js')); // /path/to/cwd/foo/bar
console.log(await parseCwd(import.meta.url)); // /path/to/cwd/foo/bar
console.log(await parseCwd(new URL(import.meta.url))); // /path/to/cwd/foo/bar
console.log(await parseCwd({ cwd: 'foo/bar/my-file.js' })); // /path/to/cwd/foo/bar

// Error - Directory not found
await parseCwd('does/not/exist');
```

## Usage

`parse-cwd` is an ESM module. That means it _must_ be `import`ed. To load from a CJS module, use dynamic import `const { parseCwd } = await import('parse-cwd');`.

## API

### parseCwd(cwd)

- cwd
  - file path to resolve to URL
  - Type: `string` or `URL` or `null`
  - optional, defaults to `process.cwd()`
  - Optionally wrap as an object, e.g. `{ cwd: '/foo/bar' }`
    - Convenient for directly passing higher level `options` object

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