Socket
Socket
Sign inDemoInstall

file-url

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 3.0.0

index.d.ts

17

index.js
'use strict';
const path = require('path');
module.exports = (str, opts) => {
if (typeof str !== 'string') {
throw new TypeError(`Expected a string, got ${typeof str}`);
module.exports = (filePath, options) => {
if (typeof filePath !== 'string') {
throw new TypeError(`Expected a string, got ${typeof filePath}`);
}
opts = Object.assign({resolve: true}, opts);
options = {
resolve: true,
...options
};
let pathName = str;
let pathName = filePath;
if (opts.resolve) {
pathName = path.resolve(str);
if (options.resolve) {
pathName = path.resolve(filePath);
}

@@ -16,0 +19,0 @@

{
"name": "file-url",
"version": "2.0.2",
"description": "Convert a path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`",
"license": "MIT",
"repository": "sindresorhus/file-url",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"file",
"url",
"uri",
"path",
"scheme",
"slash"
],
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "file-url",
"version": "3.0.0",
"description": "Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`",
"license": "MIT",
"repository": "sindresorhus/file-url",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"file",
"url",
"uri",
"path",
"scheme",
"slash"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
# file-url [![Build Status](https://travis-ci.org/sindresorhus/file-url.svg?branch=master)](https://travis-ci.org/sindresorhus/file-url)
> Convert a path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
> Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`

@@ -9,3 +9,3 @@

```
$ npm install --save file-url
$ npm install file-url
```

@@ -25,3 +25,2 @@

// passing {resolve: false} will make it not call path.resolve() on the path
fileUrl('unicorn.jpg', {resolve: false});

@@ -31,3 +30,26 @@ //=> '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`<br>
Default: `true`
Passing `false` will make it not call `path.resolve()` on the path.
## Related

@@ -34,0 +56,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc