Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Created April 18, 2020 23:26
Show Gist options
  • Save Qarun-Qadir-Bissoondial/709a78c8aa02168605f1398f4bc8280c to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/709a78c8aa02168605f1398f4bc8280c to your computer and use it in GitHub Desktop.
capitalizeName - Version 2
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