update
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-19 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
||||
Copyright (c) 2015-22 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
+223
-34
@@ -1,16 +1,54 @@
|
||||
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# parse-url
|
||||
|
||||
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://travis-ci.org/IonicaBizau/parse-url/) [](https://www.npmjs.com/package/parse-url) [](https://www.npmjs.com/package/parse-url) [](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
||||
|
||||
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
> An advanced url parser supporting git urls too.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
For low-level path parsing, check out [`parse-path`](https://github.com/IonicaBizau/parse-path). This very module is designed to parse urls. By default the urls are normalized.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :cloud: Installation
|
||||
|
||||
```sh
|
||||
@@ -22,6 +60,17 @@ yarn add parse-url
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :clipboard: Example
|
||||
|
||||
|
||||
@@ -78,17 +127,28 @@ console.log(parseUrl("git@github.com:IonicaBizau/git-stats.git", false))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :question: Get Help
|
||||
|
||||
There are few ways to get help:
|
||||
|
||||
|
||||
|
||||
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
||||
2. For bug reports and feature requests, open issues. :bug:
|
||||
|
||||
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :memo: Documentation
|
||||
|
||||
|
||||
@@ -121,12 +181,22 @@ Parses the input url.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :yum: How to contribute
|
||||
Have an idea? Found a bug? See [how to contribute][contributing].
|
||||
|
||||
|
||||
## :sparkling_heart: Support my projects
|
||||
|
||||
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
|
||||
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
|
||||
|
||||
@@ -145,52 +215,171 @@ However, if you get some profit from this or just want to encourage me to contin
|
||||
Thanks! :heart:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :dizzy: Where is this library used?
|
||||
If you are using this library in one of your projects, add it in this list. :sparkles:
|
||||
|
||||
- `git-up`
|
||||
- `lien`
|
||||
- `stun`
|
||||
- `@open-wa/wa-automate`
|
||||
- `kakapo`
|
||||
- `parse-db-uri`
|
||||
- `url-local`
|
||||
- `fuge-runner`
|
||||
- `build-plugin-ssr`
|
||||
- `rucksack`
|
||||
- `egg-muc-custom-loader`
|
||||
- `hologit`
|
||||
- `@enkeledi/react-native-week-month-date-picker`
|
||||
- `normalize-ssh`
|
||||
- `robots-agent`
|
||||
- `warp-api`
|
||||
- `normalize-id`
|
||||
- `xl-git-up`
|
||||
- `warp-server`
|
||||
- `@hemith/react-native-tnk`
|
||||
- `@kriblet/wa-automate`
|
||||
- `@notnuzzel/crawl`
|
||||
- `native-kakao-login`
|
||||
- `begg`
|
||||
- `gitlab-backup-util-harduino`
|
||||
- `miguelcostero-ng2-toasty`
|
||||
- `npm_one_1_2_3`
|
||||
- `bilibili2local`
|
||||
- `react-native-arunmeena1987`
|
||||
- `react-native-biometric-authenticate`
|
||||
- `react-native-contact-list`
|
||||
- `react-native-is7`
|
||||
- `react-native-payu-payment-testing`
|
||||
- `react-native-kakao-maps`
|
||||
- `react-native-my-first-try-arun-ramya`
|
||||
- `react-native-ytximkit`
|
||||
- `rn-adyen-dropin`
|
||||
- `@dataparty/api`
|
||||
- `@datalogic/react-native-datalogic-module`
|
||||
- `@corelmax/react-native-my2c2p-sdk`
|
||||
- `@felipesimmi/react-native-datalogic-module`
|
||||
- `@hawkingnetwork/react-native-tab-view`
|
||||
- `@jprustv/sulla-hotfix`
|
||||
- `@mergulhao/wa-automate`
|
||||
- `react-native-cplus`
|
||||
- `npm_qwerty`
|
||||
- `native-apple-login`
|
||||
- `drowl-base-theme-iconset`
|
||||
- `cli-live-tutorial`
|
||||
- `react-native-arunjeyam1987`
|
||||
- `verify-aws-sns-signature`
|
||||
- `vue-cli-plugin-ice-builder`
|
||||
- `vrt-cli`
|
||||
- `ssh-host-manager`
|
||||
- `soajs.repositories`
|
||||
- `react-native-bubble-chart`
|
||||
- `react-native-flyy`
|
||||
- `native-zip`
|
||||
- `graphmilker`
|
||||
- `tumblr-text`
|
||||
- `@apardellass/react-native-audio-stream`
|
||||
- `@geeky-apo/react-native-advanced-clipboard`
|
||||
- `@hsui/plugin-wss`
|
||||
- `blitzzz`
|
||||
- `candlelabssdk`
|
||||
- `@roshub/api`
|
||||
- `@saad27/react-native-bottom-tab-tour`
|
||||
- `generator-bootstrap-boilerplate-template`
|
||||
- `homebridge-pushcutter`
|
||||
- `react-feedback-sdk`
|
||||
- `loast`
|
||||
- `npm_one_12_34_1_`
|
||||
- `npm_one_2_2`
|
||||
- `react-native-responsive-size`
|
||||
- `react-native-sayhello-module`
|
||||
- `react-native-dsphoto-module`
|
||||
- `payutesting`
|
||||
- `vue-cli-plugin-ut-builder`
|
||||
- `xbuilder-forms`
|
||||
- `deploy-versioning`
|
||||
- `eval-spider`
|
||||
- `@hstech/utils`
|
||||
- `@angga30prabu/wa-modified`
|
||||
- `@lakutata-module/service`
|
||||
- `birken-react-native-community-image-editor`
|
||||
- `get-tarball-cli`
|
||||
- `luojia-cli-dev`
|
||||
- `reac-native-arun-ramya-test`
|
||||
- `react-native-transtracker-library`
|
||||
- `react-native-pulsator-native`
|
||||
- `react-native-arun-ramya-test`
|
||||
- `react-native-arunramya151`
|
||||
- `react-native-plugpag-wrapper`
|
||||
- `delta-screen`
|
||||
- `workpad`
|
||||
- `microbe.js`
|
||||
- `ndla-source-map-resolver`
|
||||
- `@screeb/react-native`
|
||||
- `@mockswitch/cli`
|
||||
- `@ndla/source-map-resolver`
|
||||
- `@jimengio/mocked-proxy`
|
||||
- `@buganto/client`
|
||||
- `ts-scraper`
|
||||
- `ba-js-cookie-banner`
|
||||
- `react-native-syan-photo-picker`
|
||||
- `@wecraftapps/react-native-use-keyboard`
|
||||
- `angularvezba`
|
||||
- `hui-plugin-wss`
|
||||
- `l2forlerna`
|
||||
- `native-google-login`
|
||||
- `react-native-modal-progress-bar`
|
||||
- `react-native-test-module-hhh`
|
||||
- `raact-native-arunramya151`
|
||||
- `react-native-badge-control`
|
||||
- `rn-tm-notify`
|
||||
- `wander-cli`
|
||||
- `hubot-will-it-connect`
|
||||
- `react-native-jsi-device-info`
|
||||
- `heroku-wp-environment-sync`
|
||||
- `normalize-ssh-url`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
- [`delta-screen`](https://github.com/carlosmarte/delta-screen#readme)—[delta-screen on npm](https://www.npmjs.com/package/delta-screen)
|
||||
- [`deploy-versioning`](https://github.com/educastellano/deploy-versioning#readme)—Deploy your code keeping older versions.
|
||||
- [`eval-spider`](https://github.com/evalsocket/eval-spider/blob/master/README.md) (by evalsocket)—crawle website
|
||||
- [`fuge-runner`](https://github.com/apparatus/fuge-runner#readme) (by Peter Elger)—[![npm version][npm-badge]][npm-url] [![npm downloads][npm-downloads-badge]][npm-url] [![Build Status][travis-badge]][travis-url]
|
||||
- [`get-tarball-cli`](https://npmjs.com/package/get-tarball-cli) (by Vincent G. Cabrera)—Download tarballs from npm using a package-lock.json file
|
||||
- [`git-up`](https://github.com/IonicaBizau/git-up)—A low level git url parser.
|
||||
- [`heroku-wp-environment-sync`](https://github.com/taneliheikkinen/heroku-wp-environment-sync#readme) (by Taneli Heikkinen)—A heroku plugin to sync different wordpress environments.
|
||||
- [`hologit`](https://github.com/EmergencePlatform/hologit#readme) (by Chris Alfano)—Hologit automates the projection of layered composite file trees based on flat, declarative plans
|
||||
- [`hubot-will-it-connect`](https://github.com/gambtho/hubot-will-it-connect#readme) (by gambtho)—Connects hubot with willitconnect, to validate CF's ability to connect to external resources
|
||||
- [`kakapo`](https://github.com/devlucky/Kakapo.js#readme) (by devlucky)—Next generation mocking framework in Javascript
|
||||
- [`lien`](https://github.com/LienJS/Lien)—An easy to use web framework for Node.js.
|
||||
- [`microbe.js`](https://github.com/Aweary/microbe.js) (by Brandon Dail)—A small Node.js framework for simple routing
|
||||
- [`miguelcostero-ng2-toasty`](https://github.com/akserg/ng2-toasty) (by Sergey Akopkokhyants)—Angular2 Toasty component shows growl-style alerts and messages for your web app
|
||||
- [`native-zip`](https://npmjs.com/package/native-zip) (by kardel)—app内H5应用本地化打包工具,支持增量打包,全量打包
|
||||
- [`ndla-source-map-resolver`](https://npmjs.com/package/ndla-source-map-resolver) (by ndla@knowit.no)—Source map resolver for errors logged via ndla-error-reporter.
|
||||
- [`normalize-ssh`](https://github.com/zkochan/normalize-ssh#readme) (by Zoltan Kochan)—Normalize a SSH URL
|
||||
- [`parse-db-uri`](https://github.com/IonicaBizau/parse-db-uri#readme)—Parse database URIs
|
||||
- [`robots-agent`](https://github.com/gajus/robots-agent#readme) (by Gajus Kuizinas)—robots.txt agent with cache.
|
||||
- [`ssh-host-manager`](https://github.com/shyim/ssh-session-manager#readme) (by Shyim)—Simple CLI to manage your ssh shortcuts
|
||||
- [`ts-scraper`](https://github.com/pskd73/ts-scraper#readme) (by Pramod Kumar)—Scarp links present in the website recursively
|
||||
- [`tumblr-text`](https://npmjs.com/package/tumblr-text) (by cobaimelan)—[](https://travis-ci.org/ayhankuru/tumblr-text) [](https://david-dm.org/ayhan
|
||||
- [`url-local`](https://github.com/IonicaBizau/url-local#readme)—Checks if a given url is a local url or not.
|
||||
- [`vrt-cli`](https://github.com/cesarferreira/vrt-cli#readme) (by Viktor Bezdek)—> Visual regression testing helper toolkit.
|
||||
- [`wander-cli`](https://github.com/dividedbyzeroco/wander-js#readme) (by Jake Josol)—Database Migrations for Modern Apps
|
||||
- [`warp-server`](https://github.com/dividedbyzeroco/warp-server#readme) (by Warp)—Warp Server
|
||||
- [`xbuilder-forms`](https://github.com/stewartmegaw/xBuilderForms#readme) (by Stewart Megaw)—Quickly add beautiful and powerful forms to your application
|
||||
|
||||
## :scroll: License
|
||||
|
||||
[MIT][license] © [Ionică Bizău][website]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[license]: /LICENSE
|
||||
[website]: https://ionicabizau.net
|
||||
[contributing]: /CONTRIBUTING.md
|
||||
[docs]: /DOCUMENTATION.md
|
||||
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
|
||||
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
|
||||
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
||||
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
||||
|
||||
[patreon]: https://www.patreon.com/ionicabizau
|
||||
[amazon]: http://amzn.eu/hRo9sIZ
|
||||
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
||||
|
||||
[license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(https%3A%2F%2Fionicabizau.net)&year=2015#license-mit
|
||||
[website]: https://ionicabizau.net
|
||||
[contributing]: /CONTRIBUTING.md
|
||||
[docs]: /DOCUMENTATION.md
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
declare interface ParsedUrl {
|
||||
protocols: string[];
|
||||
protocol: string;
|
||||
port?: string;
|
||||
resource: string;
|
||||
user: string;
|
||||
pathname: string;
|
||||
hash: string;
|
||||
search: string;
|
||||
href: string;
|
||||
query: {
|
||||
[key: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
declare function parseUrl(url: string, normalize?: boolean | Object): ParsedUrl;
|
||||
|
||||
export default parseUrl
|
||||
+11
-15
@@ -1,9 +1,7 @@
|
||||
"use strict";
|
||||
"use strict"
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var parsePath = require("parse-path"),
|
||||
normalizeUrl = require("normalize-url");
|
||||
const parsePath = require("parse-path")
|
||||
, normalizeUrl = require("normalize-url")
|
||||
|
||||
/**
|
||||
* parseUrl
|
||||
@@ -34,22 +32,20 @@ var parsePath = require("parse-path"),
|
||||
* - `href` (String): The input url.
|
||||
* - `query` (Object): The url querystring, parsed as object.
|
||||
*/
|
||||
function parseUrl(url) {
|
||||
var normalize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
|
||||
function parseUrl(url, normalize = false) {
|
||||
if (typeof url !== "string" || !url.trim()) {
|
||||
throw new Error("Invalid url.");
|
||||
throw new Error("Invalid url.")
|
||||
}
|
||||
if (normalize) {
|
||||
if ((typeof normalize === "undefined" ? "undefined" : _typeof(normalize)) !== "object") {
|
||||
if (typeof normalize !== "object") {
|
||||
normalize = {
|
||||
stripFragment: false
|
||||
};
|
||||
stripHash: false
|
||||
}
|
||||
}
|
||||
url = normalizeUrl(url, normalize);
|
||||
url = normalizeUrl(url, normalize)
|
||||
}
|
||||
var parsed = parsePath(url);
|
||||
const parsed = parsePath(url)
|
||||
return parsed;
|
||||
}
|
||||
|
||||
module.exports = parseUrl;
|
||||
module.exports = parseUrl;
|
||||
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
declare namespace normalizeUrl {
|
||||
interface Options {
|
||||
/**
|
||||
@default 'http:'
|
||||
*/
|
||||
readonly defaultProtocol?: string;
|
||||
|
||||
/**
|
||||
Prepends `defaultProtocol` to the URL if it's protocol-relative.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('//sindresorhus.com:80/');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false});
|
||||
//=> '//sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly normalizeProtocol?: boolean;
|
||||
|
||||
/**
|
||||
Normalizes `https:` URLs to `http:`.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('https://sindresorhus.com:80/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('https://sindresorhus.com:80/', {forceHttp: true});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly forceHttp?: boolean;
|
||||
|
||||
/**
|
||||
Normalizes `http:` URLs to `https:`.
|
||||
|
||||
This option can't be used with the `forceHttp` option at the same time.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('https://sindresorhus.com:80/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com:80/', {forceHttps: true});
|
||||
//=> 'https://sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly forceHttps?: boolean;
|
||||
|
||||
/**
|
||||
Strip the [authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) part of a URL.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('user:password@sindresorhus.com');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('user:password@sindresorhus.com', {stripAuthentication: false});
|
||||
//=> 'https://user:password@sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly stripAuthentication?: boolean;
|
||||
|
||||
/**
|
||||
Removes hash from the URL.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('sindresorhus.com/about.html#contact');
|
||||
//=> 'http://sindresorhus.com/about.html#contact'
|
||||
|
||||
normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});
|
||||
//=> 'http://sindresorhus.com/about.html'
|
||||
```
|
||||
*/
|
||||
readonly stripHash?: boolean;
|
||||
|
||||
/**
|
||||
Removes HTTP(S) protocol from an URL `http://sindresorhus.com` → `sindresorhus.com`.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('https://sindresorhus.com');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('sindresorhus.com', {stripProtocol: true});
|
||||
//=> 'sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly stripProtocol?: boolean;
|
||||
|
||||
/**
|
||||
Strip the [text fragment](https://web.dev/text-fragments/) part of the URL
|
||||
|
||||
__Note:__ The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');
|
||||
//=> 'http://sindresorhus.com/about.html#'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');
|
||||
//=> 'http://sindresorhus.com/about.html#section'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});
|
||||
//=> 'http://sindresorhus.com/about.html#:~:text=hello'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});
|
||||
//=> 'http://sindresorhus.com/about.html#section:~:text=hello'
|
||||
```
|
||||
*/
|
||||
readonly stripTextFragment?: boolean;
|
||||
|
||||
/**
|
||||
Removes `www.` from the URL.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('http://www.sindresorhus.com');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
|
||||
//=> 'http://www.sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly stripWWW?: boolean;
|
||||
|
||||
/**
|
||||
Removes query parameters that matches any of the provided strings or regexes.
|
||||
|
||||
@default [/^utm_\w+/i]
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
|
||||
removeQueryParameters: ['ref']
|
||||
});
|
||||
//=> 'http://sindresorhus.com/?foo=bar'
|
||||
```
|
||||
|
||||
If a boolean is provided, `true` will remove all the query parameters.
|
||||
|
||||
```
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar', {
|
||||
removeQueryParameters: true
|
||||
});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
|
||||
`false` will not remove any query parameter.
|
||||
|
||||
```
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
|
||||
removeQueryParameters: false
|
||||
});
|
||||
//=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
|
||||
```
|
||||
*/
|
||||
readonly removeQueryParameters?: ReadonlyArray<RegExp | string> | boolean;
|
||||
|
||||
/**
|
||||
Removes trailing slash.
|
||||
|
||||
__Note__: Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('http://sindresorhus.com/redirect/');
|
||||
//=> 'http://sindresorhus.com/redirect'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});
|
||||
//=> 'http://sindresorhus.com/redirect/'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
*/
|
||||
readonly removeTrailingSlash?: boolean;
|
||||
|
||||
/**
|
||||
Remove a sole `/` pathname in the output. This option is independant of `removeTrailingSlash`.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('https://sindresorhus.com/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});
|
||||
//=> 'https://sindresorhus.com/'
|
||||
```
|
||||
*/
|
||||
readonly removeSingleSlash?: boolean;
|
||||
|
||||
/**
|
||||
Removes the default directory index file from path that matches any of the provided strings or regexes.
|
||||
When `true`, the regex `/^index\.[a-z]+$/` is used.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('www.sindresorhus.com/foo/default.php', {
|
||||
removeDirectoryIndex: [/^default\.[a-z]+$/]
|
||||
});
|
||||
//=> 'http://sindresorhus.com/foo'
|
||||
```
|
||||
*/
|
||||
readonly removeDirectoryIndex?: ReadonlyArray<RegExp | string>;
|
||||
|
||||
/**
|
||||
Sorts the query parameters alphabetically by key.
|
||||
|
||||
@default true
|
||||
|
||||
@example
|
||||
```
|
||||
normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {
|
||||
sortQueryParameters: false
|
||||
});
|
||||
//=> 'http://sindresorhus.com/?b=two&a=one&c=three'
|
||||
```
|
||||
*/
|
||||
readonly sortQueryParameters?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL.
|
||||
|
||||
@param url - URL to normalize, including [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).
|
||||
|
||||
@example
|
||||
```
|
||||
import normalizeUrl = require('normalize-url');
|
||||
|
||||
normalizeUrl('sindresorhus.com');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');
|
||||
//=> 'http://sindresorhus.com/baz?a=foo&b=bar'
|
||||
```
|
||||
*/
|
||||
declare function normalizeUrl(url: string, options?: normalizeUrl.Options): string;
|
||||
|
||||
export = normalizeUrl;
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
'use strict';
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
|
||||
const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
|
||||
const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
|
||||
|
||||
const testParameter = (name, filters) => {
|
||||
return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
|
||||
};
|
||||
|
||||
const normalizeDataURL = (urlString, {stripHash}) => {
|
||||
const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
|
||||
|
||||
if (!match) {
|
||||
throw new Error(`Invalid URL: ${urlString}`);
|
||||
}
|
||||
|
||||
let {type, data, hash} = match.groups;
|
||||
const mediaType = type.split(';');
|
||||
hash = stripHash ? '' : hash;
|
||||
|
||||
let isBase64 = false;
|
||||
if (mediaType[mediaType.length - 1] === 'base64') {
|
||||
mediaType.pop();
|
||||
isBase64 = true;
|
||||
}
|
||||
|
||||
// Lowercase MIME type
|
||||
const mimeType = (mediaType.shift() || '').toLowerCase();
|
||||
const attributes = mediaType
|
||||
.map(attribute => {
|
||||
let [key, value = ''] = attribute.split('=').map(string => string.trim());
|
||||
|
||||
// Lowercase `charset`
|
||||
if (key === 'charset') {
|
||||
value = value.toLowerCase();
|
||||
|
||||
if (value === DATA_URL_DEFAULT_CHARSET) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return `${key}${value ? `=${value}` : ''}`;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
const normalizedMediaType = [
|
||||
...attributes
|
||||
];
|
||||
|
||||
if (isBase64) {
|
||||
normalizedMediaType.push('base64');
|
||||
}
|
||||
|
||||
if (normalizedMediaType.length !== 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
|
||||
normalizedMediaType.unshift(mimeType);
|
||||
}
|
||||
|
||||
return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
|
||||
};
|
||||
|
||||
const normalizeUrl = (urlString, options) => {
|
||||
options = {
|
||||
defaultProtocol: 'http:',
|
||||
normalizeProtocol: true,
|
||||
forceHttp: false,
|
||||
forceHttps: false,
|
||||
stripAuthentication: true,
|
||||
stripHash: false,
|
||||
stripTextFragment: true,
|
||||
stripWWW: true,
|
||||
removeQueryParameters: [/^utm_\w+/i],
|
||||
removeTrailingSlash: true,
|
||||
removeSingleSlash: true,
|
||||
removeDirectoryIndex: false,
|
||||
sortQueryParameters: true,
|
||||
...options
|
||||
};
|
||||
|
||||
urlString = urlString.trim();
|
||||
|
||||
// Data URL
|
||||
if (/^data:/i.test(urlString)) {
|
||||
return normalizeDataURL(urlString, options);
|
||||
}
|
||||
|
||||
if (/^view-source:/i.test(urlString)) {
|
||||
throw new Error('`view-source:` is not supported as it is a non-standard protocol');
|
||||
}
|
||||
|
||||
const hasRelativeProtocol = urlString.startsWith('//');
|
||||
const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
|
||||
|
||||
// Prepend protocol
|
||||
if (!isRelativeUrl) {
|
||||
urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
|
||||
}
|
||||
|
||||
const urlObj = new URL(urlString);
|
||||
|
||||
if (options.forceHttp && options.forceHttps) {
|
||||
throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
|
||||
}
|
||||
|
||||
if (options.forceHttp && urlObj.protocol === 'https:') {
|
||||
urlObj.protocol = 'http:';
|
||||
}
|
||||
|
||||
if (options.forceHttps && urlObj.protocol === 'http:') {
|
||||
urlObj.protocol = 'https:';
|
||||
}
|
||||
|
||||
// Remove auth
|
||||
if (options.stripAuthentication) {
|
||||
urlObj.username = '';
|
||||
urlObj.password = '';
|
||||
}
|
||||
|
||||
// Remove hash
|
||||
if (options.stripHash) {
|
||||
urlObj.hash = '';
|
||||
} else if (options.stripTextFragment) {
|
||||
urlObj.hash = urlObj.hash.replace(/#?:~:text.*?$/i, '');
|
||||
}
|
||||
|
||||
// Remove duplicate slashes if not preceded by a protocol
|
||||
if (urlObj.pathname) {
|
||||
urlObj.pathname = urlObj.pathname.replace(/(?<!\b(?:[a-z][a-z\d+\-.]{1,50}:))\/{2,}/g, '/');
|
||||
}
|
||||
|
||||
// Decode URI octets
|
||||
if (urlObj.pathname) {
|
||||
try {
|
||||
urlObj.pathname = decodeURI(urlObj.pathname);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Remove directory index
|
||||
if (options.removeDirectoryIndex === true) {
|
||||
options.removeDirectoryIndex = [/^index\.[a-z]+$/];
|
||||
}
|
||||
|
||||
if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
|
||||
let pathComponents = urlObj.pathname.split('/');
|
||||
const lastComponent = pathComponents[pathComponents.length - 1];
|
||||
|
||||
if (testParameter(lastComponent, options.removeDirectoryIndex)) {
|
||||
pathComponents = pathComponents.slice(0, pathComponents.length - 1);
|
||||
urlObj.pathname = pathComponents.slice(1).join('/') + '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (urlObj.hostname) {
|
||||
// Remove trailing dot
|
||||
urlObj.hostname = urlObj.hostname.replace(/\.$/, '');
|
||||
|
||||
// Remove `www.`
|
||||
if (options.stripWWW && /^www\.(?!www\.)(?:[a-z\-\d]{1,63})\.(?:[a-z.\-\d]{2,63})$/.test(urlObj.hostname)) {
|
||||
// Each label should be max 63 at length (min: 1).
|
||||
// Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
|
||||
// Each TLD should be up to 63 characters long (min: 2).
|
||||
// It is technically possible to have a single character TLD, but none currently exist.
|
||||
urlObj.hostname = urlObj.hostname.replace(/^www\./, '');
|
||||
}
|
||||
}
|
||||
|
||||
// Remove query unwanted parameters
|
||||
if (Array.isArray(options.removeQueryParameters)) {
|
||||
for (const key of [...urlObj.searchParams.keys()]) {
|
||||
if (testParameter(key, options.removeQueryParameters)) {
|
||||
urlObj.searchParams.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.removeQueryParameters === true) {
|
||||
urlObj.search = '';
|
||||
}
|
||||
|
||||
// Sort query parameters
|
||||
if (options.sortQueryParameters) {
|
||||
urlObj.searchParams.sort();
|
||||
}
|
||||
|
||||
if (options.removeTrailingSlash) {
|
||||
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
const oldUrlString = urlString;
|
||||
|
||||
// Take advantage of many of the Node `url` normalizations
|
||||
urlString = urlObj.toString();
|
||||
|
||||
if (!options.removeSingleSlash && urlObj.pathname === '/' && !oldUrlString.endsWith('/') && urlObj.hash === '') {
|
||||
urlString = urlString.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
// Remove ending `/` unless removeSingleSlash is false
|
||||
if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '' && options.removeSingleSlash) {
|
||||
urlString = urlString.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
// Restore relative protocol, if applicable
|
||||
if (hasRelativeProtocol && !options.normalizeProtocol) {
|
||||
urlString = urlString.replace(/^http:\/\//, '//');
|
||||
}
|
||||
|
||||
// Remove http/https
|
||||
if (options.stripProtocol) {
|
||||
urlString = urlString.replace(/^(?:https?:)?\/\//, '');
|
||||
}
|
||||
|
||||
return urlString;
|
||||
};
|
||||
|
||||
module.exports = normalizeUrl;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"normalize-url@6.1.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "normalize-url@6.1.0",
|
||||
"_id": "normalize-url@6.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==",
|
||||
"_location": "/parse-url/normalize-url",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "normalize-url@6.1.0",
|
||||
"name": "normalize-url",
|
||||
"escapedName": "normalize-url",
|
||||
"rawSpec": "6.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "6.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/parse-url"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||
"_spec": "6.1.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/normalize-url/issues"
|
||||
},
|
||||
"description": "Normalize a URL",
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"nyc": "^15.0.0",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.25.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"homepage": "https://github.com/sindresorhus/normalize-url#readme",
|
||||
"keywords": [
|
||||
"normalize",
|
||||
"url",
|
||||
"uri",
|
||||
"address",
|
||||
"string",
|
||||
"normalization",
|
||||
"normalisation",
|
||||
"query",
|
||||
"querystring",
|
||||
"simplify",
|
||||
"strip",
|
||||
"trim",
|
||||
"canonical"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "normalize-url",
|
||||
"nyc": {
|
||||
"reporter": [
|
||||
"text",
|
||||
"lcov"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/normalize-url.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc ava && tsd"
|
||||
},
|
||||
"version": "6.1.0"
|
||||
}
|
||||
+286
@@ -0,0 +1,286 @@
|
||||
# normalize-url [](https://codecov.io/gh/sindresorhus/normalize-url)
|
||||
|
||||
> [Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL
|
||||
|
||||
Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install normalize-url
|
||||
```
|
||||
|
||||
*If you need to use this in the browser, use version 4: `npm i normalize-url@4`*
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const normalizeUrl = require('normalize-url');
|
||||
|
||||
normalizeUrl('sindresorhus.com');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');
|
||||
//=> 'http://sindresorhus.com/baz?a=foo&b=bar'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### normalizeUrl(url, options?)
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
URL to normalize, including [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### defaultProtocol
|
||||
|
||||
Type: `string`\
|
||||
Default: `http:`
|
||||
|
||||
##### normalizeProtocol
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Prepend `defaultProtocol` to the URL if it's protocol-relative.
|
||||
|
||||
```js
|
||||
normalizeUrl('//sindresorhus.com:80/');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false});
|
||||
//=> '//sindresorhus.com'
|
||||
```
|
||||
|
||||
##### forceHttp
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Normalize `https:` to `http:`.
|
||||
|
||||
```js
|
||||
normalizeUrl('https://sindresorhus.com:80/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('https://sindresorhus.com:80/', {forceHttp: true});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
|
||||
##### forceHttps
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Normalize `http:` to `https:`.
|
||||
|
||||
```js
|
||||
normalizeUrl('https://sindresorhus.com:80/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com:80/', {forceHttps: true});
|
||||
//=> 'https://sindresorhus.com'
|
||||
```
|
||||
|
||||
This option can't be used with the `forceHttp` option at the same time.
|
||||
|
||||
##### stripAuthentication
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Strip the [authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) part of the URL.
|
||||
|
||||
```js
|
||||
normalizeUrl('user:password@sindresorhus.com');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('user:password@sindresorhus.com', {stripAuthentication: false});
|
||||
//=> 'https://user:password@sindresorhus.com'
|
||||
```
|
||||
|
||||
##### stripHash
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Strip the hash part of the URL.
|
||||
|
||||
```js
|
||||
normalizeUrl('sindresorhus.com/about.html#contact');
|
||||
//=> 'http://sindresorhus.com/about.html#contact'
|
||||
|
||||
normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});
|
||||
//=> 'http://sindresorhus.com/about.html'
|
||||
```
|
||||
|
||||
##### stripProtocol
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Remove HTTP(S) protocol from the URL: `http://sindresorhus.com` → `sindresorhus.com`.
|
||||
|
||||
```js
|
||||
normalizeUrl('https://sindresorhus.com');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('https://sindresorhus.com', {stripProtocol: true});
|
||||
//=> 'sindresorhus.com'
|
||||
```
|
||||
|
||||
##### stripTextFragment
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Strip the [text fragment](https://web.dev/text-fragments/) part of the URL.
|
||||
|
||||
**Note:** The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment.
|
||||
|
||||
```js
|
||||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');
|
||||
//=> 'http://sindresorhus.com/about.html#'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');
|
||||
//=> 'http://sindresorhus.com/about.html#section'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});
|
||||
//=> 'http://sindresorhus.com/about.html#:~:text=hello'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});
|
||||
//=> 'http://sindresorhus.com/about.html#section:~:text=hello'
|
||||
```
|
||||
|
||||
##### stripWWW
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Remove `www.` from the URL.
|
||||
|
||||
```js
|
||||
normalizeUrl('http://www.sindresorhus.com');
|
||||
//=> 'http://sindresorhus.com'
|
||||
|
||||
normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
|
||||
//=> 'http://www.sindresorhus.com'
|
||||
```
|
||||
|
||||
##### removeQueryParameters
|
||||
|
||||
Type: `Array<RegExp | string> | boolean`\
|
||||
Default: `[/^utm_\w+/i]`
|
||||
|
||||
Remove query parameters that matches any of the provided strings or regexes.
|
||||
|
||||
```js
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
|
||||
removeQueryParameters: ['ref']
|
||||
});
|
||||
//=> 'http://sindresorhus.com/?foo=bar'
|
||||
```
|
||||
|
||||
If a boolean is provided, `true` will remove all the query parameters.
|
||||
|
||||
```js
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar', {
|
||||
removeQueryParameters: true
|
||||
});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
|
||||
`false` will not remove any query parameter.
|
||||
|
||||
```js
|
||||
normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
|
||||
removeQueryParameters: false
|
||||
});
|
||||
//=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
|
||||
```
|
||||
|
||||
##### removeTrailingSlash
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Remove trailing slash.
|
||||
|
||||
**Note:** Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`.
|
||||
|
||||
```js
|
||||
normalizeUrl('http://sindresorhus.com/redirect/');
|
||||
//=> 'http://sindresorhus.com/redirect'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});
|
||||
//=> 'http://sindresorhus.com/redirect/'
|
||||
|
||||
normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});
|
||||
//=> 'http://sindresorhus.com'
|
||||
```
|
||||
|
||||
##### removeSingleSlash
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Remove a sole `/` pathname in the output. This option is independant of `removeTrailingSlash`.
|
||||
|
||||
```js
|
||||
normalizeUrl('https://sindresorhus.com/');
|
||||
//=> 'https://sindresorhus.com'
|
||||
|
||||
normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});
|
||||
//=> 'https://sindresorhus.com/'
|
||||
```
|
||||
|
||||
|
||||
##### removeDirectoryIndex
|
||||
|
||||
Type: `boolean | Array<RegExp | string>`\
|
||||
Default: `false`
|
||||
|
||||
Removes the default directory index file from path that matches any of the provided strings or regexes. When `true`, the regex `/^index\.[a-z]+$/` is used.
|
||||
|
||||
```js
|
||||
normalizeUrl('www.sindresorhus.com/foo/default.php', {
|
||||
removeDirectoryIndex: [/^default\.[a-z]+$/]
|
||||
});
|
||||
//=> 'http://sindresorhus.com/foo'
|
||||
```
|
||||
|
||||
##### sortQueryParameters
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Sorts the query parameters alphabetically by key.
|
||||
|
||||
```js
|
||||
normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {
|
||||
sortQueryParameters: false
|
||||
});
|
||||
//=> 'http://sindresorhus.com/?b=two&a=one&c=three'
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
- [compare-urls](https://github.com/sindresorhus/compare-urls) - Compare URLs by first normalizing them
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-normalize-url?utm_source=npm-normalize-url&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-20 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# protocols
|
||||
|
||||
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://travis-ci.org/IonicaBizau/protocols/) [](https://www.npmjs.com/package/protocols) [](https://www.npmjs.com/package/protocols) [](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
||||
|
||||
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
> Get the protocols of an input url.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :cloud: Installation
|
||||
|
||||
```sh
|
||||
# Using npm
|
||||
npm install --save protocols
|
||||
|
||||
# Using yarn
|
||||
yarn add protocols
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :clipboard: Example
|
||||
|
||||
|
||||
|
||||
```js
|
||||
// Dependencies
|
||||
const protocols = require("protocols");
|
||||
|
||||
console.log(protocols("git+ssh://git@some-host.com/and-the-path/name"));
|
||||
// ["git", "ssh"]
|
||||
|
||||
console.log(protocols("http://ionicabizau.net", true));
|
||||
// "http"
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :question: Get Help
|
||||
|
||||
There are few ways to get help:
|
||||
|
||||
|
||||
|
||||
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
||||
2. For bug reports and feature requests, open issues. :bug:
|
||||
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :memo: Documentation
|
||||
|
||||
|
||||
### `protocols(input, first)`
|
||||
Returns the protocols of an input url.
|
||||
|
||||
#### Params
|
||||
|
||||
- **String** `input`: The input url.
|
||||
- **Boolean|Number** `first`: If `true`, the first protocol will be returned. If number, it will represent the zero-based index of the protocols array.
|
||||
|
||||
#### Return
|
||||
- **Array|String** The array of protocols or the specified protocol.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :yum: How to contribute
|
||||
Have an idea? Found a bug? See [how to contribute][contributing].
|
||||
|
||||
|
||||
## :sparkling_heart: Support my projects
|
||||
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
|
||||
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
|
||||
|
||||
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
|
||||
|
||||
|
||||
- Starring and sharing the projects you like :rocket:
|
||||
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
|
||||
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
|
||||
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
|
||||
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
||||
|
||||

|
||||
|
||||
|
||||
Thanks! :heart:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :dizzy: Where is this library used?
|
||||
If you are using this library in one of your projects, add it in this list. :sparkles:
|
||||
|
||||
- `parse-url`
|
||||
- `parse-path`
|
||||
- `is-ssh`
|
||||
- `bb-parse-url`
|
||||
- `@hawkingnetwork/react-native-tab-view`
|
||||
- `miguelcostero-ng2-toasty`
|
||||
- `@apardellass/react-native-audio-stream`
|
||||
- `l2forlerna`
|
||||
- `react-native-plugpag-wrapper`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## :scroll: License
|
||||
|
||||
[MIT][license] © [Ionică Bizău][website]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[license]: /LICENSE
|
||||
[website]: https://ionicabizau.net
|
||||
[contributing]: /CONTRIBUTING.md
|
||||
[docs]: /DOCUMENTATION.md
|
||||
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
|
||||
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
|
||||
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
||||
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
||||
[patreon]: https://www.patreon.com/ionicabizau
|
||||
[amazon]: http://amzn.eu/hRo9sIZ
|
||||
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* protocols
|
||||
* Returns the protocols of an input url.
|
||||
*
|
||||
* @name protocols
|
||||
* @function
|
||||
* @param {String} input The input url.
|
||||
* @param {Boolean|Number} first If `true`, the first protocol will be returned. If number, it will represent the zero-based index of the protocols array.
|
||||
* @return {Array|String} The array of protocols or the specified protocol.
|
||||
*/
|
||||
module.exports = function protocols(input, first) {
|
||||
|
||||
if (first === true) {
|
||||
first = 0;
|
||||
}
|
||||
|
||||
var index = input.indexOf("://"),
|
||||
splits = input.substring(0, index).split("+").filter(Boolean);
|
||||
|
||||
if (typeof first === "number") {
|
||||
return splits[first];
|
||||
}
|
||||
|
||||
return splits;
|
||||
};
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"protocols@1.4.8",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "protocols@1.4.8",
|
||||
"_id": "protocols@1.4.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-IgjKyaUSjsROSO8/D49Ab7hP8mJgTYcqApOqdPhLoPxAplXmkp+zRvsrSQjFn5by0rhm4VH0GAUELIPpx7B1yg==",
|
||||
"_location": "/parse-url/protocols",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "protocols@1.4.8",
|
||||
"name": "protocols",
|
||||
"escapedName": "protocols",
|
||||
"rawSpec": "1.4.8",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.4.8"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/parse-url"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/protocols/-/protocols-1.4.8.tgz",
|
||||
"_spec": "1.4.8",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Ionică Bizău",
|
||||
"email": "bizauionica@gmail.com",
|
||||
"url": "https://ionicabizau.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/IonicaBizau/protocols/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Get the protocols of an input url.",
|
||||
"devDependencies": {
|
||||
"tester": "^1.3.1"
|
||||
},
|
||||
"directories": {
|
||||
"example": "example",
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"app/",
|
||||
"lib/",
|
||||
"dist/",
|
||||
"src/",
|
||||
"scripts/",
|
||||
"resources/",
|
||||
"menu/",
|
||||
"cli.js",
|
||||
"index.js",
|
||||
"bloggify.js",
|
||||
"bloggify.json",
|
||||
"bloggify/"
|
||||
],
|
||||
"homepage": "https://github.com/IonicaBizau/protocols",
|
||||
"keywords": [
|
||||
"protocols",
|
||||
"protocol",
|
||||
"url",
|
||||
"parse"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "protocols",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/IonicaBizau/protocols.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"version": "1.4.8"
|
||||
}
|
||||
+14
-14
@@ -1,32 +1,32 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"parse-url@5.0.1",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"parse-url@6.0.2",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "parse-url@5.0.1",
|
||||
"_id": "parse-url@5.0.1",
|
||||
"_from": "parse-url@6.0.2",
|
||||
"_id": "parse-url@6.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-flNUPP27r3vJpROi0/R3/2efgKkyXqnXwyP1KQ2U0SfFRgdizOdWfvrrvJg1LuOoxs7GQhmxJlq23IpQ/BkByg==",
|
||||
"_integrity": "sha512-uCSjOvD3T+6B/sPWhR+QowAZcU/o4bjPrVBQBGFxcDF6J6FraCGIaDBsdoQawiaaAVdHvtqBe3w3vKlfBKySOQ==",
|
||||
"_location": "/parse-url",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "parse-url@5.0.1",
|
||||
"raw": "parse-url@6.0.2",
|
||||
"name": "parse-url",
|
||||
"escapedName": "parse-url",
|
||||
"rawSpec": "5.0.1",
|
||||
"rawSpec": "6.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.0.1"
|
||||
"fetchSpec": "6.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/git-up"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/parse-url/-/parse-url-5.0.1.tgz",
|
||||
"_spec": "5.0.1",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/parse-url/-/parse-url-6.0.2.tgz",
|
||||
"_spec": "6.0.2",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Ionică Bizău",
|
||||
"email": "bizauionica@gmail.com",
|
||||
@@ -42,8 +42,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"is-ssh": "^1.3.0",
|
||||
"normalize-url": "^3.3.0",
|
||||
"parse-path": "^4.0.0",
|
||||
"normalize-url": "^6.1.0",
|
||||
"parse-path": "^4.0.4",
|
||||
"protocols": "^1.4.0"
|
||||
},
|
||||
"description": "An advanced url parser supporting git urls too.",
|
||||
@@ -87,5 +87,5 @@
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"version": "5.0.1"
|
||||
"version": "6.0.2"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user