@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/test/index.cjs
CHANGED
@@ -1211,6 +1211,15 @@ function coerceKey(key, def) {
|
|
1211
1211
|
}
|
1212
1212
|
return { key, def };
|
1213
1213
|
}
|
1214
|
+
function resolveHash(hash) {
|
1215
|
+
const searchParams = new URLSearchParams(hash.replace(/^#/, ""));
|
1216
|
+
return {
|
1217
|
+
getParam: (k) => {
|
1218
|
+
const ret = searchParams.get(k);
|
1219
|
+
return ret === null ? void 0 : ret;
|
1220
|
+
}
|
1221
|
+
};
|
1222
|
+
}
|
1214
1223
|
function falsy2undef(value) {
|
1215
1224
|
return value === void 0 || value === null ? void 0 : value;
|
1216
1225
|
}
|
@@ -1233,6 +1242,7 @@ function isURL(value) {
|
|
1233
1242
|
}
|
1234
1243
|
var customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
1235
1244
|
var MutableURL = class _MutableURL extends URL {
|
1245
|
+
// override readonly hash: string;
|
1236
1246
|
constructor(urlStr) {
|
1237
1247
|
super("defect://does.not.exist");
|
1238
1248
|
const partedURL = urlStr.split(":");
|
@@ -1255,7 +1265,6 @@ var MutableURL = class _MutableURL extends URL {
|
|
1255
1265
|
} else {
|
1256
1266
|
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
1257
1267
|
}
|
1258
|
-
this.hash = this._sysURL.hash;
|
1259
1268
|
}
|
1260
1269
|
[customInspectSymbol]() {
|
1261
1270
|
return this.toString();
|
@@ -1310,16 +1319,26 @@ var MutableURL = class _MutableURL extends URL {
|
|
1310
1319
|
}
|
1311
1320
|
this._protocol = p;
|
1312
1321
|
}
|
1322
|
+
get hash() {
|
1323
|
+
return this._sysURL.hash;
|
1324
|
+
}
|
1325
|
+
set hash(h) {
|
1326
|
+
this._sysURL.hash = h;
|
1327
|
+
}
|
1313
1328
|
get searchParams() {
|
1314
1329
|
return this._sysURL.searchParams;
|
1315
1330
|
}
|
1316
|
-
|
1331
|
+
get search() {
|
1317
1332
|
let search = "";
|
1318
1333
|
if (this._sysURL.searchParams.size) {
|
1319
1334
|
for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
1320
1335
|
search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
|
1321
1336
|
}
|
1322
1337
|
}
|
1338
|
+
return search;
|
1339
|
+
}
|
1340
|
+
toString() {
|
1341
|
+
const search = this.search;
|
1323
1342
|
let hostpart = "";
|
1324
1343
|
if (this._hasHostpart) {
|
1325
1344
|
hostpart = this._sysURL.hostname;
|
@@ -1330,7 +1349,7 @@ var MutableURL = class _MutableURL extends URL {
|
|
1330
1349
|
hostpart += "/";
|
1331
1350
|
}
|
1332
1351
|
}
|
1333
|
-
return `${this._protocol}//${hostpart}${this._pathname}${search}`;
|
1352
|
+
return `${this._protocol}//${hostpart}${this._pathname}${search}${this.hash}`;
|
1334
1353
|
}
|
1335
1354
|
};
|
1336
1355
|
function from(fac, strURLUri, defaultProtocol) {
|
@@ -1393,6 +1412,10 @@ var BuildURI = class _BuildURI {
|
|
1393
1412
|
this._url.pathname = p;
|
1394
1413
|
return this;
|
1395
1414
|
}
|
1415
|
+
hash(h) {
|
1416
|
+
this._url.hash = h;
|
1417
|
+
return this;
|
1418
|
+
}
|
1396
1419
|
// could pass a relative path or a full URL
|
1397
1420
|
// if relative path, it will be appended to the current path
|
1398
1421
|
resolve(p) {
|
@@ -1421,12 +1444,51 @@ var BuildURI = class _BuildURI {
|
|
1421
1444
|
}
|
1422
1445
|
return this;
|
1423
1446
|
}
|
1424
|
-
cleanParams() {
|
1447
|
+
cleanParams(...remove) {
|
1448
|
+
const keys = new Set(remove.flat());
|
1425
1449
|
for (const key of Array.from(this._url.searchParams.keys())) {
|
1426
|
-
|
1450
|
+
if (keys.size === 0 || keys.has(key)) {
|
1451
|
+
this._url.searchParams.delete(key);
|
1452
|
+
}
|
1427
1453
|
}
|
1428
1454
|
return this;
|
1429
1455
|
}
|
1456
|
+
hashParams(val, mode = "reset") {
|
1457
|
+
let preset;
|
1458
|
+
switch (mode) {
|
1459
|
+
case "reset":
|
1460
|
+
this._url.hash = "";
|
1461
|
+
preset = {};
|
1462
|
+
break;
|
1463
|
+
case "merge":
|
1464
|
+
default:
|
1465
|
+
preset = Object.fromEntries(new URLSearchParams(this._url.hash.replace(/^#/, "")).entries());
|
1466
|
+
break;
|
1467
|
+
}
|
1468
|
+
const out = new URLSearchParams("");
|
1469
|
+
for (const [key, value] of Object.entries({ ...preset, ...val }).sort((a, b) => a[0].localeCompare(b[0]))) {
|
1470
|
+
switch (typeof value) {
|
1471
|
+
case "string":
|
1472
|
+
out.set(key, value);
|
1473
|
+
break;
|
1474
|
+
case "number":
|
1475
|
+
out.set(key, value.toString());
|
1476
|
+
break;
|
1477
|
+
case "boolean":
|
1478
|
+
out.set(key, value ? "true" : "false");
|
1479
|
+
break;
|
1480
|
+
default:
|
1481
|
+
if (value instanceof Date) {
|
1482
|
+
out.set(key, value.toISOString());
|
1483
|
+
} else {
|
1484
|
+
console.error(`unsupported type: ${typeof value} ignore key: ${key}`);
|
1485
|
+
}
|
1486
|
+
break;
|
1487
|
+
}
|
1488
|
+
}
|
1489
|
+
this._url.hash = out.toString();
|
1490
|
+
return this;
|
1491
|
+
}
|
1430
1492
|
delParam(key) {
|
1431
1493
|
this._url.searchParams.delete(key);
|
1432
1494
|
return this;
|
@@ -1461,6 +1523,9 @@ var BuildURI = class _BuildURI {
|
|
1461
1523
|
getParamsResult(...keys) {
|
1462
1524
|
return getParamsResult(keys, this);
|
1463
1525
|
}
|
1526
|
+
getHashParams(...keys) {
|
1527
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1528
|
+
}
|
1464
1529
|
toString() {
|
1465
1530
|
this._url.searchParams.sort();
|
1466
1531
|
return this._url.toString();
|
@@ -1526,6 +1591,9 @@ var URI = class _URI {
|
|
1526
1591
|
get hostname() {
|
1527
1592
|
return this._url.hostname;
|
1528
1593
|
}
|
1594
|
+
get local() {
|
1595
|
+
return this._url.pathname + this._url.search;
|
1596
|
+
}
|
1529
1597
|
// get password(): string {
|
1530
1598
|
// return this._url.password;
|
1531
1599
|
// }
|
@@ -1547,9 +1615,9 @@ var URI = class _URI {
|
|
1547
1615
|
get pathname() {
|
1548
1616
|
return this._url.pathname;
|
1549
1617
|
}
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1618
|
+
get hash() {
|
1619
|
+
return this._url.hash;
|
1620
|
+
}
|
1553
1621
|
// get host(): string {
|
1554
1622
|
// return this._url.host;
|
1555
1623
|
// }
|
@@ -1573,6 +1641,9 @@ var URI = class _URI {
|
|
1573
1641
|
getParamsResult(...keys) {
|
1574
1642
|
return getParamsResult(keys, this);
|
1575
1643
|
}
|
1644
|
+
getHashParams(...keys) {
|
1645
|
+
return getParamsResult(keys, resolveHash(this._url.hash));
|
1646
|
+
}
|
1576
1647
|
clone() {
|
1577
1648
|
return new _URI(this._url);
|
1578
1649
|
}
|