@jam-comments/server-utilities 5.10.1 → 5.10.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/dist/cjs/store.js +12 -2
- package/dist/cjs/store.test.js +32 -0
- package/dist/esm/store.js +12 -2
- package/dist/esm/store.test.js +30 -0
- package/dist/types/store.d.ts +1 -0
- package/dist/types/store.test.d.ts +1 -0
- package/package.json +5 -5
package/dist/cjs/store.js
CHANGED
|
@@ -9,10 +9,10 @@ class Store {
|
|
|
9
9
|
this.store = globalThis.jamCommentsStore;
|
|
10
10
|
}
|
|
11
11
|
set(path, markup) {
|
|
12
|
-
this.store.set(path, markup);
|
|
12
|
+
this.store.set(this.#normalizePath(path), markup);
|
|
13
13
|
}
|
|
14
14
|
get(path) {
|
|
15
|
-
return this.store.get(path) || null;
|
|
15
|
+
return this.store.get(this.#normalizePath(path)) || null;
|
|
16
16
|
}
|
|
17
17
|
clear() {
|
|
18
18
|
this.store.clear();
|
|
@@ -23,5 +23,15 @@ class Store {
|
|
|
23
23
|
get emptyMarkup() {
|
|
24
24
|
return this.store.get("EMPTY") || null;
|
|
25
25
|
}
|
|
26
|
+
#normalizePath(path) {
|
|
27
|
+
if (path === "EMPTY") {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
let withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
|
|
31
|
+
let withNoTrailingSlash = withLeadingSlash.endsWith("/")
|
|
32
|
+
? withLeadingSlash.slice(0, -1)
|
|
33
|
+
: withLeadingSlash;
|
|
34
|
+
return withNoTrailingSlash.toLowerCase();
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
exports.Store = Store;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const store_1 = require("./store");
|
|
5
|
+
(0, vitest_1.describe)("paths", () => {
|
|
6
|
+
(0, vitest_1.it)("cleans path when setting markup", () => {
|
|
7
|
+
const store = new store_1.Store();
|
|
8
|
+
store.set("/path", "markup");
|
|
9
|
+
(0, vitest_1.expect)(store.get("/path")).toEqual("markup");
|
|
10
|
+
(0, vitest_1.expect)(store.get("path")).toEqual("markup");
|
|
11
|
+
(0, vitest_1.expect)(store.get("path/")).toEqual("markup");
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)("cleans path with mixed casing", () => {
|
|
14
|
+
const store = new store_1.Store();
|
|
15
|
+
store.set("/Path", "markup");
|
|
16
|
+
(0, vitest_1.expect)(store.get("/path")).toEqual("markup");
|
|
17
|
+
(0, vitest_1.expect)(store.get("path")).toEqual("markup");
|
|
18
|
+
(0, vitest_1.expect)(store.get("path/")).toEqual("markup");
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.it)("works just fine with deep paths", () => {
|
|
21
|
+
const store = new store_1.Store();
|
|
22
|
+
store.set("/path/to/deep", "markup");
|
|
23
|
+
(0, vitest_1.expect)(store.get("/path/to/deep")).toEqual("markup");
|
|
24
|
+
(0, vitest_1.expect)(store.get("path/to/deep")).toEqual("markup");
|
|
25
|
+
(0, vitest_1.expect)(store.get("path/to/deep/")).toEqual("markup");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)("retrieves EMPTY markup", () => {
|
|
29
|
+
const store = new store_1.Store();
|
|
30
|
+
store.set("EMPTY", "empty markup");
|
|
31
|
+
(0, vitest_1.expect)(store.emptyMarkup).toEqual("empty markup");
|
|
32
|
+
});
|
package/dist/esm/store.js
CHANGED
|
@@ -6,10 +6,10 @@ export class Store {
|
|
|
6
6
|
this.store = globalThis.jamCommentsStore;
|
|
7
7
|
}
|
|
8
8
|
set(path, markup) {
|
|
9
|
-
this.store.set(path, markup);
|
|
9
|
+
this.store.set(this.#normalizePath(path), markup);
|
|
10
10
|
}
|
|
11
11
|
get(path) {
|
|
12
|
-
return this.store.get(path) || null;
|
|
12
|
+
return this.store.get(this.#normalizePath(path)) || null;
|
|
13
13
|
}
|
|
14
14
|
clear() {
|
|
15
15
|
this.store.clear();
|
|
@@ -20,4 +20,14 @@ export class Store {
|
|
|
20
20
|
get emptyMarkup() {
|
|
21
21
|
return this.store.get("EMPTY") || null;
|
|
22
22
|
}
|
|
23
|
+
#normalizePath(path) {
|
|
24
|
+
if (path === "EMPTY") {
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
let withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
|
|
28
|
+
let withNoTrailingSlash = withLeadingSlash.endsWith("/")
|
|
29
|
+
? withLeadingSlash.slice(0, -1)
|
|
30
|
+
: withLeadingSlash;
|
|
31
|
+
return withNoTrailingSlash.toLowerCase();
|
|
32
|
+
}
|
|
23
33
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Store } from "./store";
|
|
3
|
+
describe("paths", () => {
|
|
4
|
+
it("cleans path when setting markup", () => {
|
|
5
|
+
const store = new Store();
|
|
6
|
+
store.set("/path", "markup");
|
|
7
|
+
expect(store.get("/path")).toEqual("markup");
|
|
8
|
+
expect(store.get("path")).toEqual("markup");
|
|
9
|
+
expect(store.get("path/")).toEqual("markup");
|
|
10
|
+
});
|
|
11
|
+
it("cleans path with mixed casing", () => {
|
|
12
|
+
const store = new Store();
|
|
13
|
+
store.set("/Path", "markup");
|
|
14
|
+
expect(store.get("/path")).toEqual("markup");
|
|
15
|
+
expect(store.get("path")).toEqual("markup");
|
|
16
|
+
expect(store.get("path/")).toEqual("markup");
|
|
17
|
+
});
|
|
18
|
+
it("works just fine with deep paths", () => {
|
|
19
|
+
const store = new Store();
|
|
20
|
+
store.set("/path/to/deep", "markup");
|
|
21
|
+
expect(store.get("/path/to/deep")).toEqual("markup");
|
|
22
|
+
expect(store.get("path/to/deep")).toEqual("markup");
|
|
23
|
+
expect(store.get("path/to/deep/")).toEqual("markup");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("retrieves EMPTY markup", () => {
|
|
27
|
+
const store = new Store();
|
|
28
|
+
store.set("EMPTY", "empty markup");
|
|
29
|
+
expect(store.emptyMarkup).toEqual("empty markup");
|
|
30
|
+
});
|
package/dist/types/store.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jam-comments/server-utilities",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.2",
|
|
4
4
|
"description": "Various JavaScript utilities for JamComments.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"homepage": "https://jamcomments.com",
|
|
23
23
|
"license": "GPL-2.0",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^22.
|
|
25
|
+
"@types/node": "^22.9.0",
|
|
26
26
|
"prettier": "^3.3.3",
|
|
27
|
-
"typescript": "^5.
|
|
28
|
-
"vite": "^5.4.
|
|
29
|
-
"vitest": "^2.
|
|
27
|
+
"typescript": "^5.6.3",
|
|
28
|
+
"vite": "^5.4.11",
|
|
29
|
+
"vitest": "^2.1.5"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|