url-or-path

Convert between file URL and path.

MIT 18 个版本
安装
npm install url-or-path
yarn add url-or-path
pnpm add url-or-path
bun add url-or-path
README

url-or-path

Build Status Coverage Npm Version MIT License

Convert between file URL and path.

Install

yarn add url-or-path

Usage

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 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://.

版本列表
2.7.1 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
0.0.2 2021-08-25
0.0.1 2021-08-25
0.0.0 2021-08-25