Created
October 29, 2020 09:46
-
-
Save Gummiees/cb9e84e9f5b10348c753cff30fab8d4a to your computer and use it in GitHub Desktop.
Duplicates the content from a source to a target, both being the same type
This file contains 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
/** | |
* | |
* Duplica el contenido de un objeto sobre otro del mismo tipo. | |
* | |
* @param source Objeto a partir de cual obtener los valores | |
* @param destiny Objeto al cual asignar dichos valores | |
*/ | |
mapAll<T>(source: T, destiny: T) { | |
const keys: any[] = Object.keys(source); | |
keys.forEach((key) => { | |
if (source[key] instanceof Object && !(source[key] instanceof Date)) { | |
this.mapAll<T>(source[key], destiny[key]); | |
} else { | |
destiny[key] = source[key]; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment