Wondering what’s next for npm?Check out our public roadmap! »

file-urlTypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

file-url Build Status

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

Install

$ npm install file-url

Usage

const fileUrl = require('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

License

MIT © Sindre Sorhus

Install

npm i file-url

DownloadsWeekly Downloads

108,538

Version

3.0.0

License

MIT

Unpacked Size

4.15 kB

Total Files

5

Last publish

Collaborators

  • avatar