Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse-url 8.0.0 #55

Merged
merged 16 commits into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions DOCUMENTATION.md
Expand Up @@ -2,6 +2,12 @@

You can see below the API reference of this module.

### `interopDefaultLegacy()`
#__PURE__

### `interopDefaultLegacy()`
#__PURE__

### `parseUrl(url, normalize)`
Parses the input url.

Expand All @@ -28,4 +34,5 @@ Parses the input url.
- `search` (String): The url querystring value.
- `href` (String): The input url.
- `query` (Object): The url querystring, parsed as object.
- `parse_failed` (Boolean): Whether the parsing failed or not.

94 changes: 53 additions & 41 deletions README.md
Expand Up @@ -77,7 +77,7 @@ yarn add parse-url

```js
// Dependencies
const parseUrl = require("parse-url")
import parseUrl from "../lib/index.js";

console.log(parseUrl("http://ionicabizau.net/blog"))
// {
Expand Down Expand Up @@ -168,6 +168,12 @@ There are few ways to get help:
## :memo: Documentation


### `interopDefaultLegacy()`
#__PURE__

### `interopDefaultLegacy()`
#__PURE__

### `parseUrl(url, normalize)`
Parses the input url.

Expand All @@ -194,6 +200,7 @@ Parses the input url.
- `search` (String): The url querystring value.
- `href` (String): The input url.
- `query` (Object): The url querystring, parsed as object.
- `parse_failed` (Boolean): Whether the parsing failed or not.



Expand Down Expand Up @@ -249,13 +256,15 @@ Thanks! :heart:
If you are using this library in one of your projects, add it in this list. :sparkles:

- `git-up`
- `@semantic-release/gitlab`
- `lien`
- `stun`
- `@open-wa/wa-automate`
- `kakapo`
- `@pushrocks/smarturl`
- `parse-db-uri`
- `url-local`
- `fuge-runner`
- `url-local`
- `build-plugin-ssr`
- `rucksack`
- `egg-muc-custom-loader`
Expand All @@ -270,24 +279,21 @@ If you are using this library in one of your projects, add it in this list. :spa
- `@hemith/react-native-tnk`
- `@kriblet/wa-automate`
- `@notnuzzel/crawl`
- `native-kakao-login`
- `gitlab-backup-util-harduino`
- `bilibili2local`
- `miguelcostero-ng2-toasty`
- `native-kakao-login`
- `react-native-my-first-try-arun-ramya`
- `react-native-kakao-maps`
- `react-native-is7`
- `react-native-ytximkit`
- `react-native-payu-payment-testing`
- `npm_one_1_2_3`
- `react-native-biometric-authenticate`
- `react-native-arunmeena1987`
- `react-native-biometric-authenticate`
- `react-native-contact-list`
- `rn-adyen-dropin`
- `react-native-is7`
- `react-native-payu-payment-testing`
- `react-native-kakao-maps`
- `react-native-my-first-try-arun-ramya`
- `react-native-ytximkit`
- `@positionex/position-sdk`
- `begg`
- `@corelmax/react-native-my2c2p-sdk`
- `@dataparty/api`
- `@felipesimmi/react-native-datalogic-module`
- `@jprustv/sulla-hotfix`
- `@hawkingnetwork/react-native-tab-view`
Expand All @@ -300,58 +306,61 @@ If you are using this library in one of your projects, add it in this list. :spa
- `ssh-host-manager`
- `soajs.repositories`
- `react-native-arunjeyam1987`
- `react-native-bubble-chart`
- `verify-aws-sns-signature`
- `vrt-cli`
- `vue-cli-plugin-ice-builder`
- `react-native-flyy`
- `graphmilker`
- `native-zip`
- `react-native-flyy`
- `react-native-bubble-chart`
- `verify-aws-sns-signature`
- `@dataparty/api`
- `@apardellass/react-native-audio-stream`
- `@geeky-apo/react-native-advanced-clipboard`
- `@hsui/plugin-wss`
- `blitzzz`
- `candlelabssdk`
- `@roshub/api`
- `@saad27/react-native-bottom-tab-tour`
- `@roshub/api`
- `candlelabssdk`
- `blitzzz`
- `generator-bootstrap-boilerplate-template`
- `react-feedback-sdk`
- `loast`
- `react-native-dsphoto-module`
- `react-native-responsive-size`
- `react-native-sayhello-module`
- `npm_one_12_34_1_`
- `npm_one_2_2`
- `payutesting`
- `react-native-sayhello-module`
- `react-native-dsphoto-module`
- `vue-cli-plugin-ut-builder`
- `xbuilder-forms`
- `tumblr-text`
- `deploy-versioning`
- `eval-spider`
- `homebridge-pushcutter`
- `@con-test/react-native-concent-common`
- `@hstech/utils`
- `@angga30prabu/wa-modified`
- `birken-react-native-community-image-editor`
- `get-tarball-cli`
- `luojia-cli-dev`
- `tumblr-text`
- `react-native-shekhar-bridge-test`
- `loast`
- `react-feedback-sdk`
- `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`
- `react-native-pulsator-native`
- `react-native-transtracker-library`
- `workpad`
- `ndla-source-map-resolver`
- `@screeb/react-native`
- `@lakutata-module/service`
- `@angga30prabu/wa-modified`
- `@hstech/utils`
- `get-tarball-cli`
- `luojia-cli-dev`
- `birken-react-native-community-image-editor`
- `delta-screen`
- `microbe.js`
- `@buganto/client`
- `@lakutata-module/service`
- `ndla-source-map-resolver`
- `@screeb/react-native`
- `@jfilipe-sparta/react-native-module_2`
- `@jimengio/mocked-proxy`
- `@buganto/client`
- `@mockswitch/cli`
- `@ndla/source-map-resolver`
- `angularvezba`
- `api-reach-react-native-fix`
- `angularvezba`
- `astra-ufo-sdk`
- `react-native-syan-photo-picker`
- `@wecraftapps/react-native-use-keyboard`
Expand All @@ -361,15 +370,18 @@ If you are using this library in one of your projects, add it in this list. :spa
- `raact-native-arunramya151`
- `react-native-modal-progress-bar`
- `react-native-test-module-hhh`
- `react-native-jsi-device-info`
- `react-native-badge-control`
- `rn-tm-notify`
- `wander-cli`
- `ts-scraper`
- `react-native-badge-control`
- `react-native-jsi-device-info`
- `normalize-ssh-url`
- `heroku-wp-environment-sync`
- `hubot-will-it-connect`
- `normalize-ssh-url`
- `ba-js-cookie-banner`
- `@ndla/source-map-resolver`
- `ts-scraper`
- `electron-info`
- `rn-tm-notify`
- `native-date-picker-module`



Expand Down
94 changes: 94 additions & 0 deletions dist/index.js
@@ -0,0 +1,94 @@
'use strict';

var parsePath = require('parse-path');
var normalizeUrl = require('normalize-url');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var parsePath__default = /*#__PURE__*/_interopDefaultLegacy(parsePath);
var normalizeUrl__default = /*#__PURE__*/_interopDefaultLegacy(normalizeUrl);

// Dependencies

/**
* parseUrl
* Parses the input url.
*
* **Note**: This *throws* if invalid urls are provided.
*
* @name parseUrl
* @function
* @param {String} url The input url.
* @param {Boolean|Object} normalize Whether to normalize the url or not.
* Default is `false`. If `true`, the url will
* be normalized. If an object, it will be the
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
*
* For SSH urls, normalize won't work.
*
* @return {Object} An object containing the following fields:
*
* - `protocols` (Array): An array with the url protocols (usually it has one element).
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
* - `port` (null|Number): The domain port.
* - `resource` (String): The url domain (including subdomains).
* - `user` (String): The authentication user (usually for ssh urls).
* - `pathname` (String): The url pathname.
* - `hash` (String): The url hash.
* - `search` (String): The url querystring value.
* - `href` (String): The input url.
* - `query` (Object): The url querystring, parsed as object.
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;

const throwErr = msg => {
const err = new Error(msg);
err.subject_url = url;
throw err
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
}

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false
};
}
url = normalizeUrl__default["default"](url, normalize);
}

const parsed = parsePath__default["default"](url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[4];
parsed.host = matched[4];
parsed.user = "git";
parsed.pathname = `/${matched[6]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
}
}

return parsed;
};

parseUrl.MAX_INPUT_LENGTH = 2048;

module.exports = parseUrl;
87 changes: 87 additions & 0 deletions dist/index.mjs
@@ -0,0 +1,87 @@
import parsePath from 'parse-path';
import normalizeUrl from 'normalize-url';

// Dependencies

/**
* parseUrl
* Parses the input url.
*
* **Note**: This *throws* if invalid urls are provided.
*
* @name parseUrl
* @function
* @param {String} url The input url.
* @param {Boolean|Object} normalize Whether to normalize the url or not.
* Default is `false`. If `true`, the url will
* be normalized. If an object, it will be the
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
*
* For SSH urls, normalize won't work.
*
* @return {Object} An object containing the following fields:
*
* - `protocols` (Array): An array with the url protocols (usually it has one element).
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
* - `port` (null|Number): The domain port.
* - `resource` (String): The url domain (including subdomains).
* - `user` (String): The authentication user (usually for ssh urls).
* - `pathname` (String): The url pathname.
* - `hash` (String): The url hash.
* - `search` (String): The url querystring value.
* - `href` (String): The input url.
* - `query` (Object): The url querystring, parsed as object.
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;

const throwErr = msg => {
const err = new Error(msg);
err.subject_url = url;
throw err
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
}

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false
};
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath(url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[4];
parsed.host = matched[4];
parsed.user = "git";
parsed.pathname = `/${matched[6]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
}
}

return parsed;
};

parseUrl.MAX_INPUT_LENGTH = 2048;

export { parseUrl as default };
File renamed without changes.