Created
September 4, 2022 07:39
-
-
Save MRezaSafari/c5198e258885687522a8f2222f232dcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function serverObjectsSanitizer<T>(input: T, ignoreList: string[]): T { | |
if (Array.isArray(input)) | |
return input.map((i) => | |
serverObjectsSanitizer(i, ignoreList) | |
) as unknown as T; | |
if (typeof input == 'object' && input != null) | |
return Object.keys(input).reduce((t, c) => { | |
const before = input[c]; | |
if (ignoreList.indexOf(c) > -1) { | |
delete t[c]; | |
} else { | |
t[c] = serverObjectsSanitizer(before, ignoreList); | |
} | |
return t; | |
}, {}) as unknown as T; | |
return input as unknown as T; | |
} | |
export default serverObjectsSanitizer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's why I hate it. Otherwise, there is NOTHING difficult in this code that makes it hard to understand :)