@go-mailer/jarvis 7.0.2 → 7.1.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/lib/utilitiy/text.js +19 -4
- package/package.json +1 -1
package/lib/utilitiy/text.js
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
const flattenObject = (object = {}, result = {}) => {
|
|
1
|
+
const flattenObject = (object = {}, result = {}, concatenate_keys = false, root_key = "") => {
|
|
2
2
|
let flattened_object = {};
|
|
3
3
|
|
|
4
4
|
const entries = Object.entries(object);
|
|
5
5
|
|
|
6
6
|
for (let [key, value] of entries) {
|
|
7
|
+
const item_key = root_key && concatenate_keys ? `${root_key}.${key}` : key;
|
|
7
8
|
if (value && typeof value === "object") {
|
|
8
|
-
flattened_object = { ...flattenObject(value, { ...flattened_object }) };
|
|
9
|
+
flattened_object = { ...flattenObject(value, { ...flattened_object }, concatenate_keys, item_key) };
|
|
9
10
|
} else {
|
|
10
|
-
flattened_object[
|
|
11
|
+
flattened_object[item_key] = value;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
return { ...result, ...flattened_object };
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const scrambleSensitiveData = (SENSITIVE_DATA_KEYS = [], object = {}) => {
|
|
19
|
+
const scrambled_data = {};
|
|
20
|
+
for (const [key, value] of Object.entries(object)) {
|
|
21
|
+
scrambled_data[key] = value;
|
|
22
|
+
for (const piid_key of SENSITIVE_DATA_KEYS) {
|
|
23
|
+
if (key.toLowerCase().includes(piid_key.toLowerCase())) {
|
|
24
|
+
scrambled_data[key] = value.toString().replace(/\w/gi, "*");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return scrambled_data;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = { flattenObject, scrambleSensitiveData };
|