@server/next 0.15.1 → 0.15.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/package.json +1 -1
- package/src/ServerUrl.js +49 -17
- package/src/ServerUrl.test.js +18 -0
package/package.json
CHANGED
package/src/ServerUrl.js
CHANGED
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { inspect } from "util";
|
|
2
|
+
|
|
3
|
+
const colors = {
|
|
4
|
+
string: process.env.NO_COLOR ? "" : "\x1b[32m",
|
|
5
|
+
number: process.env.NO_COLOR ? "" : "\x1b[33m",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const properties = [
|
|
9
|
+
"hash",
|
|
10
|
+
"host",
|
|
11
|
+
"hostname",
|
|
12
|
+
"href",
|
|
13
|
+
"origin",
|
|
14
|
+
"params",
|
|
15
|
+
"password",
|
|
16
|
+
"path",
|
|
17
|
+
"pathname",
|
|
18
|
+
"port",
|
|
19
|
+
"protocol",
|
|
20
|
+
"query",
|
|
21
|
+
"search",
|
|
22
|
+
"searchParams",
|
|
23
|
+
"username",
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export default class ServerUrl extends URL {
|
|
2
27
|
constructor(urlString) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
super(urlString);
|
|
29
|
+
|
|
30
|
+
const custom = {
|
|
31
|
+
port: +this.port || null,
|
|
32
|
+
path: this.pathname,
|
|
33
|
+
params: {},
|
|
34
|
+
query: this.getQuery(this.searchParams.entries()),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
for (let key of properties) {
|
|
38
|
+
const value = key in custom ? custom[key] : this[key];
|
|
39
|
+
Object.defineProperty(this, key, { value, enumerable: true });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[inspect.custom]() {
|
|
44
|
+
const props = Object.keys(this)
|
|
45
|
+
.map((key) => {
|
|
46
|
+
const color = colors[typeof this[key]] || "";
|
|
47
|
+
return ` ${key}: ${color}${inspect(this[key])}\x1b[0m`;
|
|
48
|
+
})
|
|
49
|
+
.join("\n");
|
|
50
|
+
return `ServerUrl {\n${props}\n}`;
|
|
19
51
|
}
|
|
20
52
|
|
|
21
53
|
getQuery(entries) {
|
package/src/ServerUrl.test.js
CHANGED
|
@@ -17,6 +17,24 @@ describe("getUrl()", () => {
|
|
|
17
17
|
expect(url.host).toBe("example.com");
|
|
18
18
|
expect(url.hostname).toBe("example.com");
|
|
19
19
|
expect(url.port).toBe(null);
|
|
20
|
+
|
|
21
|
+
expect(Object.keys(url)).toEqual([
|
|
22
|
+
"hash",
|
|
23
|
+
"host",
|
|
24
|
+
"hostname",
|
|
25
|
+
"href",
|
|
26
|
+
"origin",
|
|
27
|
+
"params",
|
|
28
|
+
"password",
|
|
29
|
+
"path",
|
|
30
|
+
"pathname",
|
|
31
|
+
"port",
|
|
32
|
+
"protocol",
|
|
33
|
+
"query",
|
|
34
|
+
"search",
|
|
35
|
+
"searchParams",
|
|
36
|
+
"username",
|
|
37
|
+
]);
|
|
20
38
|
});
|
|
21
39
|
|
|
22
40
|
it("can parse localhost", () => {
|