Can you guide me on how to verify and create a URL under different circumstances?
I am dealing with 3 cases that involve different types of objects:
"repositories": {
"toto": {
"tata": "https://google.com/",
"titi": "images"
}
},
The second case is as follows:
"repositories": {
"toto": {
"tata": "https://google.com/",
"titi": "" // empty string
}
},
And the third case like this:
"repositories": {
"toto": {
"tata": "https://google.com/",
// no "titi" key
}
},
I need assistance in generating a URL while considering these 3 distinct scenarios.
I'm unsure how to handle the 2nd and 3rd cases within the same script.
In my current script, I have:
else if (type === "toto") {
const totoURi = repositories.toto.tata;
const titi = repositories.toto.titi;
// Struggling to incorporate the logic for the 2nd and 3rd cases
const url =
totoURi +
titi +
"." +
type;
// Example for first case: https://google.com/images.toto
// Expected for 2nd case: https://google.com.toto
// Expected for 3rd case: https://google.com.toto
}
Thank you for any guidance or help provided.