Whats the best way to map all object properties into a new object format with different property names example:
this is the desired format
const person = {
firstName: 'john',
lastName: 'doe',
houses: [{ housName: 'Kruger' }]
}
and I have these two objects
const person1 = {
prenom: 'john', //this should be mapped to the firstName
nom: 'doe', //this should be mapped to the lastName
houses: [{ house_name: 'Kruger' }]
}
const person2 = {
name: 'john', // this should be mapped to the firstName
familyName: 'doe', // this should be assigned to the lastName
Houses: [{ House_Name: 'Kruger' }]
};
The goals is to make person1 and person2 with all their properties and sub properties look like person.
I HAVE TRIED
export class Person {
@Expose({ name: 'prenom' })
firstName: string;
@Expose({ name: 'nom' })
lastName: string;
}
}
//this should give a formatted version from person1 ==> person
const formatted = plainToClass(person1,Person)
However this would require me to create multiple iterations of Person class which is not convenient if we would like to use this class for typing.