file-url
Version:
Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
52 lines (30 loc) • 834 B
Markdown
> Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
```
$ npm install file-url
```
```js
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'
```
Returns the `filePath` converted to a file URL.
Type: `string`
File path to convert.
Type: `object`
Type: `boolean`\
Default: `true`
Passing `false` will make it not call `path.resolve()` on the path.
- [file-url-cli](https://github.com/sindresorhus/file-url-cli) - CLI for this module