I need to transpile a key is some situation. Right now i'm using this:
transpileKey = key => {
if (key === 'smsCode') key = 'code';
if (key === 'phoneMobile') key = 'phoneNumber';
if (key === 'passport') key = 'ssn';
if (key === 'comment') key = 'notes';
return key;
};
And the function who calls it:
validate = (key) => {
key = transpileKey(key)
console.log(key)
}
validate('smsCode')
I wrote this switch to make it nicer, but it's not returning the proper value (I get the last one, 'notes' in the log).
transpileKey = key => {
switch (key) {
case 'smsCode':
key = 'code';
case 'phoneMobile':
key = 'phoneNumber';
case 'passport':
key = 'ssn';
case 'comment':
key = 'notes';
}
return key;
};
What is wrong?