Skip to content

Convert a file path to a file URL: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`

License

Notifications You must be signed in to change notification settings

timothytripp/file-url

 
 

Repository files navigation

file-url

Convert a file path to a file url: unicorn.jpgfile:///Users/sindresorhus/unicorn.jpg

Install

$ npm install file-url

Usage

import fileUrl from 'file-url';

fileUrl('unicorn.jpg');
//=> 'file:///Users/sindresorhus/dev/file-url/unicorn.jpg'

fileUrl('/Users/pony/pics/unicorn.jpg');
//=> 'file:///Users/pony/pics/unicorn.jpg'

fileUrl('unicorn.jpg', {resolve: false});
//=> 'file:///unicorn.jpg'

API

fileUrl(filePath, options?)

Returns the filePath converted to a file URL.

filePath

Type: string

File path to convert.

options

Type: object

resolve

Type: boolean
Default: true

Passing false will make it not call path.resolve() on the path.

Related

About

Convert a file path to a file URL: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 88.4%
  • TypeScript 11.6%