Created
April 18, 2020 23:26
-
-
Save Qarun-Qadir-Bissoondial/709a78c8aa02168605f1398f4bc8280c to your computer and use it in GitHub Desktop.
capitalizeName - Version 2
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
export const capitalizeName = (obj: object): object => { | |
if (!obj) { | |
throw new Error('object is null or undefined'); | |
} | |
if (!('name' in obj)) { | |
return Object.assign(obj, {name: ''}); | |
} | |
if (typeof obj['name'] !== 'string') { | |
throw new Error("'name' key in object must be a string."); | |
} | |
const newObject = Object.assign({}, obj, { name: obj['name'].toUpperCase() }); | |
return newObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment