@jskit-ai/kernel 0.1.14 → 0.1.16
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
CHANGED
package/shared/support/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { isRecord } from "./normalize.js";
|
|
2
2
|
export { pickOwnProperties } from "./pickOwnProperties.js";
|
|
3
3
|
export { formatDateTime } from "./formatDateTime.js";
|
|
4
|
-
export { appendQueryString } from "./queryPath.js";
|
|
4
|
+
export { appendQueryString, splitPathQueryAndHash } from "./queryPath.js";
|
|
5
5
|
export { normalizePermissionList, hasPermission } from "./permissions.js";
|
|
6
6
|
export {
|
|
7
7
|
normalizeReturnToPath,
|
|
@@ -14,6 +14,24 @@ function splitPathAndHash(path = "") {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function splitPathQueryAndHash(path = "") {
|
|
18
|
+
const { pathWithoutHash, hash } = splitPathAndHash(path);
|
|
19
|
+
const queryIndex = pathWithoutHash.indexOf("?");
|
|
20
|
+
if (queryIndex < 0) {
|
|
21
|
+
return {
|
|
22
|
+
pathname: pathWithoutHash,
|
|
23
|
+
queryString: "",
|
|
24
|
+
hash
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
pathname: pathWithoutHash.slice(0, queryIndex),
|
|
30
|
+
queryString: pathWithoutHash.slice(queryIndex + 1),
|
|
31
|
+
hash
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
function appendQueryString(path = "", queryString = "") {
|
|
18
36
|
const normalizedPath = String(path || "").trim();
|
|
19
37
|
if (!normalizedPath) {
|
|
@@ -30,4 +48,4 @@ function appendQueryString(path = "", queryString = "") {
|
|
|
30
48
|
return `${pathWithoutHash}${separator}${normalizedQuery}${hash}`;
|
|
31
49
|
}
|
|
32
50
|
|
|
33
|
-
export { appendQueryString };
|
|
51
|
+
export { appendQueryString, splitPathQueryAndHash };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import { appendQueryString } from "./queryPath.js";
|
|
3
|
+
import { appendQueryString, splitPathQueryAndHash } from "./queryPath.js";
|
|
4
4
|
|
|
5
5
|
test("appendQueryString appends query to a path without existing search", () => {
|
|
6
6
|
assert.equal(appendQueryString("/api/conversations", "cursor=2"), "/api/conversations?cursor=2");
|
|
@@ -17,3 +17,23 @@ test("appendQueryString preserves hash fragments", () => {
|
|
|
17
17
|
test("appendQueryString ignores empty query strings", () => {
|
|
18
18
|
assert.equal(appendQueryString("/api/conversations", ""), "/api/conversations");
|
|
19
19
|
});
|
|
20
|
+
|
|
21
|
+
test("splitPathQueryAndHash separates pathname, query string, and hash", () => {
|
|
22
|
+
assert.deepEqual(splitPathQueryAndHash("/contacts?search=buddy#top"), {
|
|
23
|
+
pathname: "/contacts",
|
|
24
|
+
queryString: "search=buddy",
|
|
25
|
+
hash: "#top"
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
assert.deepEqual(splitPathQueryAndHash("/contacts#top"), {
|
|
29
|
+
pathname: "/contacts",
|
|
30
|
+
queryString: "",
|
|
31
|
+
hash: "#top"
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
assert.deepEqual(splitPathQueryAndHash("/contacts?search=buddy"), {
|
|
35
|
+
pathname: "/contacts",
|
|
36
|
+
queryString: "search=buddy",
|
|
37
|
+
hash: ""
|
|
38
|
+
});
|
|
39
|
+
});
|