@jam-comments/server-utilities 5.2.0 → 5.3.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/index.js +2 -1
- package/dist/cjs/utils.js +5 -0
- package/dist/cjs/utils.test.js +19 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils.js +4 -0
- package/dist/esm/utils.test.js +20 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logError = exports.log = exports.deleteTempDirectory = exports.fetchAll = exports.markupFetcher = exports.TEMP_DIRECTORY = void 0;
|
|
6
|
+
exports.logError = exports.log = exports.removeFalseyValues = exports.deleteTempDirectory = exports.fetchAll = exports.markupFetcher = exports.TEMP_DIRECTORY = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
exports.TEMP_DIRECTORY = path_1.default.join(process.cwd(), "_temp_jc");
|
|
9
9
|
var markupFetcher_1 = require("./markupFetcher");
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "markupFetcher", { enumerable: true, get: functio
|
|
|
11
11
|
Object.defineProperty(exports, "fetchAll", { enumerable: true, get: function () { return markupFetcher_1.fetchAll; } });
|
|
12
12
|
var utils_1 = require("./utils");
|
|
13
13
|
Object.defineProperty(exports, "deleteTempDirectory", { enumerable: true, get: function () { return utils_1.deleteTempDirectory; } });
|
|
14
|
+
Object.defineProperty(exports, "removeFalseyValues", { enumerable: true, get: function () { return utils_1.removeFalseyValues; } });
|
|
14
15
|
var log_1 = require("./log");
|
|
15
16
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return log_1.log; } });
|
|
16
17
|
Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return log_1.logError; } });
|
package/dist/cjs/utils.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.readFile = readFile;
|
|
|
11
11
|
exports.getEmptyMarkup = getEmptyMarkup;
|
|
12
12
|
exports.tempDirectoryExists = tempDirectoryExists;
|
|
13
13
|
exports.saveFile = saveFile;
|
|
14
|
+
exports.removeFalseyValues = removeFalseyValues;
|
|
14
15
|
const fs_1 = require("fs");
|
|
15
16
|
const _1 = require(".");
|
|
16
17
|
function isValidTimezone(tz) {
|
|
@@ -105,3 +106,7 @@ function saveFile(name, data, writeFileImpl = fs_1.writeFile) {
|
|
|
105
106
|
});
|
|
106
107
|
});
|
|
107
108
|
}
|
|
109
|
+
function removeFalseyValues(obj) {
|
|
110
|
+
const filteredItems = Object.entries(obj).filter(([, value]) => value);
|
|
111
|
+
return Object.fromEntries(filteredItems);
|
|
112
|
+
}
|
package/dist/cjs/utils.test.js
CHANGED
|
@@ -87,3 +87,22 @@ const env = process.env;
|
|
|
87
87
|
(0, vitest_1.expect)(result).toBeInstanceOf(Promise);
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
|
+
(0, vitest_1.describe)("removeFalseyValues()", () => {
|
|
91
|
+
(0, vitest_1.it)("should remove falsey values", () => {
|
|
92
|
+
(0, vitest_1.expect)((0, utils_1.removeFalseyValues)({ a: 1, b: 0, d: null, e: "" })).toEqual({
|
|
93
|
+
a: 1,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.it)("should remove undefined items", () => {
|
|
97
|
+
const customCopy = {
|
|
98
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
99
|
+
copy_submit_button: "Submit",
|
|
100
|
+
copy_name_placeholder: undefined,
|
|
101
|
+
};
|
|
102
|
+
const result = (0, utils_1.removeFalseyValues)(customCopy);
|
|
103
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
104
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
105
|
+
copy_submit_button: "Submit",
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
export const TEMP_DIRECTORY = path.join(process.cwd(), "_temp_jc");
|
|
3
3
|
export { markupFetcher, fetchAll } from "./markupFetcher";
|
|
4
|
-
export { deleteTempDirectory } from "./utils";
|
|
4
|
+
export { deleteTempDirectory, removeFalseyValues } from "./utils";
|
|
5
5
|
export { log, logError } from "./log";
|
package/dist/esm/utils.js
CHANGED
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, createTempDirectory, toSavedFileName, readFile, saveFile, } from "./utils";
|
|
2
|
+
import { getEnvironment, createTempDirectory, toSavedFileName, readFile, saveFile, removeFalseyValues, } from "./utils";
|
|
3
3
|
import { TEMP_DIRECTORY } from ".";
|
|
4
4
|
const env = process.env;
|
|
5
5
|
beforeEach(() => {
|
|
@@ -85,3 +85,22 @@ describe("saveFile()", () => {
|
|
|
85
85
|
expect(result).toBeInstanceOf(Promise);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
+
describe("removeFalseyValues()", () => {
|
|
89
|
+
it("should remove falsey values", () => {
|
|
90
|
+
expect(removeFalseyValues({ a: 1, b: 0, d: null, e: "" })).toEqual({
|
|
91
|
+
a: 1,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("should remove undefined items", () => {
|
|
95
|
+
const customCopy = {
|
|
96
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
97
|
+
copy_submit_button: "Submit",
|
|
98
|
+
copy_name_placeholder: undefined,
|
|
99
|
+
};
|
|
100
|
+
const result = removeFalseyValues(customCopy);
|
|
101
|
+
expect(result).toEqual({
|
|
102
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
103
|
+
copy_submit_button: "Submit",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { CustomCopy } from "./markupFetcher";
|
|
2
2
|
export declare const TEMP_DIRECTORY: string;
|
|
3
3
|
export { markupFetcher, fetchAll } from "./markupFetcher";
|
|
4
|
-
export { deleteTempDirectory } from "./utils";
|
|
4
|
+
export { deleteTempDirectory, removeFalseyValues } from "./utils";
|
|
5
5
|
export { log, logError } from "./log";
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare function readFile(name: any, readFileSyncImpl?: typeof readFileSy
|
|
|
10
10
|
export declare function getEmptyMarkup(): string;
|
|
11
11
|
export declare function tempDirectoryExists(existsSyncImpl?: typeof existsSync): boolean;
|
|
12
12
|
export declare function saveFile(name: string, data: string, writeFileImpl?: any): Promise<void>;
|
|
13
|
+
export declare function removeFalseyValues<T>(obj: T): Partial<T>;
|