quasiurl 1.1.7 → 1.1.9

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