@adviser/cement 0.4.3 → 0.4.5
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/{chunk-FZHQTSQU.js → chunk-Z724JFU6.js} +80 -9
- package/chunk-Z724JFU6.js.map +1 -0
- package/{index-BpBCVun3.d.cts → index-BJwthmNK.d.cts} +10 -2
- package/{index-Dnurrov8.d.ts → index-Bh_2ZgIk.d.ts} +10 -2
- package/index.cjs +93 -14
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +15 -7
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/src/jsr.json +1 -1
- package/src/path-ops.ts +21 -6
- package/src/uri.ts +93 -9
- package/test/index.cjs +79 -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 +1 -1
- package/ts/src/path-ops.d.ts.map +1 -1
- package/ts/src/path-ops.js +17 -6
- package/ts/src/path-ops.js.map +1 -1
- package/ts/src/path-ops.test.js +20 -4
- package/ts/src/path-ops.test.js.map +1 -1
- package/ts/src/uri.d.ts +10 -2
- package/ts/src/uri.d.ts.map +1 -1
- package/ts/src/uri.js +79 -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/chunk-FZHQTSQU.js.map +0 -1
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
|
}
|
@@ -744,6 +753,7 @@ function isURL(value) {
|
|
744
753
|
}
|
745
754
|
var customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
746
755
|
var MutableURL = class _MutableURL extends URL {
|
756
|
+
// override readonly hash: string;
|
747
757
|
constructor(urlStr) {
|
748
758
|
super("defect://does.not.exist");
|
749
759
|
const partedURL = urlStr.split(":");
|
@@ -766,7 +776,6 @@ var MutableURL = class _MutableURL extends URL {
|
|
766
776
|
} else {
|
767
777
|
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
768
778
|
}
|
769
|
-
this.hash = this._sysURL.hash;
|
770
779
|
}
|
771
780
|
[customInspectSymbol]() {
|
772
781
|
return this.toString();
|
@@ -821,16 +830,26 @@ var MutableURL = class _MutableURL extends URL {
|
|
821
830
|
}
|
822
831
|
this._protocol = p;
|
823
832
|
}
|
833
|
+
get hash() {
|
834
|
+
return this._sysURL.hash;
|
835
|
+
}
|
836
|
+
set hash(h) {
|
837
|
+
this._sysURL.hash = h;
|
838
|
+
}
|
824
839
|
get searchParams() {
|
825
840
|
return this._sysURL.searchParams;
|
826
841
|
}
|
827
|
-
|
842
|
+
get search() {
|
828
843
|
let search = "";
|
829
844
|
if (this._sysURL.searchParams.size) {
|
830
845
|
for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
831
846
|
search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
|
832
847
|
}
|
833
848
|
}
|
849
|
+
return search;
|
850
|
+
}
|
851
|
+
toString() {
|
852
|
+
const search = this.search;
|
834
853
|
let hostpart = "";
|
835
854
|
if (this._hasHostpart) {
|
836
855
|
hostpart = this._sysURL.hostname;
|
@@ -841,7 +860,7 @@ var MutableURL = class _MutableURL extends URL {
|
|
841
860
|
hostpart += "/";
|
842
861
|
}
|
843
862
|
}
|
844
|
-
return `${this._protocol}//${hostpart}${this._pathname}${search}`;
|
863
|
+
return `${this._protocol}//${hostpart}${this._pathname}${search}${this.hash}`;
|
845
864
|
}
|
846
865
|
};
|
847
866
|
function from(fac, strURLUri, defaultProtocol) {
|
@@ -904,6 +923,10 @@ var BuildURI = class _BuildURI {
|
|
904
923
|
this._url.pathname = p;
|
905
924
|
return this;
|
906
925
|
}
|
926
|
+
hash(h) {
|
927
|
+
this._url.hash = h;
|
928
|
+
return this;
|
929
|
+
}
|
907
930
|
// could pass a relative path or a full URL
|
908
931
|
// if relative path, it will be appended to the current path
|
909
932
|
resolve(p) {
|
@@ -932,10 +955,49 @@ var BuildURI = class _BuildURI {
|
|
932
955
|
}
|
933
956
|
return this;
|
934
957
|
}
|
935
|
-
cleanParams() {
|
958
|
+
cleanParams(...remove) {
|
959
|
+
const keys = new Set(remove.flat());
|
936
960
|
for (const key of Array.from(this._url.searchParams.keys())) {
|
937
|
-
|
961
|
+
if (keys.size === 0 || keys.has(key)) {
|
962
|
+
this._url.searchParams.delete(key);
|
963
|
+
}
|
964
|
+
}
|
965
|
+
return this;
|
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
|
+
}
|
938
999
|
}
|
1000
|
+
this._url.hash = out.toString();
|
939
1001
|
return this;
|
940
1002
|
}
|
941
1003
|
delParam(key) {
|
@@ -972,6 +1034,9 @@ var BuildURI = class _BuildURI {
|
|
972
1034
|
getParamsResult(...keys) {
|
973
1035
|
return getParamsResult(keys, this);
|
974
1036
|
}
|
1037
|
+
getHashParams(...keys) {
|
1038
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1039
|
+
}
|
975
1040
|
toString() {
|
976
1041
|
this._url.searchParams.sort();
|
977
1042
|
return this._url.toString();
|
@@ -1055,6 +1120,9 @@ var URI = class _URI {
|
|
1055
1120
|
get hostname() {
|
1056
1121
|
return this._url.hostname;
|
1057
1122
|
}
|
1123
|
+
get local() {
|
1124
|
+
return this._url.pathname + this._url.search;
|
1125
|
+
}
|
1058
1126
|
// get password(): string {
|
1059
1127
|
// return this._url.password;
|
1060
1128
|
// }
|
@@ -1076,9 +1144,9 @@ var URI = class _URI {
|
|
1076
1144
|
get pathname() {
|
1077
1145
|
return this._url.pathname;
|
1078
1146
|
}
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1147
|
+
get hash() {
|
1148
|
+
return this._url.hash;
|
1149
|
+
}
|
1082
1150
|
// get host(): string {
|
1083
1151
|
// return this._url.host;
|
1084
1152
|
// }
|
@@ -1102,6 +1170,9 @@ var URI = class _URI {
|
|
1102
1170
|
getParamsResult(...keys) {
|
1103
1171
|
return getParamsResult(keys, this);
|
1104
1172
|
}
|
1173
|
+
getHashParams(...keys) {
|
1174
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1175
|
+
}
|
1105
1176
|
clone() {
|
1106
1177
|
return new _URI(this._url);
|
1107
1178
|
}
|
@@ -3508,7 +3579,11 @@ var pathOpsImpl = class {
|
|
3508
3579
|
__privateAdd(this, _pathOpsImpl_instances);
|
3509
3580
|
}
|
3510
3581
|
join(...paths) {
|
3511
|
-
|
3582
|
+
const parts = __privateMethod(this, _pathOpsImpl_instances, parts_fn).call(this, paths.filter((i) => i).join("/"));
|
3583
|
+
if (parts.dirname === "" || parts.dirname === ".") {
|
3584
|
+
return parts.basename ? parts.basename : ".";
|
3585
|
+
}
|
3586
|
+
return parts.dirname + "/" + parts.basename;
|
3512
3587
|
}
|
3513
3588
|
dirname(path) {
|
3514
3589
|
return __privateMethod(this, _pathOpsImpl_instances, parts_fn).call(this, path).dirname;
|
@@ -3519,14 +3594,18 @@ var pathOpsImpl = class {
|
|
3519
3594
|
};
|
3520
3595
|
_pathOpsImpl_instances = new WeakSet();
|
3521
3596
|
parts_fn = function(path) {
|
3597
|
+
path = path.replace(/\/+/g, "/").replace(/(\/\.\/)+/g, "/").replace(/\/+$/, "");
|
3522
3598
|
const splitted = path.split("/");
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3599
|
+
if (splitted.length === 1) {
|
3600
|
+
return {
|
3601
|
+
dirname: ".",
|
3602
|
+
basename: splitted[0] === "." ? "" : splitted[0]
|
3603
|
+
};
|
3526
3604
|
}
|
3605
|
+
const basename = splitted.pop();
|
3527
3606
|
return {
|
3528
|
-
dirname:
|
3529
|
-
basename
|
3607
|
+
dirname: splitted.join("/").replace(/^\.\//, ""),
|
3608
|
+
basename
|
3530
3609
|
};
|
3531
3610
|
};
|
3532
3611
|
var pathOps = new pathOpsImpl();
|