quasiurl 1.0.1 → 1.0.2

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
@@ -6,3 +6,17 @@ Unlike `URL`, `QuasiURL`:
6
6
  - can have an empty `origin`, `pathname`, `hostname`, `protocol`;
7
7
  - preserves templating characters without URL-encoding them;
8
8
  - doesn't implement the entire `URL` spec.
9
+
10
+ ```
11
+ new URL("/x").href
12
+ > TypeError: URL constructor: /x is not a valid URL.
13
+
14
+ new QuasiURL("/x").href
15
+ > "/x"
16
+
17
+ new URL("https://a.aa/x{/:name}").pathname
18
+ > "/x%7B/:name%7D"
19
+
20
+ new QuasiURL("https://a.aa/x{/:name}").pathname
21
+ > "/x{/:name}"
22
+ ```
package/dist/tests.js CHANGED
@@ -44,7 +44,15 @@ function createQuasiURL(url2) {
44
44
  ${JSON.stringify(url2)}`);
45
45
  return new QuasiURL(url2);
46
46
  }
47
- var url = createQuasiURL("/sections/:id");
47
+ var url = createQuasiURL("/x");
48
+ assert(url.origin === "");
49
+ assert(url.pathname === "/x");
50
+ assert(url.search === "");
51
+ assert(url.hash === "");
52
+ assert(url.href === "/x");
53
+ assert(url.hostname === "");
54
+ assert(url.protocol === "");
55
+ url = createQuasiURL("/sections/:id");
48
56
  assert(url.origin === "");
49
57
  assert(url.pathname === "/sections/:id");
50
58
  assert(url.search === "");
@@ -60,6 +68,14 @@ assert(url.hash === "");
60
68
  assert(url.href === "/x{/:name}");
61
69
  assert(url.hostname === "");
62
70
  assert(url.protocol === "");
71
+ url = createQuasiURL("https://a.aa/x{/:name}");
72
+ assert(url.origin === "https://a.aa");
73
+ assert(url.pathname === "/x{/:name}");
74
+ assert(url.search === "");
75
+ assert(url.hash === "");
76
+ assert(url.href === "https://a.aa/x{/:name}");
77
+ assert(url.hostname === "a.aa");
78
+ assert(url.protocol === "https:");
63
79
  url = createQuasiURL("/x?a=1&b=nnn#start");
64
80
  assert(url.origin === "");
65
81
  assert(url.pathname === "/x");
package/index.ts CHANGED
@@ -4,36 +4,36 @@
4
4
  * - preserves templating characters without URL-encoding them.
5
5
  */
6
6
  export class QuasiURL {
7
- hash: string;
8
- hostname: string;
9
- href: string;
10
- origin: string;
11
- pathname: string;
12
- protocol: string;
13
- search: string;
7
+ hash: string;
8
+ hostname: string;
9
+ href: string;
10
+ origin: string;
11
+ pathname: string;
12
+ protocol: string;
13
+ search: string;
14
14
 
15
- constructor(url: string) {
16
- let head = url.match(/^((\w+:)?\/\/([^/]+))(\/.*|$)/);
17
- let tail = url.match(/(\?[^#]+)(#.+)?$/);
15
+ constructor(url: string) {
16
+ let head = url.match(/^((\w+:)?\/\/([^/]+))(\/.*|$)/);
17
+ let tail = url.match(/(\?[^#]+)(#.+)?$/);
18
18
 
19
- let origin = head?.[1] ?? '';
20
- let pathname = url
21
- .replace(/^((\w+:)?\/\/[^/]+)/, '')
22
- .replace(/\?.*$/, '')
23
- .replace(/#.*$/, '');
24
- let search = tail?.[1] ?? '';
25
- let hash = tail?.[2] ?? '';
19
+ let origin = head?.[1] ?? "";
20
+ let pathname = url
21
+ .replace(/^((\w+:)?\/\/[^/]+)/, "")
22
+ .replace(/\?.*$/, "")
23
+ .replace(/#.*$/, "");
24
+ let search = tail?.[1] ?? "";
25
+ let hash = tail?.[2] ?? "";
26
26
 
27
- this.origin = origin;
28
- this.pathname = pathname;
29
- this.search = search;
30
- this.hash = hash;
27
+ this.origin = origin;
28
+ this.pathname = pathname;
29
+ this.search = search;
30
+ this.hash = hash;
31
31
 
32
- this.href = `${origin}${pathname}${search}${hash}`;
33
- this.hostname = head?.[3] ?? '';
34
- this.protocol = head?.[2] ?? '';
35
- }
36
- toString() {
37
- return this.href;
38
- }
32
+ this.href = `${origin}${pathname}${search}${hash}`;
33
+ this.hostname = head?.[3] ?? "";
34
+ this.protocol = head?.[2] ?? "";
35
+ }
36
+ toString() {
37
+ return this.href;
38
+ }
39
39
  }
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "name": "quasiurl",
3
- "version": "1.0.1",
4
- "description": "URL for templating",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "scripts": {
8
- "build": "npx npm-run-all clean -p compile compile-tests",
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
- "compile-tests": "npx esbuild tests.ts --bundle --outdir=dist --platform=neutral",
12
- "prepublishOnly": "npm run build",
13
- "preversion": "npx npm-run-all typecheck shape build test",
14
- "shape": "npx codeshape",
15
- "test": "node dist/tests.js",
16
- "typecheck": "tsc --noEmit"
17
- },
18
- "author": "axtk",
19
- "license": "ISC",
20
- "repository": {
21
- "type": "git",
22
- "url": "git://github.com/axtk/quasiurl.git"
23
- },
24
- "keywords": [
25
- "url",
26
- "template"
27
- ],
28
- "devDependencies": {
29
- "@types/node": "^24.0.4",
30
- "typescript": "^5.9.2"
31
- }
32
- }
1
+ {
2
+ "name": "quasiurl",
3
+ "version": "1.0.2",
4
+ "description": "URL for templating",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "build": "npx npm-run-all clean -p compile compile-tests",
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
+ "compile-tests": "npx esbuild tests.ts --bundle --outdir=dist --platform=neutral",
12
+ "prepublishOnly": "npm run build",
13
+ "preversion": "npx npm-run-all typecheck shape build test",
14
+ "shape": "npx codeshape",
15
+ "test": "node dist/tests.js",
16
+ "typecheck": "tsc --noEmit"
17
+ },
18
+ "author": "axtk",
19
+ "license": "ISC",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git://github.com/t8js/quasiurl.git"
23
+ },
24
+ "keywords": [
25
+ "url",
26
+ "template"
27
+ ],
28
+ "devDependencies": {
29
+ "@types/node": "^24.0.4",
30
+ "typescript": "^5.9.2"
31
+ }
32
+ }
package/tests.ts CHANGED
@@ -1,102 +1,122 @@
1
- import {QuasiURL} from '.';
1
+ import { QuasiURL } from ".";
2
2
 
3
3
  let k = 0;
4
4
 
5
5
  function assert(predicate: boolean) {
6
- let n = `00${++k}`.slice(-3);
7
-
8
- if (predicate) console.log(n, 'passed');
9
- else {
10
- console.error(n, 'failed');
11
- console.error();
12
- console.error('[!] failed');
13
- process.exit(1);
14
- }
6
+ let n = `00${++k}`.slice(-3);
7
+
8
+ if (predicate) console.log(n, "passed");
9
+ else {
10
+ console.error(n, "failed");
11
+ console.error();
12
+ console.error("[!] failed");
13
+ process.exit(1);
14
+ }
15
15
  }
16
16
 
17
17
  function createQuasiURL(url: string) {
18
- console.log(`\n${JSON.stringify(url)}`);
19
- return new QuasiURL(url);
18
+ console.log(`\n${JSON.stringify(url)}`);
19
+ return new QuasiURL(url);
20
20
  }
21
21
 
22
- let url = createQuasiURL('/sections/:id');
23
-
24
- assert(url.origin === '');
25
- assert(url.pathname === '/sections/:id');
26
- assert(url.search === '');
27
- assert(url.hash === '');
28
- assert(url.href === '/sections/:id');
29
- assert(url.hostname === '');
30
- assert(url.protocol === '');
31
-
32
- url = createQuasiURL('/x{/:name}');
33
-
34
- assert(url.origin === '');
35
- assert(url.pathname === '/x{/:name}');
36
- assert(url.search === '');
37
- assert(url.hash === '');
38
- assert(url.href === '/x{/:name}');
39
- assert(url.hostname === '');
40
- assert(url.protocol === '');
41
-
42
- url = createQuasiURL('/x?a=1&b=nnn#start');
43
-
44
- assert(url.origin === '');
45
- assert(url.pathname === '/x');
46
- assert(url.search === '?a=1&b=nnn');
47
- assert(url.hash === '#start');
48
- assert(url.href === '/x?a=1&b=nnn#start');
49
- assert(url.hostname === '');
50
- assert(url.protocol === '');
51
-
52
- url = createQuasiURL('https://a.aa/chapter/1');
53
-
54
- assert(url.origin === 'https://a.aa');
55
- assert(url.pathname === '/chapter/1');
56
- assert(url.search === '');
57
- assert(url.hash === '');
58
- assert(url.href === 'https://a.aa/chapter/1');
59
- assert(url.hostname === 'a.aa');
60
- assert(url.protocol === 'https:');
61
-
62
- url = createQuasiURL('https://a.aa');
63
-
64
- assert(url.origin === 'https://a.aa');
65
- assert(url.pathname === '');
66
- assert(url.search === '');
67
- assert(url.hash === '');
68
- assert(url.href === 'https://a.aa');
69
- assert(url.hostname === 'a.aa');
70
- assert(url.protocol === 'https:');
71
-
72
- url = createQuasiURL('');
73
-
74
- assert(url.origin === '');
75
- assert(url.pathname === '');
76
- assert(url.search === '');
77
- assert(url.hash === '');
78
- assert(url.href === '');
79
- assert(url.hostname === '');
80
- assert(url.protocol === '');
81
-
82
- url = createQuasiURL('?x=321&y=567#start');
83
-
84
- assert(url.origin === '');
85
- assert(url.pathname === '');
86
- assert(url.search === '?x=321&y=567');
87
- assert(url.hash === '#start');
88
- assert(url.href === '?x=321&y=567#start');
89
- assert(url.hostname === '');
90
- assert(url.protocol === '');
91
-
92
- url = createQuasiURL('x/y?a=1');
93
-
94
- assert(url.origin === '');
95
- assert(url.pathname === 'x/y');
96
- assert(url.search === '?a=1');
97
- assert(url.hash === '');
98
- assert(url.href === 'x/y?a=1');
99
- assert(url.hostname === '');
100
- assert(url.protocol === '');
101
-
102
- console.log('\npassed');
22
+ let url = createQuasiURL("/x");
23
+
24
+ assert(url.origin === "");
25
+ assert(url.pathname === "/x");
26
+ assert(url.search === "");
27
+ assert(url.hash === "");
28
+ assert(url.href === "/x");
29
+ assert(url.hostname === "");
30
+ assert(url.protocol === "");
31
+
32
+ url = createQuasiURL("/sections/:id");
33
+
34
+ assert(url.origin === "");
35
+ assert(url.pathname === "/sections/:id");
36
+ assert(url.search === "");
37
+ assert(url.hash === "");
38
+ assert(url.href === "/sections/:id");
39
+ assert(url.hostname === "");
40
+ assert(url.protocol === "");
41
+
42
+ url = createQuasiURL("/x{/:name}");
43
+
44
+ assert(url.origin === "");
45
+ assert(url.pathname === "/x{/:name}");
46
+ assert(url.search === "");
47
+ assert(url.hash === "");
48
+ assert(url.href === "/x{/:name}");
49
+ assert(url.hostname === "");
50
+ assert(url.protocol === "");
51
+
52
+ url = createQuasiURL("https://a.aa/x{/:name}");
53
+
54
+ assert(url.origin === "https://a.aa");
55
+ assert(url.pathname === "/x{/:name}");
56
+ assert(url.search === "");
57
+ assert(url.hash === "");
58
+ assert(url.href === "https://a.aa/x{/:name}");
59
+ assert(url.hostname === "a.aa");
60
+ assert(url.protocol === "https:");
61
+
62
+ url = createQuasiURL("/x?a=1&b=nnn#start");
63
+
64
+ assert(url.origin === "");
65
+ assert(url.pathname === "/x");
66
+ assert(url.search === "?a=1&b=nnn");
67
+ assert(url.hash === "#start");
68
+ assert(url.href === "/x?a=1&b=nnn#start");
69
+ assert(url.hostname === "");
70
+ assert(url.protocol === "");
71
+
72
+ url = createQuasiURL("https://a.aa/chapter/1");
73
+
74
+ assert(url.origin === "https://a.aa");
75
+ assert(url.pathname === "/chapter/1");
76
+ assert(url.search === "");
77
+ assert(url.hash === "");
78
+ assert(url.href === "https://a.aa/chapter/1");
79
+ assert(url.hostname === "a.aa");
80
+ assert(url.protocol === "https:");
81
+
82
+ url = createQuasiURL("https://a.aa");
83
+
84
+ assert(url.origin === "https://a.aa");
85
+ assert(url.pathname === "");
86
+ assert(url.search === "");
87
+ assert(url.hash === "");
88
+ assert(url.href === "https://a.aa");
89
+ assert(url.hostname === "a.aa");
90
+ assert(url.protocol === "https:");
91
+
92
+ url = createQuasiURL("");
93
+
94
+ assert(url.origin === "");
95
+ assert(url.pathname === "");
96
+ assert(url.search === "");
97
+ assert(url.hash === "");
98
+ assert(url.href === "");
99
+ assert(url.hostname === "");
100
+ assert(url.protocol === "");
101
+
102
+ url = createQuasiURL("?x=321&y=567#start");
103
+
104
+ assert(url.origin === "");
105
+ assert(url.pathname === "");
106
+ assert(url.search === "?x=321&y=567");
107
+ assert(url.hash === "#start");
108
+ assert(url.href === "?x=321&y=567#start");
109
+ assert(url.hostname === "");
110
+ assert(url.protocol === "");
111
+
112
+ url = createQuasiURL("x/y?a=1");
113
+
114
+ assert(url.origin === "");
115
+ assert(url.pathname === "x/y");
116
+ assert(url.search === "?a=1");
117
+ assert(url.hash === "");
118
+ assert(url.href === "x/y?a=1");
119
+ assert(url.hostname === "");
120
+ assert(url.protocol === "");
121
+
122
+ console.log("\npassed");
package/tsconfig.json CHANGED
@@ -1,15 +1,12 @@
1
- {
2
- "include": [
3
- "index.ts",
4
- "tests.ts"
5
- ],
6
- "compilerOptions": {
7
- "lib": ["ESNext", "DOM"],
8
- "target": "ESNext",
9
- "outDir": "dist",
10
- "moduleResolution": "node",
11
- "strict": true,
12
- "noUnusedLocals": true,
13
- "noUnusedParameters": true
14
- }
15
- }
1
+ {
2
+ "include": ["index.ts", "tests.ts"],
3
+ "compilerOptions": {
4
+ "lib": ["ESNext", "DOM"],
5
+ "target": "ESNext",
6
+ "outDir": "dist",
7
+ "moduleResolution": "node",
8
+ "strict": true,
9
+ "noUnusedLocals": true,
10
+ "noUnusedParameters": true
11
+ }
12
+ }