@react-foundry/uri 0.1.8 → 0.2.0
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.js +2 -18
- package/dist/query-string.js +3 -8
- package/dist/uri.js +5 -9
- package/package.json +7 -9
- package/dist/index.mjs +0 -2
- package/dist/query-string.mjs +0 -5
- package/dist/uri.mjs +0 -132
package/dist/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./query-string"), exports);
|
|
18
|
-
__exportStar(require("./uri"), exports);
|
|
1
|
+
export * from './query-string';
|
|
2
|
+
export * from './uri';
|
package/dist/query-string.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.queryString = exports.qsParse = void 0;
|
|
4
|
-
const qs_1 = require("qs");
|
|
5
|
-
const qsParse = (s) => (0, qs_1.parse)(s && s[0] === '?'
|
|
1
|
+
import { parse, stringify } from 'qs';
|
|
2
|
+
export const qsParse = (s) => parse(s && s[0] === '?'
|
|
6
3
|
? s?.substring(1)
|
|
7
4
|
: s);
|
|
8
|
-
|
|
9
|
-
const queryString = (obj) => '?' + (0, qs_1.stringify)(obj);
|
|
10
|
-
exports.queryString = queryString;
|
|
5
|
+
export const queryString = (obj) => '?' + stringify(obj);
|
package/dist/uri.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.URI = void 0;
|
|
4
|
-
const query_string_1 = require("./query-string");
|
|
5
|
-
class URI extends Object {
|
|
1
|
+
import { qsParse, queryString } from './query-string';
|
|
2
|
+
export class URI extends Object {
|
|
6
3
|
#url;
|
|
7
4
|
#noHostname = false;
|
|
8
5
|
#noPathname = false;
|
|
@@ -29,7 +26,7 @@ class URI extends Object {
|
|
|
29
26
|
this.#noPathname = true;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
this.#query =
|
|
29
|
+
this.#query = qsParse(this.#url.search);
|
|
33
30
|
}
|
|
34
31
|
get href() {
|
|
35
32
|
const targetHref = this.#url.href;
|
|
@@ -94,7 +91,7 @@ class URI extends Object {
|
|
|
94
91
|
return this.#url.search;
|
|
95
92
|
}
|
|
96
93
|
set search(v) {
|
|
97
|
-
this.#query =
|
|
94
|
+
this.#query = qsParse(v);
|
|
98
95
|
this.#url.search = v;
|
|
99
96
|
}
|
|
100
97
|
get hash() {
|
|
@@ -108,7 +105,7 @@ class URI extends Object {
|
|
|
108
105
|
}
|
|
109
106
|
set query(v) {
|
|
110
107
|
this.#query = v;
|
|
111
|
-
this.#url.search =
|
|
108
|
+
this.#url.search = queryString(v);
|
|
112
109
|
}
|
|
113
110
|
toString() {
|
|
114
111
|
return (this.#noHostname
|
|
@@ -133,4 +130,3 @@ class URI extends Object {
|
|
|
133
130
|
return new URI(s, base);
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
|
-
exports.URI = URI;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-foundry/uri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A more forgiving alternative to JavaScript's standard URL class.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.
|
|
10
|
-
"
|
|
11
|
-
"default": "./dist/index.mjs"
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
@@ -26,16 +26,14 @@
|
|
|
26
26
|
"@types/qs": "6.15.0",
|
|
27
27
|
"jest": "30.3.0",
|
|
28
28
|
"jest-environment-jsdom": "30.3.0",
|
|
29
|
-
"ts-jest": "29.4.
|
|
29
|
+
"ts-jest": "29.4.9",
|
|
30
30
|
"typescript": "5.9.3"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
34
|
-
"build": "
|
|
35
|
-
"build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
|
|
36
|
-
"build:cjs": "tsc",
|
|
34
|
+
"build": "tsc",
|
|
37
35
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
38
36
|
},
|
|
39
|
-
"module": "dist/index.
|
|
37
|
+
"module": "dist/index.js",
|
|
40
38
|
"typings": "dist/index.d.ts"
|
|
41
39
|
}
|
package/dist/index.mjs
DELETED
package/dist/query-string.mjs
DELETED
package/dist/uri.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { qsParse, queryString } from './query-string';
|
|
2
|
-
export class URI extends Object {
|
|
3
|
-
#url;
|
|
4
|
-
#noHostname = false;
|
|
5
|
-
#noPathname = false;
|
|
6
|
-
#query;
|
|
7
|
-
constructor(uri, base) {
|
|
8
|
-
super();
|
|
9
|
-
try {
|
|
10
|
-
this.#url = new URL(uri, base);
|
|
11
|
-
}
|
|
12
|
-
catch (_e) {
|
|
13
|
-
const dummyOrigin = 'http://a';
|
|
14
|
-
this.#noHostname = true;
|
|
15
|
-
try {
|
|
16
|
-
const newBase = (base
|
|
17
|
-
? (base[0] === '/'
|
|
18
|
-
? dummyOrigin + base
|
|
19
|
-
: dummyOrigin + '/' + base)
|
|
20
|
-
: dummyOrigin);
|
|
21
|
-
this.#url = new URL(uri, newBase);
|
|
22
|
-
this.#noPathname = this.#url.pathname === '/' && uri[0] !== '/';
|
|
23
|
-
}
|
|
24
|
-
catch (_e) {
|
|
25
|
-
this.#url = new URL('', dummyOrigin);
|
|
26
|
-
this.#noPathname = true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
this.#query = qsParse(this.#url.search);
|
|
30
|
-
}
|
|
31
|
-
get href() {
|
|
32
|
-
const targetHref = this.#url.href;
|
|
33
|
-
const hash = (targetHref[targetHref.length - 1] === '#'
|
|
34
|
-
? '#'
|
|
35
|
-
: this.#url.hash);
|
|
36
|
-
return (this.#noHostname
|
|
37
|
-
? this.pathname + this.#url.search + hash
|
|
38
|
-
: targetHref);
|
|
39
|
-
}
|
|
40
|
-
get protocol() {
|
|
41
|
-
return (this.#noHostname
|
|
42
|
-
? ''
|
|
43
|
-
: this.#url.protocol);
|
|
44
|
-
}
|
|
45
|
-
set protocol(v) {
|
|
46
|
-
this.#url.protocol = v;
|
|
47
|
-
}
|
|
48
|
-
get username() {
|
|
49
|
-
return (this.#noHostname
|
|
50
|
-
? ''
|
|
51
|
-
: this.#url.username);
|
|
52
|
-
}
|
|
53
|
-
set username(v) {
|
|
54
|
-
this.#url.username = v;
|
|
55
|
-
}
|
|
56
|
-
get password() {
|
|
57
|
-
return (this.#noHostname
|
|
58
|
-
? ''
|
|
59
|
-
: this.#url.password);
|
|
60
|
-
}
|
|
61
|
-
set password(v) {
|
|
62
|
-
this.#url.password = v;
|
|
63
|
-
}
|
|
64
|
-
get hostname() {
|
|
65
|
-
return (this.#noHostname
|
|
66
|
-
? ''
|
|
67
|
-
: this.#url.hostname);
|
|
68
|
-
}
|
|
69
|
-
set hostname(v) {
|
|
70
|
-
this.#noHostname = !v;
|
|
71
|
-
this.#url.hostname = v;
|
|
72
|
-
}
|
|
73
|
-
get port() {
|
|
74
|
-
return (this.#noHostname
|
|
75
|
-
? ''
|
|
76
|
-
: this.#url.port);
|
|
77
|
-
}
|
|
78
|
-
set port(v) {
|
|
79
|
-
this.#url.port = v;
|
|
80
|
-
}
|
|
81
|
-
get pathname() {
|
|
82
|
-
return (this.#noPathname
|
|
83
|
-
? ''
|
|
84
|
-
: this.#url.pathname);
|
|
85
|
-
}
|
|
86
|
-
set pathname(v) {
|
|
87
|
-
this.#noPathname = !v;
|
|
88
|
-
this.#url.pathname = v;
|
|
89
|
-
}
|
|
90
|
-
get search() {
|
|
91
|
-
return this.#url.search;
|
|
92
|
-
}
|
|
93
|
-
set search(v) {
|
|
94
|
-
this.#query = qsParse(v);
|
|
95
|
-
this.#url.search = v;
|
|
96
|
-
}
|
|
97
|
-
get hash() {
|
|
98
|
-
return this.#url.hash;
|
|
99
|
-
}
|
|
100
|
-
set hash(v) {
|
|
101
|
-
this.#url.hash = v;
|
|
102
|
-
}
|
|
103
|
-
get query() {
|
|
104
|
-
return this.#query;
|
|
105
|
-
}
|
|
106
|
-
set query(v) {
|
|
107
|
-
this.#query = v;
|
|
108
|
-
this.#url.search = queryString(v);
|
|
109
|
-
}
|
|
110
|
-
toString() {
|
|
111
|
-
return (this.#noHostname
|
|
112
|
-
? this.href
|
|
113
|
-
: this.#url.toString());
|
|
114
|
-
}
|
|
115
|
-
valueOf() {
|
|
116
|
-
return ({
|
|
117
|
-
href: this.href,
|
|
118
|
-
protocol: this.protocol,
|
|
119
|
-
username: this.username,
|
|
120
|
-
password: this.password,
|
|
121
|
-
hostname: this.hostname,
|
|
122
|
-
port: this.port,
|
|
123
|
-
pathname: this.pathname,
|
|
124
|
-
search: this.search,
|
|
125
|
-
query: this.query,
|
|
126
|
-
hash: this.hash
|
|
127
|
-
}).valueOf();
|
|
128
|
-
}
|
|
129
|
-
static parse(s, base) {
|
|
130
|
-
return new URI(s, base);
|
|
131
|
-
}
|
|
132
|
-
}
|