Created
February 27, 2025 12:31
-
-
Save cbfn/e160bb9ad28f79022aef940377635903 to your computer and use it in GitHub Desktop.
Depara para normalizar dados
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
export const normalizarDados = <T extends Record<string, any>>( | |
data: T, | |
depara: Record<string, string>[] | |
): T => { | |
const mapping = new Map<string, string>(); | |
depara.forEach((obj) => { | |
Object.entries(obj).forEach(([key, value]) => mapping.set(key, value)); | |
}); | |
return Object.keys(data).reduce<Record<string, any>>((acc, key) => { | |
const newKey = mapping.get(key) || key; | |
acc[newKey] = data[key]; | |
return acc; | |
}, {}) as T; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment