@jam-comments/server-utilities 5.12.1 → 5.13.0
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/markupFetcher.js +0 -1
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.js +14 -0
- package/dist/cjs/utils.test.js +27 -0
- package/dist/esm/markupFetcher.js +0 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.js +13 -0
- package/dist/esm/utils.test.js +28 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/markupFetcher.d.ts +0 -11
- package/dist/types/types.d.ts +22 -0
- package/dist/types/utils.d.ts +3 -0
- package/package.json +6 -6
package/dist/cjs/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.getEnvironment = getEnvironment;
|
|
|
5
5
|
exports.parseJson = parseJson;
|
|
6
6
|
exports.unescapeHTML = unescapeHTML;
|
|
7
7
|
exports.removeFalseyValues = removeFalseyValues;
|
|
8
|
+
exports.copyToUnderscored = copyToUnderscored;
|
|
8
9
|
function isValidTimezone(tz) {
|
|
9
10
|
try {
|
|
10
11
|
Intl.DateTimeFormat(undefined, { timeZone: tz });
|
|
@@ -65,3 +66,16 @@ function removeFalseyValues(obj) {
|
|
|
65
66
|
const filteredItems = Object.entries(obj).filter(([, value]) => value);
|
|
66
67
|
return Object.fromEntries(filteredItems);
|
|
67
68
|
}
|
|
69
|
+
function copyToUnderscored(copy) {
|
|
70
|
+
return removeFalseyValues({
|
|
71
|
+
copy_confirmation_message: copy.confirmationMessage,
|
|
72
|
+
copy_submit_button: copy.submitButton,
|
|
73
|
+
copy_name_placeholder: copy.namePlaceholder,
|
|
74
|
+
copy_email_placeholder: copy.emailPlaceholder,
|
|
75
|
+
copy_comment_placeholder: copy.commentPlaceholder,
|
|
76
|
+
copy_write_tab: copy.writeTab,
|
|
77
|
+
copy_preview_tab: copy.previewTab,
|
|
78
|
+
copy_auth_button: copy.authButton,
|
|
79
|
+
copy_log_out_button: copy.logOutButton,
|
|
80
|
+
});
|
|
81
|
+
}
|
package/dist/cjs/utils.test.js
CHANGED
|
@@ -10,6 +10,33 @@ const env = process.env;
|
|
|
10
10
|
(0, vitest_1.afterEach)(() => {
|
|
11
11
|
process.env = env;
|
|
12
12
|
});
|
|
13
|
+
(0, vitest_1.describe)("copyToUnderscored()", () => {
|
|
14
|
+
(0, vitest_1.it)("should convert copy object to underscored keys", () => {
|
|
15
|
+
const copy = {
|
|
16
|
+
confirmationMessage: "Thank you for your comment!",
|
|
17
|
+
submitButton: "Submit",
|
|
18
|
+
namePlaceholder: "Name",
|
|
19
|
+
emailPlaceholder: "Email",
|
|
20
|
+
commentPlaceholder: "Comment",
|
|
21
|
+
writeTab: "Write",
|
|
22
|
+
previewTab: "Preview",
|
|
23
|
+
authButton: "Auth",
|
|
24
|
+
logOutButton: "Log Out",
|
|
25
|
+
};
|
|
26
|
+
const result = (0, utils_1.copyToUnderscored)(copy);
|
|
27
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
28
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
29
|
+
copy_submit_button: "Submit",
|
|
30
|
+
copy_name_placeholder: "Name",
|
|
31
|
+
copy_email_placeholder: "Email",
|
|
32
|
+
copy_comment_placeholder: "Comment",
|
|
33
|
+
copy_write_tab: "Write",
|
|
34
|
+
copy_preview_tab: "Preview",
|
|
35
|
+
copy_auth_button: "Auth",
|
|
36
|
+
copy_log_out_button: "Log Out",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
13
40
|
(0, vitest_1.describe)("getEnvironment()", () => {
|
|
14
41
|
(0, vitest_1.describe)("NODE_ENV is set", () => {
|
|
15
42
|
(0, vitest_1.it)("returns environment", () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/utils.js
CHANGED
|
@@ -58,3 +58,16 @@ export function removeFalseyValues(obj) {
|
|
|
58
58
|
const filteredItems = Object.entries(obj).filter(([, value]) => value);
|
|
59
59
|
return Object.fromEntries(filteredItems);
|
|
60
60
|
}
|
|
61
|
+
export function copyToUnderscored(copy) {
|
|
62
|
+
return removeFalseyValues({
|
|
63
|
+
copy_confirmation_message: copy.confirmationMessage,
|
|
64
|
+
copy_submit_button: copy.submitButton,
|
|
65
|
+
copy_name_placeholder: copy.namePlaceholder,
|
|
66
|
+
copy_email_placeholder: copy.emailPlaceholder,
|
|
67
|
+
copy_comment_placeholder: copy.commentPlaceholder,
|
|
68
|
+
copy_write_tab: copy.writeTab,
|
|
69
|
+
copy_preview_tab: copy.previewTab,
|
|
70
|
+
copy_auth_button: copy.authButton,
|
|
71
|
+
copy_log_out_button: copy.logOutButton,
|
|
72
|
+
});
|
|
73
|
+
}
|
package/dist/esm/utils.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { getEnvironment, removeFalseyValues } from "./utils";
|
|
2
|
+
import { getEnvironment, removeFalseyValues, copyToUnderscored } from "./utils";
|
|
3
3
|
const env = process.env;
|
|
4
4
|
beforeEach(() => {
|
|
5
5
|
vi.resetModules();
|
|
@@ -8,6 +8,33 @@ beforeEach(() => {
|
|
|
8
8
|
afterEach(() => {
|
|
9
9
|
process.env = env;
|
|
10
10
|
});
|
|
11
|
+
describe("copyToUnderscored()", () => {
|
|
12
|
+
it("should convert copy object to underscored keys", () => {
|
|
13
|
+
const copy = {
|
|
14
|
+
confirmationMessage: "Thank you for your comment!",
|
|
15
|
+
submitButton: "Submit",
|
|
16
|
+
namePlaceholder: "Name",
|
|
17
|
+
emailPlaceholder: "Email",
|
|
18
|
+
commentPlaceholder: "Comment",
|
|
19
|
+
writeTab: "Write",
|
|
20
|
+
previewTab: "Preview",
|
|
21
|
+
authButton: "Auth",
|
|
22
|
+
logOutButton: "Log Out",
|
|
23
|
+
};
|
|
24
|
+
const result = copyToUnderscored(copy);
|
|
25
|
+
expect(result).toEqual({
|
|
26
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
27
|
+
copy_submit_button: "Submit",
|
|
28
|
+
copy_name_placeholder: "Name",
|
|
29
|
+
copy_email_placeholder: "Email",
|
|
30
|
+
copy_comment_placeholder: "Comment",
|
|
31
|
+
copy_write_tab: "Write",
|
|
32
|
+
copy_preview_tab: "Preview",
|
|
33
|
+
copy_auth_button: "Auth",
|
|
34
|
+
copy_log_out_button: "Log Out",
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
11
38
|
describe("getEnvironment()", () => {
|
|
12
39
|
describe("NODE_ENV is set", () => {
|
|
13
40
|
it("returns environment", () => {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { Store } from "./store";
|
|
2
|
-
export interface CustomCopy {
|
|
3
|
-
confirmationMessage?: string;
|
|
4
|
-
submitButton?: string;
|
|
5
|
-
namePlaceholder?: string;
|
|
6
|
-
emailPlaceholder?: string;
|
|
7
|
-
commentPlaceholder?: string;
|
|
8
|
-
writeTab?: string;
|
|
9
|
-
previewTab?: string;
|
|
10
|
-
authButton?: string;
|
|
11
|
-
logOutButton?: string;
|
|
12
|
-
}
|
|
13
2
|
export interface IFetchData {
|
|
14
3
|
path: string;
|
|
15
4
|
domain: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface CustomCopy {
|
|
2
|
+
confirmationMessage?: string;
|
|
3
|
+
submitButton?: string;
|
|
4
|
+
namePlaceholder?: string;
|
|
5
|
+
emailPlaceholder?: string;
|
|
6
|
+
commentPlaceholder?: string;
|
|
7
|
+
writeTab?: string;
|
|
8
|
+
previewTab?: string;
|
|
9
|
+
authButton?: string;
|
|
10
|
+
logOutButton?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface UnderscoredCopy {
|
|
13
|
+
copy_confirmation_message?: string;
|
|
14
|
+
copy_submit_button?: string;
|
|
15
|
+
copy_name_placeholder?: string;
|
|
16
|
+
copy_email_placeholder?: string;
|
|
17
|
+
copy_comment_placeholder?: string;
|
|
18
|
+
copy_write_tab?: string;
|
|
19
|
+
copy_preview_tab?: string;
|
|
20
|
+
copy_auth_button?: string;
|
|
21
|
+
copy_log_out_button?: string;
|
|
22
|
+
}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { CustomCopy } from ".";
|
|
2
|
+
import { UnderscoredCopy } from "./types";
|
|
1
3
|
export declare function isValidTimezone(tz: string): boolean;
|
|
2
4
|
export declare function getEnvironment(): string;
|
|
3
5
|
export declare function parseJson(json: string): any;
|
|
4
6
|
export declare function unescapeHTML(str: any): any;
|
|
5
7
|
export declare function removeFalseyValues<T>(obj: T): Partial<T>;
|
|
8
|
+
export declare function copyToUnderscored(copy: CustomCopy): UnderscoredCopy;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jam-comments/server-utilities",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
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.
|
|
26
|
-
"prettier": "^3.4.
|
|
27
|
-
"typescript": "^5.7.
|
|
28
|
-
"vite": "^6.0
|
|
29
|
-
"vitest": "^
|
|
25
|
+
"@types/node": "^22.13.1",
|
|
26
|
+
"prettier": "^3.4.2",
|
|
27
|
+
"typescript": "^5.7.3",
|
|
28
|
+
"vite": "^6.1.0",
|
|
29
|
+
"vitest": "^3.0.5"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|