@@ -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}
0 commit comments