protocolify
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -6,8 +6,8 @@ 'use strict'; | ||
module.exports = function (url) { | ||
if (typeof url !== 'string') { | ||
throw new TypeError(`Expected a string, got ${typeof url}`); | ||
module.exports = (urlOrFilePath, options) => { | ||
if (typeof urlOrFilePath !== 'string') { | ||
throw new TypeError(`Expected a \`string\`, got \`${typeof urlOrFilePath}\``); | ||
} | ||
return fs.existsSync(url) ? fileUrl(url) : prependHttp(url); | ||
return fs.existsSync(urlOrFilePath) ? fileUrl(urlOrFilePath) : prependHttp(urlOrFilePath, options); | ||
}; |
{ | ||
"name": "protocolify", | ||
"version": "2.0.0", | ||
"description": "Prepend `http://` to humanized URLs like `todomvc.com` and `file://` to file paths", | ||
"license": "MIT", | ||
"repository": "sindresorhus/protocolify", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"protocol", | ||
"scheme", | ||
"url", | ||
"uri", | ||
"prepend", | ||
"http", | ||
"file", | ||
"path" | ||
], | ||
"dependencies": { | ||
"file-url": "^2.0.0", | ||
"prepend-http": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "protocolify", | ||
"version": "3.0.0", | ||
"description": "Prepend `https://` to humanized URLs like `sindresorhus.com` and `file://` to file paths", | ||
"license": "MIT", | ||
"repository": "sindresorhus/protocolify", | ||
"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": [ | ||
"protocol", | ||
"scheme", | ||
"url", | ||
"uri", | ||
"prepend", | ||
"http", | ||
"file", | ||
"path" | ||
], | ||
"dependencies": { | ||
"file-url": "^3.0.0", | ||
"prepend-http": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
# protocolify [![Build Status](https://travis-ci.org/sindresorhus/protocolify.svg?branch=master)](https://travis-ci.org/sindresorhus/protocolify) | ||
> Prepend `http://` to humanized URLs like `todomvc.com` and `file://` to file paths | ||
> Prepend `https://` to humanized URLs like `sindresorhus.com` and `file://` to file paths | ||
@@ -11,3 +11,3 @@ Useful when you want to accept either a local file or URL as argument in your CLI app. | ||
``` | ||
$ npm install --save protocolify | ||
$ npm install protocolify | ||
``` | ||
@@ -21,12 +21,12 @@ | ||
protocolify('todomvc.com'); | ||
//=> 'http://todomvc.com' | ||
protocolify('sindresorhus.com'); | ||
//=> 'https://sindresorhus.com' | ||
protocolify('localhost'); | ||
protocolify('localhost', {https: false}); | ||
//=> 'http://localhost' | ||
protocolify('http://todomvc.com'); | ||
//=> 'http://todomvc.com' | ||
protocolify('https://sindresorhus.com'); | ||
//=> 'https://sindresorhus.com' | ||
// if it exists on disk it will be interpreted as a file and not an URL | ||
// If it exists on disk, it will be interpreted as a file and not a URL | ||
protocolify('index.js'); | ||
@@ -37,4 +37,26 @@ //=> 'file:///Users/sindresorhus/dev/protocolify/index.js' | ||
## API | ||
### protocolify(urlOrFilePath, [options]) | ||
#### urlOrFilePath | ||
Type: `string` | ||
URL to prepend `https://` or file path to prepend `file://`. | ||
#### options | ||
Type: `object` | ||
##### https | ||
Type: `boolean`<br> | ||
Default: `true` | ||
Prepend `https://` instead of `http://` to URLs. | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4272
5
39
60
0
3
+ Addedfile-url@3.0.0(transitive)
+ Addedprepend-http@3.0.1(transitive)
- Removedfile-url@2.0.2(transitive)
- Removedprepend-http@1.0.4(transitive)
Updatedfile-url@^3.0.0
Updatedprepend-http@^3.0.0