Skip to content

Commit 5a34dcb

Browse files
authored
Merge pull request #58 from fullstack-build/development
Development
2 parents e71664d + 5160ae9 commit 5a34dcb

File tree

8 files changed

+2348
-1334
lines changed

8 files changed

+2348
-1334
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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", "plugin:prettier/recommended"],
10+
extends: [ "@rushstack/eslint-config/profile/node", "plugin:prettier/recommended"],
1111
ignorePatterns: ["node_modules/", "dist/", "tests/", "*.test.ts", "example/"],
1212
env: {
1313
node: true,

package-lock.json

Lines changed: 2005 additions & 1203 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@
3333
"testMatch": [
3434
"/**/*.test.ts",
3535
"/**/node_modules_test/*.test.ts"
36-
],
37-
"globals": {
38-
"ts-jest": {
39-
"packageJson": "package.json"
40-
}
41-
}
36+
]
4237
},
4338
"np": {
4439
"yarn": false,
@@ -61,25 +56,25 @@
6156
},
6257
"homepage": "https://tslog.js.org",
6358
"devDependencies": {
64-
"@microsoft/api-extractor": "^7.9.2",
65-
"@rushstack/eslint-config": "^1.0.2",
59+
"@microsoft/api-extractor": "^7.11.2",
60+
"@rushstack/eslint-config": "^2.3.0",
6661
"@types/jest": "^26.0.4",
6762
"@types/node": "^14.0.23",
6863
"@types/source-map-support": "^0.5.2",
6964
"coveralls": "^3.1.0",
70-
"docsify": "^4.11.4",
71-
"eslint": "^7.4.0",
72-
"eslint-config-prettier": "^6.11.0",
65+
"docsify": "^4.11.6",
66+
"eslint": "^7.13.0",
67+
"eslint-config-prettier": "^6.15.0",
7368
"eslint-plugin-prettier": "^3.1.4",
7469
"git-hooks": "^1.1.10",
75-
"jest": "^26.1.0",
76-
"np": "^6.3.2",
77-
"onchange": "^7.0.2",
78-
"prettier": "^2.0.5",
79-
"ts-jest": "^26.1.2",
80-
"ts-node": "^8.10.2",
81-
"typedoc": "^0.17.8",
82-
"typescript": "^3.9.3"
70+
"jest": "^26.6.3",
71+
"np": "^7.0.0",
72+
"onchange": "^7.1.0",
73+
"prettier": "^2.1.2",
74+
"ts-jest": "^26.4.3",
75+
"ts-node": "^9.0.0",
76+
"typedoc": "^0.19.2",
77+
"typescript": "^4.0.5"
8378
},
8479
"dependencies": {
8580
"source-map-support": "^0.5.19"

src/LoggerHelper.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,17 @@ export class LoggerHelper {
144144

145145
public static styleString<T, S>(
146146
styleTypes: T | TUtilsInspectColors[],
147-
str: S | string
147+
str: S | string,
148+
colorizePrettyLogs: boolean = true
148149
): string {
149-
return Object.values(styleTypes).reduce((resultStr: S, styleType: T) => {
150-
return LoggerHelper._stylizeWithColor(
151-
(styleType as unknown) as TUtilsInspectColors,
152-
resultStr
153-
);
154-
}, str);
150+
return colorizePrettyLogs
151+
? Object.values(styleTypes).reduce((resultStr: S, styleType: T) => {
152+
return LoggerHelper._stylizeWithColor(
153+
(styleType as unknown) as TUtilsInspectColors,
154+
resultStr
155+
);
156+
}, str)
157+
: str;
155158
}
156159

157160
private static _stylizeWithColor<T>(
@@ -270,4 +273,50 @@ export class LoggerHelper {
270273
? `0${lineNumber}`
271274
: `${lineNumber}`;
272275
}
276+
277+
public static traverseObjectRecursively<T>(
278+
obj: T,
279+
fn: (key: number | string, value: unknown) => [number | string, unknown],
280+
done: unknown[] = []
281+
): T {
282+
Object.keys(obj).forEach((currentKey: string | number) => {
283+
if (!done.includes(obj[currentKey])) {
284+
done.push(obj[currentKey]);
285+
if (obj[currentKey] != null && typeof obj[currentKey] === "object") {
286+
const [key, value] = fn(currentKey, obj[currentKey]);
287+
obj[key] = LoggerHelper.traverseObjectRecursively(value, fn, done);
288+
} else {
289+
const [key, value] = fn(currentKey, obj[currentKey]);
290+
obj[key] = value;
291+
}
292+
}
293+
});
294+
295+
return obj;
296+
}
297+
298+
public static logObjectMaskValuesOfKeys<T>(
299+
obj: T,
300+
keys: (number | string)[],
301+
maskPlaceholder: string
302+
): T {
303+
const fn = (
304+
key: number | string,
305+
value: unknown
306+
): [number | string, unknown] => {
307+
const keysLowerCase: (
308+
| string
309+
| number
310+
)[] = keys.map((key: string | number) =>
311+
typeof key === "string" ? key.toLowerCase() : key
312+
);
313+
return keysLowerCase.includes(
314+
typeof key === "string" ? key.toLowerCase() : key
315+
)
316+
? [key, maskPlaceholder]
317+
: [key, value];
318+
};
319+
320+
return LoggerHelper.traverseObjectRecursively(obj, fn);
321+
}
273322
}

0 commit comments

Comments
 (0)