quasiurl 1.1.8 → 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 ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `URL`-like object for URL templates.
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
+ exports.QuasiURL = QuasiURL;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
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
  */
6
- export declare class QuasiURL {
8
+ declare class QuasiURL {
7
9
  _protocol: string;
8
10
  _hostname: string;
9
11
  _port: string;
@@ -32,4 +34,4 @@ export declare class QuasiURL {
32
34
  toString(): string;
33
35
  }
34
36
 
35
- export {};
37
+ export { QuasiURL };
@@ -1,4 +1,10 @@
1
- // index.ts
1
+ /**
2
+ * `URL`-like object for URL templates.
3
+ *
4
+ * Unlike `URL`, `QuasiURL`:
5
+ * - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
6
+ * - preserves templating characters without URL-encoding them.
7
+ */
2
8
  var QuasiURL = class {
3
9
  _protocol = "";
4
10
  _hostname = "";
@@ -80,6 +86,5 @@ var QuasiURL = class {
80
86
  return this.href;
81
87
  }
82
88
  };
83
- export {
84
- QuasiURL
85
- };
89
+
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,28 +1,27 @@
1
- {
2
- "name": "quasiurl",
3
- "version": "1.1.8",
4
- "description": "URL for templating",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
10
- "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral",
11
- "preversion": "npx npm-run-all clean shape compile test",
12
- "shape": "npx codeshape --typecheck --emit-types",
13
- "test": "node tests.ts"
14
- },
15
- "author": "axtk",
16
- "license": "MIT",
17
- "repository": {
18
- "type": "git",
19
- "url": "git://github.com/t8js/quasiurl.git"
20
- },
21
- "keywords": [
22
- "url",
23
- "template"
24
- ],
25
- "devDependencies": {
26
- "@types/node": "^24.0.4"
27
- }
28
- }
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
+ }