Skip to content

Commit eebc0cc

Browse files
committed
Docs 📝 .
1 parent 3113645 commit eebc0cc

File tree

7 files changed

+138
-8
lines changed

7 files changed

+138
-8
lines changed

DOCUMENTATION.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,32 @@
22

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

5+
### `parseUrl(url, normalize)`
6+
Parses the input url.
7+
8+
**Note**: This *throws* if invalid urls are provided.
9+
10+
#### Params
11+
12+
- **String** `url`: The input url.
13+
- **Boolean|Object** `normalize`: Whether to normalize the url or not. Default is `false`. If `true`, the url will
14+
be normalized. If an object, it will be the
15+
options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
16+
17+
For SSH urls, normalize won't work.
18+
19+
#### Return
20+
- **Object** An object containing the following fields:
21+
- `protocols` (Array): An array with the url protocols (usually it has one element).
22+
- `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
23+
- `port` (String): The domain port.
24+
- `resource` (String): The url domain (including subdomains).
25+
- `host` (String): The fully qualified domain name of a network host, or its IP address.
26+
- `user` (String): The authentication user (usually for ssh urls).
27+
- `pathname` (String): The url pathname.
28+
- `hash` (String): The url hash.
29+
- `search` (String): The url querystring value.
30+
- `href` (String): The input url.
31+
- `query` (Object): The url querystring, parsed as object.
32+
- `parse_failed` (Boolean): Whether the parsing failed or not.
33+

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838

39-
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.
39+
For low-level path parsing, check out [`parse-path`](https://github.com/IonicaBizau/parse-path). This very module is designed to parse urls.
4040

4141

4242

@@ -151,6 +151,40 @@ console.log(parseUrl("git@github.com:IonicaBizau/git-stats.git", false))
151151

152152

153153

154+
## :memo: Documentation
155+
156+
157+
### `parseUrl(url, normalize)`
158+
Parses the input url.
159+
160+
**Note**: This *throws* if invalid urls are provided.
161+
162+
#### Params
163+
164+
- **String** `url`: The input url.
165+
- **Boolean|Object** `normalize`: Whether to normalize the url or not. Default is `false`. If `true`, the url will
166+
be normalized. If an object, it will be the
167+
options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
168+
169+
For SSH urls, normalize won't work.
170+
171+
#### Return
172+
- **Object** An object containing the following fields:
173+
- `protocols` (Array): An array with the url protocols (usually it has one element).
174+
- `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
175+
- `port` (String): The domain port.
176+
- `resource` (String): The url domain (including subdomains).
177+
- `host` (String): The fully qualified domain name of a network host, or its IP address.
178+
- `user` (String): The authentication user (usually for ssh urls).
179+
- `pathname` (String): The url pathname.
180+
- `hash` (String): The url hash.
181+
- `search` (String): The url querystring value.
182+
- `href` (String): The input url.
183+
- `query` (Object): The url querystring, parsed as object.
184+
- `parse_failed` (Boolean): Whether the parsing failed or not.
185+
186+
187+
154188

155189

156190

dist/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,37 @@ function normalizeUrl(urlString, options) {
195195
return urlString;
196196
}
197197

198+
/**
199+
* parseUrl
200+
* Parses the input url.
201+
*
202+
* **Note**: This *throws* if invalid urls are provided.
203+
*
204+
* @name parseUrl
205+
* @function
206+
* @param {String} url The input url.
207+
* @param {Boolean|Object} normalize Whether to normalize the url or not.
208+
* Default is `false`. If `true`, the url will
209+
* be normalized. If an object, it will be the
210+
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
211+
*
212+
* For SSH urls, normalize won't work.
213+
*
214+
* @return {Object} An object containing the following fields:
215+
*
216+
* - `protocols` (Array): An array with the url protocols (usually it has one element).
217+
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
218+
* - `port` (String): The domain port.
219+
* - `resource` (String): The url domain (including subdomains).
220+
* - `host` (String): The fully qualified domain name of a network host, or its IP address.
221+
* - `user` (String): The authentication user (usually for ssh urls).
222+
* - `pathname` (String): The url pathname.
223+
* - `hash` (String): The url hash.
224+
* - `search` (String): The url querystring value.
225+
* - `href` (String): The input url.
226+
* - `query` (Object): The url querystring, parsed as object.
227+
* - `parse_failed` (Boolean): Whether the parsing failed or not.
228+
*/
198229
const parseUrl = (url, normalize = false) => {
199230
const GIT_RE = /^(?:([a-zA-Z_][a-zA-Z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
200231
const throwErr = (msg) => {

dist/index.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,37 @@ function normalizeUrl(urlString, options) {
193193
return urlString;
194194
}
195195

196+
/*!
197+
* parseUrl
198+
* Parses the input url.
199+
*
200+
* **Note**: This *throws* if invalid urls are provided.
201+
*
202+
* @name parseUrl
203+
* @function
204+
* @param {String} url The input url.
205+
* @param {Boolean|Object} normalize Whether to normalize the url or not.
206+
* Default is `false`. If `true`, the url will
207+
* be normalized. If an object, it will be the
208+
* options object sent to [`normalize-url`](https://github.com/sindresorhus/normalize-url).
209+
*
210+
* For SSH urls, normalize won't work.
211+
*
212+
* @return {Object} An object containing the following fields:
213+
*
214+
* - `protocols` (Array): An array with the url protocols (usually it has one element).
215+
* - `protocol` (String): The first protocol, `"ssh"` (if the url is a ssh url) or `"file"`.
216+
* - `port` (String): The domain port.
217+
* - `resource` (String): The url domain (including subdomains).
218+
* - `host` (String): The fully qualified domain name of a network host, or its IP address.
219+
* - `user` (String): The authentication user (usually for ssh urls).
220+
* - `pathname` (String): The url pathname.
221+
* - `hash` (String): The url hash.
222+
* - `search` (String): The url querystring value.
223+
* - `href` (String): The input url.
224+
* - `query` (Object): The url querystring, parsed as object.
225+
* - `parse_failed` (Boolean): Whether the parsing failed or not.
226+
*/
196227
const parseUrl = (url, normalize = false) => {
197228
const GIT_RE = /^(?:([a-zA-Z_][a-zA-Z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
198229
const throwErr = (msg) => {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@
7272
},
7373
"blah": {
7474
"description": [
75-
"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."
75+
"For low-level path parsing, check out [`parse-path`](https://github.com/IonicaBizau/parse-path). This very module is designed to parse urls."
7676
]
7777
},
7878
"tsd": {
7979
"directory": "test"
80+
},
81+
"pkgroll": {
82+
"esbuildOptions": {
83+
"legalComments": "inline"
84+
}
8085
}
81-
}
86+
}

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import normalizeUrl from "normalize-url";
44
import parsePath from "parse-path";
55

6-
/**
6+
/*!
77
* parseUrl
88
* Parses the input url.
99
*
@@ -40,10 +40,10 @@ const parseUrl = (url, normalize = false) => {
4040
/**
4141
* ([a-zA-Z_][a-zA-Z0-9_-]{0,31}) Try to match the user
4242
* ([\w\.\-@]+) Match the host/resource
43-
* (([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?) Match the path, allowing spaces/white
43+
* (([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?) Match the path, allowing spaces/white
4444
*/
4545
const GIT_RE = /^(?:([a-zA-Z_][a-zA-Z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
46-
46+
4747
const throwErr = msg => {
4848
const err = new Error(msg)
4949
err.subject_url = url

0 commit comments

Comments
 (0)