quasiurl 1.1.9 → 1.1.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # QuasiURL
2
2
 
3
- *`URL`-like object for templated URLs*
3
+ *`URL`-like object for URL templates*
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/quasiurl?labelColor=345&color=46e)](https://www.npmjs.com/package/quasiurl) ![Lightweight](https://img.shields.io/bundlephobia/minzip/quasiurl?label=minzip&labelColor=345&color=46e)
6
6
 
package/dist/index.cjs CHANGED
@@ -1,91 +1,90 @@
1
-
2
- //#region index.ts
3
1
  /**
4
- * Unlike URL, QuasiURL:
2
+ * `URL`-like object for URL templates.
3
+ *
4
+ * Unlike `URL`, `QuasiURL`:
5
5
  * - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
6
6
  * - preserves templating characters without URL-encoding them.
7
7
  */
8
8
  var QuasiURL = class {
9
- _protocol = "";
10
- _hostname = "";
11
- _port = "";
12
- _pathname = "";
13
- _search = "";
14
- _hash = "";
15
- constructor(url) {
16
- this.href = url;
17
- }
18
- get href() {
19
- return `${this.origin}${this.pathname}${this.search}${this.hash}`;
20
- }
21
- set href(value) {
22
- let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
23
- let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
24
- this.origin = origin;
25
- this.pathname = tail[1] ?? "";
26
- this.search = tail[2] ?? "";
27
- this.hash = tail[3] ?? "";
28
- }
29
- get protocol() {
30
- return this._protocol;
31
- }
32
- set protocol(value) {
33
- if (!value || /^\w+:$/.test(value)) this._protocol = value;
34
- }
35
- get hostname() {
36
- return this._hostname;
37
- }
38
- set hostname(value) {
39
- if (!value.includes("/")) this._hostname = value;
40
- }
41
- get port() {
42
- return this._port;
43
- }
44
- set port(value) {
45
- let s = String(value);
46
- if (!s || /^\d+$/.test(s)) this._port = s;
47
- }
48
- get host() {
49
- return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
50
- }
51
- set host(value) {
52
- let [hostname, port = ""] = value.split(":");
53
- this.hostname = hostname;
54
- this.port = port;
55
- }
56
- get origin() {
57
- if (!this.protocol && !this.host) return "";
58
- return `${this.protocol}//${this.host}`;
59
- }
60
- set origin(value) {
61
- let [protocol, host = ""] = value.split("//");
62
- this.protocol = protocol;
63
- this.host = host;
64
- }
65
- get pathname() {
66
- let p = this._pathname;
67
- return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
68
- }
69
- set pathname(value) {
70
- this._pathname = value;
71
- }
72
- get search() {
73
- return this._search && `?${this._search}`;
74
- }
75
- set search(value) {
76
- let s = String(value);
77
- this._search = s.startsWith("?") ? s.slice(1) : s;
78
- }
79
- get hash() {
80
- return this._hash && `#${this._hash}`;
81
- }
82
- set hash(value) {
83
- this._hash = value.startsWith("#") ? value.slice(1) : value;
84
- }
85
- toString() {
86
- return this.href;
87
- }
9
+ _protocol = "";
10
+ _hostname = "";
11
+ _port = "";
12
+ _pathname = "";
13
+ _search = "";
14
+ _hash = "";
15
+ constructor(url) {
16
+ this.href = url;
17
+ }
18
+ get href() {
19
+ return `${this.origin}${this.pathname}${this.search}${this.hash}`;
20
+ }
21
+ set href(value) {
22
+ let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
23
+ let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
24
+ this.origin = origin;
25
+ this.pathname = tail[1] ?? "";
26
+ this.search = tail[2] ?? "";
27
+ this.hash = tail[3] ?? "";
28
+ }
29
+ get protocol() {
30
+ return this._protocol;
31
+ }
32
+ set protocol(value) {
33
+ if (!value || /^\w+:$/.test(value)) this._protocol = value;
34
+ }
35
+ get hostname() {
36
+ return this._hostname;
37
+ }
38
+ set hostname(value) {
39
+ if (!value.includes("/")) this._hostname = value;
40
+ }
41
+ get port() {
42
+ return this._port;
43
+ }
44
+ set port(value) {
45
+ let s = String(value);
46
+ if (!s || /^\d+$/.test(s)) this._port = s;
47
+ }
48
+ get host() {
49
+ return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
50
+ }
51
+ set host(value) {
52
+ let [hostname, port = ""] = value.split(":");
53
+ this.hostname = hostname;
54
+ this.port = port;
55
+ }
56
+ get origin() {
57
+ if (!this.protocol && !this.host) return "";
58
+ return `${this.protocol}//${this.host}`;
59
+ }
60
+ set origin(value) {
61
+ let [protocol, host = ""] = value.split("//");
62
+ this.protocol = protocol;
63
+ this.host = host;
64
+ }
65
+ get pathname() {
66
+ let p = this._pathname;
67
+ return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
68
+ }
69
+ set pathname(value) {
70
+ this._pathname = value;
71
+ }
72
+ get search() {
73
+ return this._search && `?${this._search}`;
74
+ }
75
+ set search(value) {
76
+ let s = String(value);
77
+ this._search = s.startsWith("?") ? s.slice(1) : s;
78
+ }
79
+ get hash() {
80
+ return this._hash && `#${this._hash}`;
81
+ }
82
+ set hash(value) {
83
+ this._hash = value.startsWith("#") ? value.slice(1) : value;
84
+ }
85
+ toString() {
86
+ return this.href;
87
+ }
88
88
  };
89
89
 
90
- //#endregion
91
- exports.QuasiURL = QuasiURL;
90
+ exports.QuasiURL = QuasiURL;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /**
2
- * Unlike URL, QuasiURL:
2
+ * `URL`-like object for URL templates.
3
+ *
4
+ * Unlike `URL`, `QuasiURL`:
3
5
  * - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
4
6
  * - preserves templating characters without URL-encoding them.
5
7
  */
package/dist/index.mjs CHANGED
@@ -1,90 +1,90 @@
1
- //#region index.ts
2
1
  /**
3
- * Unlike URL, QuasiURL:
2
+ * `URL`-like object for URL templates.
3
+ *
4
+ * Unlike `URL`, `QuasiURL`:
4
5
  * - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
5
6
  * - preserves templating characters without URL-encoding them.
6
7
  */
7
8
  var QuasiURL = class {
8
- _protocol = "";
9
- _hostname = "";
10
- _port = "";
11
- _pathname = "";
12
- _search = "";
13
- _hash = "";
14
- constructor(url) {
15
- this.href = url;
16
- }
17
- get href() {
18
- return `${this.origin}${this.pathname}${this.search}${this.hash}`;
19
- }
20
- set href(value) {
21
- let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
22
- let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
23
- this.origin = origin;
24
- this.pathname = tail[1] ?? "";
25
- this.search = tail[2] ?? "";
26
- this.hash = tail[3] ?? "";
27
- }
28
- get protocol() {
29
- return this._protocol;
30
- }
31
- set protocol(value) {
32
- if (!value || /^\w+:$/.test(value)) this._protocol = value;
33
- }
34
- get hostname() {
35
- return this._hostname;
36
- }
37
- set hostname(value) {
38
- if (!value.includes("/")) this._hostname = value;
39
- }
40
- get port() {
41
- return this._port;
42
- }
43
- set port(value) {
44
- let s = String(value);
45
- if (!s || /^\d+$/.test(s)) this._port = s;
46
- }
47
- get host() {
48
- return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
49
- }
50
- set host(value) {
51
- let [hostname, port = ""] = value.split(":");
52
- this.hostname = hostname;
53
- this.port = port;
54
- }
55
- get origin() {
56
- if (!this.protocol && !this.host) return "";
57
- return `${this.protocol}//${this.host}`;
58
- }
59
- set origin(value) {
60
- let [protocol, host = ""] = value.split("//");
61
- this.protocol = protocol;
62
- this.host = host;
63
- }
64
- get pathname() {
65
- let p = this._pathname;
66
- return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
67
- }
68
- set pathname(value) {
69
- this._pathname = value;
70
- }
71
- get search() {
72
- return this._search && `?${this._search}`;
73
- }
74
- set search(value) {
75
- let s = String(value);
76
- this._search = s.startsWith("?") ? s.slice(1) : s;
77
- }
78
- get hash() {
79
- return this._hash && `#${this._hash}`;
80
- }
81
- set hash(value) {
82
- this._hash = value.startsWith("#") ? value.slice(1) : value;
83
- }
84
- toString() {
85
- return this.href;
86
- }
9
+ _protocol = "";
10
+ _hostname = "";
11
+ _port = "";
12
+ _pathname = "";
13
+ _search = "";
14
+ _hash = "";
15
+ constructor(url) {
16
+ this.href = url;
17
+ }
18
+ get href() {
19
+ return `${this.origin}${this.pathname}${this.search}${this.hash}`;
20
+ }
21
+ set href(value) {
22
+ let origin = value.match(/^(\w+:)?\/\/[^/:]+(:\d+)?/)?.[0] ?? "";
23
+ let tail = value.slice(origin.length).match(/^([^?#]+)?(\?[^#]+)?(#.+)?$/) ?? [];
24
+ this.origin = origin;
25
+ this.pathname = tail[1] ?? "";
26
+ this.search = tail[2] ?? "";
27
+ this.hash = tail[3] ?? "";
28
+ }
29
+ get protocol() {
30
+ return this._protocol;
31
+ }
32
+ set protocol(value) {
33
+ if (!value || /^\w+:$/.test(value)) this._protocol = value;
34
+ }
35
+ get hostname() {
36
+ return this._hostname;
37
+ }
38
+ set hostname(value) {
39
+ if (!value.includes("/")) this._hostname = value;
40
+ }
41
+ get port() {
42
+ return this._port;
43
+ }
44
+ set port(value) {
45
+ let s = String(value);
46
+ if (!s || /^\d+$/.test(s)) this._port = s;
47
+ }
48
+ get host() {
49
+ return `${this.hostname}${this.port ? `:${this.port}` : ""}`;
50
+ }
51
+ set host(value) {
52
+ let [hostname, port = ""] = value.split(":");
53
+ this.hostname = hostname;
54
+ this.port = port;
55
+ }
56
+ get origin() {
57
+ if (!this.protocol && !this.host) return "";
58
+ return `${this.protocol}//${this.host}`;
59
+ }
60
+ set origin(value) {
61
+ let [protocol, host = ""] = value.split("//");
62
+ this.protocol = protocol;
63
+ this.host = host;
64
+ }
65
+ get pathname() {
66
+ let p = this._pathname;
67
+ return `${p.startsWith("/") || p.startsWith("{/") ? "" : "/"}${p}`;
68
+ }
69
+ set pathname(value) {
70
+ this._pathname = value;
71
+ }
72
+ get search() {
73
+ return this._search && `?${this._search}`;
74
+ }
75
+ set search(value) {
76
+ let s = String(value);
77
+ this._search = s.startsWith("?") ? s.slice(1) : s;
78
+ }
79
+ get hash() {
80
+ return this._hash && `#${this._hash}`;
81
+ }
82
+ set hash(value) {
83
+ this._hash = value.startsWith("#") ? value.slice(1) : value;
84
+ }
85
+ toString() {
86
+ return this.href;
87
+ }
87
88
  };
88
89
 
89
- //#endregion
90
- export { QuasiURL };
90
+ export { QuasiURL };
package/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /**
2
- * Unlike URL, QuasiURL:
2
+ * `URL`-like object for URL templates.
3
+ *
4
+ * Unlike `URL`, `QuasiURL`:
3
5
  * - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
4
6
  * - preserves templating characters without URL-encoding them.
5
7
  */
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "quasiurl",
3
- "version": "1.1.9",
4
- "description": "URL for templating",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
- "scripts": {
10
- "preversion": "npx npm-run-all shape test",
11
- "shape": "npx codeshape",
12
- "test": "node tests.ts"
13
- },
14
- "author": "axtk",
15
- "license": "MIT",
16
- "repository": {
17
- "type": "git",
18
- "url": "git://github.com/t8js/quasiurl.git"
19
- },
20
- "keywords": [
21
- "url",
22
- "template"
23
- ],
24
- "devDependencies": {
25
- "@types/node": "^24.0.4"
26
- }
27
- }
1
+ {
2
+ "name": "quasiurl",
3
+ "version": "1.1.10",
4
+ "description": "URL-like object for URL templates",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "scripts": {
10
+ "preversion": "npx npm-run-all shape test",
11
+ "shape": "npx codeshape",
12
+ "test": "node tests.ts"
13
+ },
14
+ "author": "axtk",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/t8js/quasiurl.git"
19
+ },
20
+ "keywords": [
21
+ "url",
22
+ "template"
23
+ ],
24
+ "devDependencies": {
25
+ "@types/node": "^24.0.4"
26
+ }
27
+ }