Comparing version 3.0.0 to 4.0.0
@@ -1,10 +0,8 @@ | ||
declare namespace fileUrl { | ||
interface Options { | ||
/** | ||
Passing `false` will make it not call `path.resolve()` on the path. | ||
export interface Options { | ||
/** | ||
Passing `false` will make it not call `path.resolve()` on the path. | ||
@default true | ||
*/ | ||
readonly resolve?: boolean; | ||
} | ||
@default true | ||
*/ | ||
readonly resolve?: boolean; | ||
} | ||
@@ -20,3 +18,3 @@ | ||
``` | ||
import fileUrl = require('file-url'); | ||
import fileUrl from 'file-url'; | ||
@@ -33,4 +31,2 @@ fileUrl('unicorn.jpg'); | ||
*/ | ||
declare function fileUrl(filePath: string, options?: fileUrl.Options): string; | ||
export = fileUrl; | ||
export default function fileUrl(filePath: string, options?: Options): string; |
19
index.js
@@ -1,5 +0,4 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
import path from 'path'; | ||
module.exports = (filePath, options) => { | ||
export default function fileUrl(filePath, options = {}) { | ||
if (typeof filePath !== 'string') { | ||
@@ -9,10 +8,6 @@ throw new TypeError(`Expected a string, got ${typeof filePath}`); | ||
options = { | ||
resolve: true, | ||
...options | ||
}; | ||
const {resolve = true} = options; | ||
let pathName = filePath; | ||
if (options.resolve) { | ||
if (resolve) { | ||
pathName = path.resolve(filePath); | ||
@@ -23,3 +18,3 @@ } | ||
// Windows drive letter must be prefixed with a slash | ||
// Windows drive letter must be prefixed with a slash. | ||
if (pathName[0] !== '/') { | ||
@@ -29,5 +24,5 @@ pathName = `/${pathName}`; | ||
// Escape required characters for path components | ||
// Escape required characters for path components. | ||
// See: https://tools.ietf.org/html/rfc3986#section-3.3 | ||
return encodeURI(`file://${pathName}`).replace(/[?#]/g, encodeURIComponent); | ||
}; | ||
} |
{ | ||
"name": "file-url", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/file-url", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -31,6 +34,6 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,6 +0,5 @@ | ||
# file-url [![Build Status](https://travis-ci.org/sindresorhus/file-url.svg?branch=master)](https://travis-ci.org/sindresorhus/file-url) | ||
# file-url | ||
> Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg` | ||
## Install | ||
@@ -12,7 +11,6 @@ | ||
## Usage | ||
```js | ||
const fileUrl = require('file-url'); | ||
import fileUrl from 'file-url'; | ||
@@ -31,3 +29,3 @@ fileUrl('unicorn.jpg'); | ||
### fileUrl(filePath, [options]) | ||
### fileUrl(filePath, options?) | ||
@@ -44,7 +42,7 @@ Returns the `filePath` converted to a file URL. | ||
Type: `Object` | ||
Type: `object` | ||
##### resolve | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -54,10 +52,4 @@ | ||
## Related | ||
- [file-url-cli](https://github.com/sindresorhus/file-url-cli) - CLI for this module | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
3989
42
52