Skip to content

Instantly share code, notes, and snippets.

@narennaik
Last active June 28, 2021 19:52
Show Gist options
  • Save narennaik/374eb0bece640eb21128d7be42542d52 to your computer and use it in GitHub Desktop.
Save narennaik/374eb0bece640eb21128d7be42542d52 to your computer and use it in GitHub Desktop.
using pipe
const getDomainName = (item) => item.details.name;
const getProtocol = (item) => (item.details.valid ? 'https' : 'http');
const getUrl = (item) => `${getProtocol(item)}://${getDomainName(item)}`;
// TODO: (temporary) Adding callback=true because server side redirection needs this parameter
const addCallbackParameter = (url) => `${url}?callback=true`;
const generateUrl = (item) => {
const url = getUrl(item);
const urlWithCallbackParameter = addCallbackParameter(url);
return urlWithCallbackParameter;
};
// The above function can be simplified or created using pipe utility function from ramda.
const generateUrl = R.pipe(getUrl, addCallbackParameter);
const urlList = domainList.map(generateUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment