quasiurl 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +85 -85
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +85 -84
- package/index.ts +5 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# QuasiURL
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`URL`-like object applicable to partial URLs and URL templates
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/quasiurl) 
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
//#region index.ts
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* `URL`-like object applicable to partial URLs and URL templates.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `URL`, `QuasiURL`:
|
|
5
5
|
* - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
|
|
6
|
-
* - preserves templating characters without URL-encoding them
|
|
6
|
+
* - preserves templating characters without URL-encoding them;
|
|
7
|
+
* - doesn't implement the entire `URL` spec.
|
|
7
8
|
*/
|
|
8
9
|
var QuasiURL = class {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
10
|
+
_protocol = "";
|
|
11
|
+
_hostname = "";
|
|
12
|
+
_port = "";
|
|
13
|
+
_pathname = "";
|
|
14
|
+
_search = "";
|
|
15
|
+
_hash = "";
|
|
16
|
+
constructor(url) {
|
|
17
|
+
this.href = url;
|
|
18
|
+
}
|
|
19
|
+
get href() {
|
|
20
|
+
return `${this.origin}${this.pathname}${this.search}${this.hash}`;
|
|
21
|
+
}
|
|
22
|
+
set href(value) {
|
|
23
|
+
let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
|
|
24
|
+
let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
|
|
25
|
+
this.origin = origin;
|
|
26
|
+
this.pathname = tail[1] ?? "";
|
|
27
|
+
this.search = tail[2] ?? "";
|
|
28
|
+
this.hash = tail[3] ?? "";
|
|
29
|
+
}
|
|
30
|
+
get protocol() {
|
|
31
|
+
return this._protocol;
|
|
32
|
+
}
|
|
33
|
+
set protocol(value) {
|
|
34
|
+
if (!value || /^\w+:$/.test(value)) this._protocol = value;
|
|
35
|
+
}
|
|
36
|
+
get hostname() {
|
|
37
|
+
return this._hostname;
|
|
38
|
+
}
|
|
39
|
+
set hostname(value) {
|
|
40
|
+
if (!value.includes("/")) this._hostname = value;
|
|
41
|
+
}
|
|
42
|
+
get port() {
|
|
43
|
+
return this._port;
|
|
44
|
+
}
|
|
45
|
+
set port(value) {
|
|
46
|
+
let s = String(value);
|
|
47
|
+
if (!s || /^\d+$/.test(s)) this._port = s;
|
|
48
|
+
}
|
|
49
|
+
get host() {
|
|
50
|
+
return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
|
|
51
|
+
}
|
|
52
|
+
set host(value) {
|
|
53
|
+
let [hostname, port = ""] = value.split(":");
|
|
54
|
+
this.hostname = hostname;
|
|
55
|
+
this.port = port;
|
|
56
|
+
}
|
|
57
|
+
get origin() {
|
|
58
|
+
if (!this.protocol && !this.host) return "";
|
|
59
|
+
return `${this.protocol}//${this.host}`;
|
|
60
|
+
}
|
|
61
|
+
set origin(value) {
|
|
62
|
+
let [protocol, host = ""] = value.split("//");
|
|
63
|
+
this.protocol = protocol;
|
|
64
|
+
this.host = host;
|
|
65
|
+
}
|
|
66
|
+
get pathname() {
|
|
67
|
+
let p = this._pathname;
|
|
68
|
+
return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
|
|
69
|
+
}
|
|
70
|
+
set pathname(value) {
|
|
71
|
+
this._pathname = value;
|
|
72
|
+
}
|
|
73
|
+
get search() {
|
|
74
|
+
return this._search && `?${this._search}`;
|
|
75
|
+
}
|
|
76
|
+
set search(value) {
|
|
77
|
+
let s = String(value);
|
|
78
|
+
this._search = s.startsWith("?") ? s.slice(1) : s;
|
|
79
|
+
}
|
|
80
|
+
get hash() {
|
|
81
|
+
return this._hash && `#${this._hash}`;
|
|
82
|
+
}
|
|
83
|
+
set hash(value) {
|
|
84
|
+
this._hash = value.startsWith("#") ? value.slice(1) : value;
|
|
85
|
+
}
|
|
86
|
+
toString() {
|
|
87
|
+
return this.href;
|
|
88
|
+
}
|
|
88
89
|
};
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
exports.QuasiURL = QuasiURL;
|
|
91
|
+
exports.QuasiURL = QuasiURL;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `URL`-like object applicable to partial URLs and URL templates.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `URL`, `QuasiURL`:
|
|
3
5
|
* - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
|
|
4
|
-
* - preserves templating characters without URL-encoding them
|
|
6
|
+
* - preserves templating characters without URL-encoding them;
|
|
7
|
+
* - doesn't implement the entire `URL` spec.
|
|
5
8
|
*/
|
|
6
9
|
declare class QuasiURL {
|
|
7
10
|
_protocol: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
|
-
//#region index.ts
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* `URL`-like object applicable to partial URLs and URL templates.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `URL`, `QuasiURL`:
|
|
4
5
|
* - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
|
|
5
|
-
* - preserves templating characters without URL-encoding them
|
|
6
|
+
* - preserves templating characters without URL-encoding them;
|
|
7
|
+
* - doesn't implement the entire `URL` spec.
|
|
6
8
|
*/
|
|
7
9
|
var QuasiURL = class {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
10
|
+
_protocol = "";
|
|
11
|
+
_hostname = "";
|
|
12
|
+
_port = "";
|
|
13
|
+
_pathname = "";
|
|
14
|
+
_search = "";
|
|
15
|
+
_hash = "";
|
|
16
|
+
constructor(url) {
|
|
17
|
+
this.href = url;
|
|
18
|
+
}
|
|
19
|
+
get href() {
|
|
20
|
+
return `${this.origin}${this.pathname}${this.search}${this.hash}`;
|
|
21
|
+
}
|
|
22
|
+
set href(value) {
|
|
23
|
+
let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
|
|
24
|
+
let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
|
|
25
|
+
this.origin = origin;
|
|
26
|
+
this.pathname = tail[1] ?? "";
|
|
27
|
+
this.search = tail[2] ?? "";
|
|
28
|
+
this.hash = tail[3] ?? "";
|
|
29
|
+
}
|
|
30
|
+
get protocol() {
|
|
31
|
+
return this._protocol;
|
|
32
|
+
}
|
|
33
|
+
set protocol(value) {
|
|
34
|
+
if (!value || /^\w+:$/.test(value)) this._protocol = value;
|
|
35
|
+
}
|
|
36
|
+
get hostname() {
|
|
37
|
+
return this._hostname;
|
|
38
|
+
}
|
|
39
|
+
set hostname(value) {
|
|
40
|
+
if (!value.includes("/")) this._hostname = value;
|
|
41
|
+
}
|
|
42
|
+
get port() {
|
|
43
|
+
return this._port;
|
|
44
|
+
}
|
|
45
|
+
set port(value) {
|
|
46
|
+
let s = String(value);
|
|
47
|
+
if (!s || /^\d+$/.test(s)) this._port = s;
|
|
48
|
+
}
|
|
49
|
+
get host() {
|
|
50
|
+
return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
|
|
51
|
+
}
|
|
52
|
+
set host(value) {
|
|
53
|
+
let [hostname, port = ""] = value.split(":");
|
|
54
|
+
this.hostname = hostname;
|
|
55
|
+
this.port = port;
|
|
56
|
+
}
|
|
57
|
+
get origin() {
|
|
58
|
+
if (!this.protocol && !this.host) return "";
|
|
59
|
+
return `${this.protocol}//${this.host}`;
|
|
60
|
+
}
|
|
61
|
+
set origin(value) {
|
|
62
|
+
let [protocol, host = ""] = value.split("//");
|
|
63
|
+
this.protocol = protocol;
|
|
64
|
+
this.host = host;
|
|
65
|
+
}
|
|
66
|
+
get pathname() {
|
|
67
|
+
let p = this._pathname;
|
|
68
|
+
return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
|
|
69
|
+
}
|
|
70
|
+
set pathname(value) {
|
|
71
|
+
this._pathname = value;
|
|
72
|
+
}
|
|
73
|
+
get search() {
|
|
74
|
+
return this._search && `?${this._search}`;
|
|
75
|
+
}
|
|
76
|
+
set search(value) {
|
|
77
|
+
let s = String(value);
|
|
78
|
+
this._search = s.startsWith("?") ? s.slice(1) : s;
|
|
79
|
+
}
|
|
80
|
+
get hash() {
|
|
81
|
+
return this._hash && `#${this._hash}`;
|
|
82
|
+
}
|
|
83
|
+
set hash(value) {
|
|
84
|
+
this._hash = value.startsWith("#") ? value.slice(1) : value;
|
|
85
|
+
}
|
|
86
|
+
toString() {
|
|
87
|
+
return this.href;
|
|
88
|
+
}
|
|
87
89
|
};
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
export { QuasiURL };
|
|
91
|
+
export { QuasiURL };
|
package/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `URL`-like object applicable to partial URLs and URL templates.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `URL`, `QuasiURL`:
|
|
3
5
|
* - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
|
|
4
|
-
* - preserves templating characters without URL-encoding them
|
|
6
|
+
* - preserves templating characters without URL-encoding them;
|
|
7
|
+
* - doesn't implement the entire `URL` spec.
|
|
5
8
|
*/
|
|
6
9
|
export class QuasiURL {
|
|
7
10
|
_protocol = "";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quasiurl",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "URL
|
|
3
|
+
"version": "1.1.11",
|
|
4
|
+
"description": "URL-like object applicable to partial URLs and URL templates",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"url",
|
|
22
|
-
"
|
|
22
|
+
"partial url",
|
|
23
|
+
"url template"
|
|
23
24
|
],
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/node": "^24.0.4"
|