@adviser/cement 0.4.2 → 0.4.4
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/cf/index.js +2 -2
- package/{chunk-XJ3SFZPE.js → chunk-FURW5CDL.js} +2 -2
- package/{chunk-C5L2FW7O.js → chunk-NJMNJYN2.js} +2 -2
- package/{chunk-MBLJQD6G.js → chunk-NTOGMD33.js} +1 -1
- package/chunk-NTOGMD33.js.map +1 -0
- package/{chunk-S5OZRDIH.js → chunk-Z724JFU6.js} +86 -11
- package/chunk-Z724JFU6.js.map +1 -0
- package/deno/index.js +2 -2
- package/{index-TtYD7HhB.d.cts → index-BJwthmNK.d.cts} +12 -2
- package/{index-N0bkrgSt.d.ts → index-Bh_2ZgIk.d.ts} +12 -2
- package/index.cjs +83 -8
- package/index.cjs.map +1 -1
- package/index.d.cts +4 -3
- package/index.d.ts +4 -3
- package/index.js +4 -4
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.js +2 -2
- package/package.json +5 -4
- package/src/is-promise.ts +2 -0
- package/src/jsr.json +1 -1
- package/src/uri.ts +99 -9
- package/test/index.cjs +83 -8
- package/test/index.cjs.map +1 -1
- package/test/index.d.cts +1 -1
- package/test/index.d.ts +1 -1
- package/test/index.js +3 -3
- package/ts/src/is-promise.d.ts +1 -0
- package/ts/src/is-promise.d.ts.map +1 -1
- package/ts/src/is-promise.js.map +1 -1
- package/ts/src/uri.d.ts +12 -2
- package/ts/src/uri.d.ts.map +1 -1
- package/ts/src/uri.js +83 -5
- package/ts/src/uri.js.map +1 -1
- package/ts/src/uri.test.js +97 -0
- package/ts/src/uri.test.js.map +1 -1
- package/ts/vitest.browser.config.d.ts.map +1 -1
- package/ts/vitest.browser.config.js +6 -2
- package/ts/vitest.browser.config.js.map +1 -1
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +2 -2
- package/web/index.js +2 -2
- package/chunk-MBLJQD6G.js.map +0 -1
- package/chunk-S5OZRDIH.js.map +0 -1
- /package/{chunk-XJ3SFZPE.js.map → chunk-FURW5CDL.js.map} +0 -0
- /package/{chunk-C5L2FW7O.js.map → chunk-NJMNJYN2.js.map} +0 -0
@@ -67,13 +67,14 @@ interface HostURIObject extends URIObject {
|
|
67
67
|
readonly port: string;
|
68
68
|
}
|
69
69
|
declare function isURL(value: unknown): value is URL;
|
70
|
+
declare const customInspectSymbol: unique symbol;
|
70
71
|
declare class MutableURL extends URL {
|
71
72
|
private readonly _sysURL;
|
72
73
|
private _protocol;
|
73
74
|
private _pathname;
|
74
75
|
private _hasHostpart;
|
75
|
-
readonly hash: string;
|
76
76
|
constructor(urlStr: string);
|
77
|
+
[customInspectSymbol](): string;
|
77
78
|
clone(): MutableURL;
|
78
79
|
get host(): string;
|
79
80
|
get port(): string;
|
@@ -84,7 +85,10 @@ declare class MutableURL extends URL {
|
|
84
85
|
get pathname(): string;
|
85
86
|
get protocol(): string;
|
86
87
|
set protocol(p: string);
|
88
|
+
get hash(): string;
|
89
|
+
set hash(h: string);
|
87
90
|
get searchParams(): URLSearchParams;
|
91
|
+
get search(): string;
|
88
92
|
toString(): string;
|
89
93
|
}
|
90
94
|
declare class BuildURI implements URIInterface<BuildURI> {
|
@@ -97,9 +101,11 @@ declare class BuildURI implements URIInterface<BuildURI> {
|
|
97
101
|
hostname(h: string): BuildURI;
|
98
102
|
protocol(p: string): BuildURI;
|
99
103
|
pathname(p: string): BuildURI;
|
104
|
+
hash(h: string): BuildURI;
|
100
105
|
resolve(p: CoerceURI): BuildURI;
|
101
106
|
appendRelative(p: CoerceURI): BuildURI;
|
102
|
-
cleanParams(): BuildURI;
|
107
|
+
cleanParams(...remove: (string | string[])[]): BuildURI;
|
108
|
+
hashParams(val: Record<string, string | number | boolean | Date | null | undefined>, mode?: "reset" | "merge"): BuildURI;
|
103
109
|
delParam(key: string): BuildURI;
|
104
110
|
defParam(key: string, str: string): BuildURI;
|
105
111
|
setParam(key: string, str: string): BuildURI;
|
@@ -108,6 +114,7 @@ declare class BuildURI implements URIInterface<BuildURI> {
|
|
108
114
|
getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
|
109
115
|
getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
|
110
116
|
getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
|
117
|
+
getHashParams(...keys: KeysParam): Result<Record<string, string>>;
|
111
118
|
toString(): string;
|
112
119
|
toJSON(): string;
|
113
120
|
asURL(): URL;
|
@@ -129,15 +136,18 @@ declare class URI implements URIInterface<URI> {
|
|
129
136
|
private constructor();
|
130
137
|
build(): BuildURI;
|
131
138
|
get hostname(): string;
|
139
|
+
get local(): string;
|
132
140
|
get port(): string;
|
133
141
|
get host(): string;
|
134
142
|
get protocol(): string;
|
135
143
|
get pathname(): string;
|
144
|
+
get hash(): string;
|
136
145
|
get getParams(): Iterable<[string, string]>;
|
137
146
|
hasParam(key: string): boolean;
|
138
147
|
getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
|
139
148
|
getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
|
140
149
|
getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
|
150
|
+
getHashParams(...keys: KeysParam): Result<Record<string, string>>;
|
141
151
|
clone(): URI;
|
142
152
|
asURL(): URL;
|
143
153
|
toString(): string;
|
@@ -67,13 +67,14 @@ interface HostURIObject extends URIObject {
|
|
67
67
|
readonly port: string;
|
68
68
|
}
|
69
69
|
declare function isURL(value: unknown): value is URL;
|
70
|
+
declare const customInspectSymbol: unique symbol;
|
70
71
|
declare class MutableURL extends URL {
|
71
72
|
private readonly _sysURL;
|
72
73
|
private _protocol;
|
73
74
|
private _pathname;
|
74
75
|
private _hasHostpart;
|
75
|
-
readonly hash: string;
|
76
76
|
constructor(urlStr: string);
|
77
|
+
[customInspectSymbol](): string;
|
77
78
|
clone(): MutableURL;
|
78
79
|
get host(): string;
|
79
80
|
get port(): string;
|
@@ -84,7 +85,10 @@ declare class MutableURL extends URL {
|
|
84
85
|
get pathname(): string;
|
85
86
|
get protocol(): string;
|
86
87
|
set protocol(p: string);
|
88
|
+
get hash(): string;
|
89
|
+
set hash(h: string);
|
87
90
|
get searchParams(): URLSearchParams;
|
91
|
+
get search(): string;
|
88
92
|
toString(): string;
|
89
93
|
}
|
90
94
|
declare class BuildURI implements URIInterface<BuildURI> {
|
@@ -97,9 +101,11 @@ declare class BuildURI implements URIInterface<BuildURI> {
|
|
97
101
|
hostname(h: string): BuildURI;
|
98
102
|
protocol(p: string): BuildURI;
|
99
103
|
pathname(p: string): BuildURI;
|
104
|
+
hash(h: string): BuildURI;
|
100
105
|
resolve(p: CoerceURI): BuildURI;
|
101
106
|
appendRelative(p: CoerceURI): BuildURI;
|
102
|
-
cleanParams(): BuildURI;
|
107
|
+
cleanParams(...remove: (string | string[])[]): BuildURI;
|
108
|
+
hashParams(val: Record<string, string | number | boolean | Date | null | undefined>, mode?: "reset" | "merge"): BuildURI;
|
103
109
|
delParam(key: string): BuildURI;
|
104
110
|
defParam(key: string, str: string): BuildURI;
|
105
111
|
setParam(key: string, str: string): BuildURI;
|
@@ -108,6 +114,7 @@ declare class BuildURI implements URIInterface<BuildURI> {
|
|
108
114
|
getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
|
109
115
|
getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
|
110
116
|
getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
|
117
|
+
getHashParams(...keys: KeysParam): Result<Record<string, string>>;
|
111
118
|
toString(): string;
|
112
119
|
toJSON(): string;
|
113
120
|
asURL(): URL;
|
@@ -129,15 +136,18 @@ declare class URI implements URIInterface<URI> {
|
|
129
136
|
private constructor();
|
130
137
|
build(): BuildURI;
|
131
138
|
get hostname(): string;
|
139
|
+
get local(): string;
|
132
140
|
get port(): string;
|
133
141
|
get host(): string;
|
134
142
|
get protocol(): string;
|
135
143
|
get pathname(): string;
|
144
|
+
get hash(): string;
|
136
145
|
get getParams(): Iterable<[string, string]>;
|
137
146
|
hasParam(key: string): boolean;
|
138
147
|
getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
|
139
148
|
getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
|
140
149
|
getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
|
150
|
+
getHashParams(...keys: KeysParam): Result<Record<string, string>>;
|
141
151
|
clone(): URI;
|
142
152
|
asURL(): URL;
|
143
153
|
toString(): string;
|
package/index.cjs
CHANGED
@@ -722,6 +722,15 @@ function coerceKey(key, def) {
|
|
722
722
|
}
|
723
723
|
return { key, def };
|
724
724
|
}
|
725
|
+
function resolveHash(hash) {
|
726
|
+
const searchParams = new URLSearchParams(hash.replace(/^#/, ""));
|
727
|
+
return {
|
728
|
+
getParam: (k) => {
|
729
|
+
const ret = searchParams.get(k);
|
730
|
+
return ret === null ? void 0 : ret;
|
731
|
+
}
|
732
|
+
};
|
733
|
+
}
|
725
734
|
function falsy2undef(value) {
|
726
735
|
return value === void 0 || value === null ? void 0 : value;
|
727
736
|
}
|
@@ -742,7 +751,9 @@ function ensureURLWithDefaultProto(url, defaultProtocol) {
|
|
742
751
|
function isURL(value) {
|
743
752
|
return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
|
744
753
|
}
|
754
|
+
var customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
745
755
|
var MutableURL = class _MutableURL extends URL {
|
756
|
+
// override readonly hash: string;
|
746
757
|
constructor(urlStr) {
|
747
758
|
super("defect://does.not.exist");
|
748
759
|
const partedURL = urlStr.split(":");
|
@@ -765,7 +776,9 @@ var MutableURL = class _MutableURL extends URL {
|
|
765
776
|
} else {
|
766
777
|
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
767
778
|
}
|
768
|
-
|
779
|
+
}
|
780
|
+
[customInspectSymbol]() {
|
781
|
+
return this.toString();
|
769
782
|
}
|
770
783
|
clone() {
|
771
784
|
return new _MutableURL(this.toString());
|
@@ -817,16 +830,26 @@ var MutableURL = class _MutableURL extends URL {
|
|
817
830
|
}
|
818
831
|
this._protocol = p;
|
819
832
|
}
|
833
|
+
get hash() {
|
834
|
+
return this._sysURL.hash;
|
835
|
+
}
|
836
|
+
set hash(h) {
|
837
|
+
this._sysURL.hash = h;
|
838
|
+
}
|
820
839
|
get searchParams() {
|
821
840
|
return this._sysURL.searchParams;
|
822
841
|
}
|
823
|
-
|
842
|
+
get search() {
|
824
843
|
let search = "";
|
825
844
|
if (this._sysURL.searchParams.size) {
|
826
845
|
for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
827
846
|
search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
|
828
847
|
}
|
829
848
|
}
|
849
|
+
return search;
|
850
|
+
}
|
851
|
+
toString() {
|
852
|
+
const search = this.search;
|
830
853
|
let hostpart = "";
|
831
854
|
if (this._hasHostpart) {
|
832
855
|
hostpart = this._sysURL.hostname;
|
@@ -837,7 +860,7 @@ var MutableURL = class _MutableURL extends URL {
|
|
837
860
|
hostpart += "/";
|
838
861
|
}
|
839
862
|
}
|
840
|
-
return `${this._protocol}//${hostpart}${this._pathname}${search}`;
|
863
|
+
return `${this._protocol}//${hostpart}${this._pathname}${search}${this.hash}`;
|
841
864
|
}
|
842
865
|
};
|
843
866
|
function from(fac, strURLUri, defaultProtocol) {
|
@@ -900,6 +923,10 @@ var BuildURI = class _BuildURI {
|
|
900
923
|
this._url.pathname = p;
|
901
924
|
return this;
|
902
925
|
}
|
926
|
+
hash(h) {
|
927
|
+
this._url.hash = h;
|
928
|
+
return this;
|
929
|
+
}
|
903
930
|
// could pass a relative path or a full URL
|
904
931
|
// if relative path, it will be appended to the current path
|
905
932
|
resolve(p) {
|
@@ -928,12 +955,51 @@ var BuildURI = class _BuildURI {
|
|
928
955
|
}
|
929
956
|
return this;
|
930
957
|
}
|
931
|
-
cleanParams() {
|
958
|
+
cleanParams(...remove) {
|
959
|
+
const keys = new Set(remove.flat());
|
932
960
|
for (const key of Array.from(this._url.searchParams.keys())) {
|
933
|
-
|
961
|
+
if (keys.size === 0 || keys.has(key)) {
|
962
|
+
this._url.searchParams.delete(key);
|
963
|
+
}
|
934
964
|
}
|
935
965
|
return this;
|
936
966
|
}
|
967
|
+
hashParams(val, mode = "reset") {
|
968
|
+
let preset;
|
969
|
+
switch (mode) {
|
970
|
+
case "reset":
|
971
|
+
this._url.hash = "";
|
972
|
+
preset = {};
|
973
|
+
break;
|
974
|
+
case "merge":
|
975
|
+
default:
|
976
|
+
preset = Object.fromEntries(new URLSearchParams(this._url.hash.replace(/^#/, "")).entries());
|
977
|
+
break;
|
978
|
+
}
|
979
|
+
const out = new URLSearchParams("");
|
980
|
+
for (const [key, value] of Object.entries({ ...preset, ...val }).sort((a, b) => a[0].localeCompare(b[0]))) {
|
981
|
+
switch (typeof value) {
|
982
|
+
case "string":
|
983
|
+
out.set(key, value);
|
984
|
+
break;
|
985
|
+
case "number":
|
986
|
+
out.set(key, value.toString());
|
987
|
+
break;
|
988
|
+
case "boolean":
|
989
|
+
out.set(key, value ? "true" : "false");
|
990
|
+
break;
|
991
|
+
default:
|
992
|
+
if (value instanceof Date) {
|
993
|
+
out.set(key, value.toISOString());
|
994
|
+
} else {
|
995
|
+
console.error(`unsupported type: ${typeof value} ignore key: ${key}`);
|
996
|
+
}
|
997
|
+
break;
|
998
|
+
}
|
999
|
+
}
|
1000
|
+
this._url.hash = out.toString();
|
1001
|
+
return this;
|
1002
|
+
}
|
937
1003
|
delParam(key) {
|
938
1004
|
this._url.searchParams.delete(key);
|
939
1005
|
return this;
|
@@ -968,6 +1034,9 @@ var BuildURI = class _BuildURI {
|
|
968
1034
|
getParamsResult(...keys) {
|
969
1035
|
return getParamsResult(keys, this);
|
970
1036
|
}
|
1037
|
+
getHashParams(...keys) {
|
1038
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1039
|
+
}
|
971
1040
|
toString() {
|
972
1041
|
this._url.searchParams.sort();
|
973
1042
|
return this._url.toString();
|
@@ -1051,6 +1120,9 @@ var URI = class _URI {
|
|
1051
1120
|
get hostname() {
|
1052
1121
|
return this._url.hostname;
|
1053
1122
|
}
|
1123
|
+
get local() {
|
1124
|
+
return this._url.pathname + this._url.search;
|
1125
|
+
}
|
1054
1126
|
// get password(): string {
|
1055
1127
|
// return this._url.password;
|
1056
1128
|
// }
|
@@ -1072,9 +1144,9 @@ var URI = class _URI {
|
|
1072
1144
|
get pathname() {
|
1073
1145
|
return this._url.pathname;
|
1074
1146
|
}
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1147
|
+
get hash() {
|
1148
|
+
return this._url.hash;
|
1149
|
+
}
|
1078
1150
|
// get host(): string {
|
1079
1151
|
// return this._url.host;
|
1080
1152
|
// }
|
@@ -1098,6 +1170,9 @@ var URI = class _URI {
|
|
1098
1170
|
getParamsResult(...keys) {
|
1099
1171
|
return getParamsResult(keys, this);
|
1100
1172
|
}
|
1173
|
+
getHashParams(...keys) {
|
1174
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1175
|
+
}
|
1101
1176
|
clone() {
|
1102
1177
|
return new _URI(this._url);
|
1103
1178
|
}
|