Skip to content

Commit 156383c

Browse files
committed
Fix #59
1 parent 38930e0 commit 156383c

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

.eslintrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// This is a workaround for https://github.com/eslint/eslint/issues/3458
2-
require('@rushstack/eslint-config/patch/modern-module-resolution');
2+
require("@rushstack/eslint-config/patch/modern-module-resolution");
33

44
module.exports = {
55
plugins: ["prettier"],
66
rules: {
77
"prettier/prettier": "error",
88
eqeqeq: [2, "smart"],
99
},
10-
extends: [ "@rushstack/eslint-config/profile/node", "plugin:prettier/recommended"],
10+
extends: [
11+
"@rushstack/eslint-config/profile/node",
12+
"plugin:prettier/recommended",
13+
],
1114
ignorePatterns: ["node_modules/", "dist/", "tests/", "*.test.ts", "example/"],
1215
env: {
1316
node: true,

src/LoggerHelper.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,21 @@ export class LoggerHelper {
276276

277277
public static traverseObjectRecursively<T>(
278278
obj: T,
279-
fn: (key: number | string, value: unknown) => [number | string, unknown],
279+
maskValuesFn: (key: number | string, obj: T) => T,
280280
done: unknown[] = []
281281
): T {
282282
Object.keys(obj).forEach((currentKey: string | number) => {
283283
if (!done.includes(obj[currentKey])) {
284284
done.push(obj[currentKey]);
285285
if (obj[currentKey] != null && typeof obj[currentKey] === "object") {
286-
const [key, value] = fn(currentKey, obj[currentKey]);
287-
obj[key] = LoggerHelper.traverseObjectRecursively(value, fn, done);
286+
const maskedObj = maskValuesFn(currentKey, obj);
287+
obj[currentKey] = LoggerHelper.traverseObjectRecursively(
288+
maskedObj[currentKey],
289+
maskValuesFn,
290+
done
291+
);
288292
} else {
289-
const [key, value] = fn(currentKey, obj[currentKey]);
290-
obj[key] = value;
293+
obj = maskValuesFn(currentKey, obj);
291294
}
292295
}
293296
});
@@ -304,23 +307,23 @@ export class LoggerHelper {
304307
return obj;
305308
}
306309

307-
const fn = (
308-
key: number | string,
309-
value: unknown
310-
): [number | string, unknown] => {
310+
const maskValuesFn = <T>(key: number | string, obj: T): T => {
311311
const keysLowerCase: (
312312
| string
313313
| number
314314
)[] = keys.map((key: string | number) =>
315315
typeof key === "string" ? key.toLowerCase() : key
316316
);
317-
return keysLowerCase.includes(
318-
typeof key === "string" ? key.toLowerCase() : key
319-
)
320-
? [key, maskPlaceholder]
321-
: [key, value];
317+
if (
318+
keysLowerCase.includes(
319+
typeof key === "string" ? key.toLowerCase() : key
320+
)
321+
) {
322+
obj[key] = maskPlaceholder;
323+
}
324+
return obj;
322325
};
323326

324-
return LoggerHelper.traverseObjectRecursively(obj, fn);
327+
return LoggerHelper.traverseObjectRecursively(obj, maskValuesFn);
325328
}
326329
}

tests/settings.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ describe("Logger: settings", () => {
817817
stdErr: std,
818818
});
819819

820-
const { argumentsArray: undefinedMaskValuesArgArray } = undefinedMaskValuesLogger.info(verySecretiveCircularObject);
820+
const {
821+
argumentsArray: undefinedMaskValuesArgArray,
822+
} = undefinedMaskValuesLogger.info(verySecretiveCircularObject);
821823
expect(undefinedMaskValuesArgArray[0]).toBe(verySecretiveCircularObject);
822824
});
823825

0 commit comments

Comments
 (0)