Skip to content

Commit 2373f7f

Browse files
committed
Updated docs
1 parent 8f0dfd7 commit 2373f7f

File tree

5 files changed

+241
-42
lines changed

5 files changed

+241
-42
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ node_modules
77
.DS_Store
88
package-lock.json
99
.bloggify/*
10-
dist

DOCUMENTATION.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
You can see below the API reference of this module.
44

5+
### `interopDefaultLegacy()`
6+
#__PURE__
7+
8+
### `interopDefaultLegacy()`
9+
#__PURE__
10+
511
### `parseUrl(url, normalize)`
612
Parses the input url.
713

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

README.md

+53-41
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ yarn add parse-url
7777

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

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

170170

171+
### `interopDefaultLegacy()`
172+
#__PURE__
173+
174+
### `interopDefaultLegacy()`
175+
#__PURE__
176+
171177
### `parseUrl(url, normalize)`
172178
Parses the input url.
173179

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

198205

199206

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

251258
- `git-up`
259+
- `@semantic-release/gitlab`
252260
- `lien`
253261
- `stun`
254262
- `@open-wa/wa-automate`
255263
- `kakapo`
264+
- `@pushrocks/smarturl`
256265
- `parse-db-uri`
257-
- `url-local`
258266
- `fuge-runner`
267+
- `url-local`
259268
- `build-plugin-ssr`
260269
- `rucksack`
261270
- `egg-muc-custom-loader`
@@ -270,24 +279,21 @@ If you are using this library in one of your projects, add it in this list. :spa
270279
- `@hemith/react-native-tnk`
271280
- `@kriblet/wa-automate`
272281
- `@notnuzzel/crawl`
282+
- `native-kakao-login`
273283
- `gitlab-backup-util-harduino`
274-
- `bilibili2local`
275284
- `miguelcostero-ng2-toasty`
276-
- `native-kakao-login`
277-
- `react-native-my-first-try-arun-ramya`
278-
- `react-native-kakao-maps`
279-
- `react-native-is7`
280-
- `react-native-ytximkit`
281-
- `react-native-payu-payment-testing`
282285
- `npm_one_1_2_3`
283-
- `react-native-biometric-authenticate`
284286
- `react-native-arunmeena1987`
287+
- `react-native-biometric-authenticate`
285288
- `react-native-contact-list`
286-
- `rn-adyen-dropin`
289+
- `react-native-is7`
290+
- `react-native-payu-payment-testing`
291+
- `react-native-kakao-maps`
292+
- `react-native-my-first-try-arun-ramya`
293+
- `react-native-ytximkit`
287294
- `@positionex/position-sdk`
288295
- `begg`
289296
- `@corelmax/react-native-my2c2p-sdk`
290-
- `@dataparty/api`
291297
- `@felipesimmi/react-native-datalogic-module`
292298
- `@jprustv/sulla-hotfix`
293299
- `@hawkingnetwork/react-native-tab-view`
@@ -300,58 +306,61 @@ If you are using this library in one of your projects, add it in this list. :spa
300306
- `ssh-host-manager`
301307
- `soajs.repositories`
302308
- `react-native-arunjeyam1987`
303-
- `react-native-bubble-chart`
304-
- `verify-aws-sns-signature`
305309
- `vrt-cli`
306310
- `vue-cli-plugin-ice-builder`
307-
- `react-native-flyy`
308311
- `graphmilker`
309312
- `native-zip`
313+
- `react-native-flyy`
314+
- `react-native-bubble-chart`
315+
- `verify-aws-sns-signature`
316+
- `@dataparty/api`
310317
- `@apardellass/react-native-audio-stream`
311318
- `@geeky-apo/react-native-advanced-clipboard`
312319
- `@hsui/plugin-wss`
313-
- `blitzzz`
314-
- `candlelabssdk`
315-
- `@roshub/api`
316320
- `@saad27/react-native-bottom-tab-tour`
321+
- `@roshub/api`
322+
- `candlelabssdk`
323+
- `blitzzz`
317324
- `generator-bootstrap-boilerplate-template`
318-
- `react-feedback-sdk`
319-
- `loast`
325+
- `react-native-dsphoto-module`
326+
- `react-native-responsive-size`
327+
- `react-native-sayhello-module`
320328
- `npm_one_12_34_1_`
321329
- `npm_one_2_2`
322330
- `payutesting`
323-
- `react-native-sayhello-module`
324-
- `react-native-dsphoto-module`
325331
- `vue-cli-plugin-ut-builder`
326332
- `xbuilder-forms`
327-
- `tumblr-text`
328333
- `deploy-versioning`
329334
- `eval-spider`
330335
- `homebridge-pushcutter`
331336
- `@con-test/react-native-concent-common`
332-
- `@hstech/utils`
333-
- `@angga30prabu/wa-modified`
334-
- `birken-react-native-community-image-editor`
335-
- `get-tarball-cli`
336-
- `luojia-cli-dev`
337+
- `tumblr-text`
338+
- `react-native-shekhar-bridge-test`
339+
- `loast`
340+
- `react-feedback-sdk`
337341
- `reac-native-arun-ramya-test`
338-
- `react-native-transtracker-library`
339-
- `react-native-pulsator-native`
340342
- `react-native-arun-ramya-test`
341343
- `react-native-arunramya151`
342344
- `react-native-plugpag-wrapper`
345+
- `react-native-pulsator-native`
346+
- `react-native-transtracker-library`
343347
- `workpad`
344-
- `ndla-source-map-resolver`
345-
- `@screeb/react-native`
346-
- `@lakutata-module/service`
348+
- `@angga30prabu/wa-modified`
349+
- `@hstech/utils`
350+
- `get-tarball-cli`
351+
- `luojia-cli-dev`
352+
- `birken-react-native-community-image-editor`
347353
- `delta-screen`
348354
- `microbe.js`
349-
- `@buganto/client`
355+
- `@lakutata-module/service`
356+
- `ndla-source-map-resolver`
357+
- `@screeb/react-native`
358+
- `@jfilipe-sparta/react-native-module_2`
350359
- `@jimengio/mocked-proxy`
360+
- `@buganto/client`
351361
- `@mockswitch/cli`
352-
- `@ndla/source-map-resolver`
353-
- `angularvezba`
354362
- `api-reach-react-native-fix`
363+
- `angularvezba`
355364
- `astra-ufo-sdk`
356365
- `react-native-syan-photo-picker`
357366
- `@wecraftapps/react-native-use-keyboard`
@@ -361,15 +370,18 @@ If you are using this library in one of your projects, add it in this list. :spa
361370
- `raact-native-arunramya151`
362371
- `react-native-modal-progress-bar`
363372
- `react-native-test-module-hhh`
364-
- `react-native-jsi-device-info`
365-
- `react-native-badge-control`
366-
- `rn-tm-notify`
367373
- `wander-cli`
368-
- `ts-scraper`
374+
- `react-native-badge-control`
375+
- `react-native-jsi-device-info`
376+
- `normalize-ssh-url`
369377
- `heroku-wp-environment-sync`
370378
- `hubot-will-it-connect`
371-
- `normalize-ssh-url`
372379
- `ba-js-cookie-banner`
380+
- `@ndla/source-map-resolver`
381+
- `ts-scraper`
382+
- `electron-info`
383+
- `rn-tm-notify`
384+
- `native-date-picker-module`
373385

374386

375387

dist/index.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict';
2+
3+
var parsePath = require('parse-path');
4+
var normalizeUrl = require('normalize-url');
5+
6+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7+
8+
var parsePath__default = /*#__PURE__*/_interopDefaultLegacy(parsePath);
9+
var normalizeUrl__default = /*#__PURE__*/_interopDefaultLegacy(normalizeUrl);
10+
11+
// Dependencies
12+
13+
/**
14+
* parseUrl
15+
* Parses the input url.
16+
*
17+
* **Note**: This *throws* if invalid urls are provided.
18+
*
19+
* @name parseUrl
20+
* @function
21+
* @param {String} url The input url.
22+
* @param {Boolean|Object} normalize Whether to normalize the url or not.
23+
* Default is `false`. If `true`, the url will
24+
* be normalized. If an object, it will be the
25+
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
26+
*
27+
* For SSH urls, normalize won't work.
28+
*
29+
* @return {Object} An object containing the following fields:
30+
*
31+
* - `protocols` (Array): An array with the url protocols (usually it has one element).
32+
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
33+
* - `port` (null|Number): The domain port.
34+
* - `resource` (String): The url domain (including subdomains).
35+
* - `user` (String): The authentication user (usually for ssh urls).
36+
* - `pathname` (String): The url pathname.
37+
* - `hash` (String): The url hash.
38+
* - `search` (String): The url querystring value.
39+
* - `href` (String): The input url.
40+
* - `query` (Object): The url querystring, parsed as object.
41+
* - `parse_failed` (Boolean): Whether the parsing failed or not.
42+
*/
43+
const parseUrl = (url, normalize = false) => {
44+
45+
// Constants
46+
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;
47+
48+
const throwErr = msg => {
49+
const err = new Error(msg);
50+
err.subject_url = url;
51+
throw err
52+
};
53+
54+
if (typeof url !== "string" || !url.trim()) {
55+
throwErr("Invalid url.");
56+
}
57+
58+
if (url.length > parseUrl.MAX_INPUT_LENGTH) {
59+
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
60+
}
61+
62+
if (normalize) {
63+
if (typeof normalize !== "object") {
64+
normalize = {
65+
stripHash: false
66+
};
67+
}
68+
url = normalizeUrl__default["default"](url, normalize);
69+
}
70+
71+
const parsed = parsePath__default["default"](url);
72+
73+
// Potential git-ssh urls
74+
if (parsed.parse_failed) {
75+
const matched = parsed.href.match(GIT_RE);
76+
if (matched) {
77+
parsed.protocols = ["ssh"];
78+
parsed.protocol = "ssh";
79+
parsed.resource = matched[4];
80+
parsed.host = matched[4];
81+
parsed.user = "git";
82+
parsed.pathname = `/${matched[6]}`;
83+
parsed.parse_failed = false;
84+
} else {
85+
throwErr("URL parsing failed.");
86+
}
87+
}
88+
89+
return parsed;
90+
};
91+
92+
parseUrl.MAX_INPUT_LENGTH = 2048;
93+
94+
module.exports = parseUrl;

dist/index.mjs

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import parsePath from 'parse-path';
2+
import normalizeUrl from 'normalize-url';
3+
4+
// Dependencies
5+
6+
/**
7+
* parseUrl
8+
* Parses the input url.
9+
*
10+
* **Note**: This *throws* if invalid urls are provided.
11+
*
12+
* @name parseUrl
13+
* @function
14+
* @param {String} url The input url.
15+
* @param {Boolean|Object} normalize Whether to normalize the url or not.
16+
* Default is `false`. If `true`, the url will
17+
* be normalized. If an object, it will be the
18+
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
19+
*
20+
* For SSH urls, normalize won't work.
21+
*
22+
* @return {Object} An object containing the following fields:
23+
*
24+
* - `protocols` (Array): An array with the url protocols (usually it has one element).
25+
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
26+
* - `port` (null|Number): The domain port.
27+
* - `resource` (String): The url domain (including subdomains).
28+
* - `user` (String): The authentication user (usually for ssh urls).
29+
* - `pathname` (String): The url pathname.
30+
* - `hash` (String): The url hash.
31+
* - `search` (String): The url querystring value.
32+
* - `href` (String): The input url.
33+
* - `query` (Object): The url querystring, parsed as object.
34+
* - `parse_failed` (Boolean): Whether the parsing failed or not.
35+
*/
36+
const parseUrl = (url, normalize = false) => {
37+
38+
// Constants
39+
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;
40+
41+
const throwErr = msg => {
42+
const err = new Error(msg);
43+
err.subject_url = url;
44+
throw err
45+
};
46+
47+
if (typeof url !== "string" || !url.trim()) {
48+
throwErr("Invalid url.");
49+
}
50+
51+
if (url.length > parseUrl.MAX_INPUT_LENGTH) {
52+
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
53+
}
54+
55+
if (normalize) {
56+
if (typeof normalize !== "object") {
57+
normalize = {
58+
stripHash: false
59+
};
60+
}
61+
url = normalizeUrl(url, normalize);
62+
}
63+
64+
const parsed = parsePath(url);
65+
66+
// Potential git-ssh urls
67+
if (parsed.parse_failed) {
68+
const matched = parsed.href.match(GIT_RE);
69+
if (matched) {
70+
parsed.protocols = ["ssh"];
71+
parsed.protocol = "ssh";
72+
parsed.resource = matched[4];
73+
parsed.host = matched[4];
74+
parsed.user = "git";
75+
parsed.pathname = `/${matched[6]}`;
76+
parsed.parse_failed = false;
77+
} else {
78+
throwErr("URL parsing failed.");
79+
}
80+
}
81+
82+
return parsed;
83+
};
84+
85+
parseUrl.MAX_INPUT_LENGTH = 2048;
86+
87+
export { parseUrl as default };

0 commit comments

Comments
 (0)