Skip to content

Instantly share code, notes, and snippets.

@cbfn
Created February 27, 2025 12:31
Show Gist options
  • Save cbfn/e160bb9ad28f79022aef940377635903 to your computer and use it in GitHub Desktop.
Save cbfn/e160bb9ad28f79022aef940377635903 to your computer and use it in GitHub Desktop.
Depara para normalizar dados
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