url-or-path

Convert between file URL and path.

Usage no npm install needed!

<script type="module">
  import urlOrPath from 'https://cdn.skypack.dev/url-or-path';
</script>

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.

toDirectory(urlOrPath)

Type: string | URL

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

isUrl(object)

Check if object is a URL instance of file:// string.

isUrlInstance(object)

Check if object is a URL instance.

isUrlString(object)

Check if object is a file:// string