# url-or-path

> Convert between file URL and path.

Latest version **2.7.1** (published 2026-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install url-or-path
pnpm add url-or-path
yarn add url-or-path
bun add url-or-path
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.7.1 |
| Published | 2026-06-12 |
| First published | 2021-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | fisker Cheung |
| Maintainers | fisker |

## Links

- npm: https://www.npmjs.com/package/url-or-path
- Repository: https://github.com/fisker/url-or-path
- Homepage: https://github.com/fisker/url-or-path#readme
- Issues: https://github.com/fisker/url-or-path/issues
- Funding: https://github.com/fisker/url-or-path?sponsor=1
- npm.io page: https://npm.io/package/url-or-path

## Recent versions

- 2.7.1 (latest) — 2026-06-12
- 2.6.1 — 2025-04-28
- 2.6.0 — 2025-04-28
- 2.5.0 — 2025-04-27
- 2.3.2 — 2024-10-30
- 2.3.1 — 2024-10-29
- 2.3.0 — 2023-11-19
- 2.2.0 — 2023-11-17
- 2.1.0 — 2022-02-11
- 2.0.0 — 2022-02-11
- 1.1.0 — 2022-02-08
- 1.0.4 — 2022-01-14
- 1.0.2 — 2022-01-12
- 1.0.1 — 2021-12-23
- 1.0.0 — 2021-08-25
- … 3 more at https://npm.io/package/url-or-path/versions

## README

# url-or-path

[![Build Status][github_actions_badge]][github_actions_link]
[![Coverage][coveralls_badge]][coveralls_link]
[![Npm Version][package_version_badge]][package_link]
[![MIT License][license_badge]][license_link]

[github_actions_badge]: https://img.shields.io/github/actions/workflow/status/fisker/url-or-path/continuous-integration.yml?barnach=main&style=flat-square
[github_actions_link]: https://github.com/fisker/url-or-path/actions?query=branch%3Amain
[coveralls_badge]: https://img.shields.io/coveralls/github/fisker/url-or-path/main?style=flat-square
[coveralls_link]: https://coveralls.io/github/fisker/url-or-path?branch=main
[license_badge]: https://img.shields.io/npm/l/prettier-format.svg?style=flat-square
[license_link]: https://github.com/fisker/url-or-path/blob/main/license
[package_version_badge]: https://img.shields.io/npm/v/url-or-path.svg?style=flat-square
[package_link]: https://www.npmjs.com/package/url-or-path

> Convert between file URL and path.

## Install

```bash
yarn add url-or-path
```

## Usage

```js
import {toUrl, toPath} from 'url-or-path'

console.log(toUrl(urlOrPath))
//=> URL {/* ... */}

console.log(toPath(urlOrPath))
//=> 'path/to/file'
```

## API

### `toUrl(urlOrPath)`(alias `toURL`)

Type: `string | URL`

Returns a [`URL`](https://nodejs.org/dist/latest-v16.x/docs/api/url.html#url_class_url) object of given URL or path string.

### `toPath(urlOrPath)`

Type: `string | URL`

Returns path string of given URL or path string.

### `toAbsolute(urlOrPath)`

Type: `string | URL`

Returns absolute path string of given URL or path string.

### `toDirectory(urlOrPath)`

Type: `string | URL`

Same as `toUrl`, but the result URL always ends with `/`.

### `isUrl(value)`(alias `isURL`)

Check if `value` is a `URL` instance or a string starts with `file://`.

### `isUrlInstance(value)`(alias `isURLInstance`)

Check if `value` is a `URL` instance.

### `isUrlString(value)`(alias `isURLString`)

Check if `value` is a string starts with `file://`.

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