Skip to content

Instantly share code, notes, and snippets.

@Chester97
Created January 16, 2021 17:51
Show Gist options
  • Save Chester97/1964393487ebe43e21e30108ebc99cb0 to your computer and use it in GitHub Desktop.
Save Chester97/1964393487ebe43e21e30108ebc99cb0 to your computer and use it in GitHub Desktop.
// Cyberpunk 2077 - plan aktualizacji, Źródło zdjęć: © CD Projekt Red | Jan Kowal // Pełny string, caption, source | author
// Cyberpunk 2077 - plan aktualizacji, Źródło zdjęć: © CD Projekt Red
// Źródło zdjęć: © CD Projekt Red | Jan Kowal
// Cyberpunk 2077 - plan aktualizacji
// source - 'Źródło zdjęć: © SOURCE'
// caption - Jeśli jest source to: 'CAPTION, ' | jeśli nie, to: 'CAPTION'
// author - Jeśli source to 'SOURCE | AUTHOR'
type imageDetailsType = {
source?: string,
caption?: string,
author?: string,
isAmp?: boolean
}
type imgDetailsGeneratorType = (value: imageDetailsType) => String;
const foo: imgDetailsGeneratorType = (value) => {
const { author, caption, isAmp, source } = value;
const captionValue = (caption && isAmp) && `${caption}${!source ? '' : ', '}`;
const sourceValue = source && `Źródło zdjęć: © ${source}${(author && !captionValue) ? ' ' : ''}`;
const authorValue = author && `${captionValue ? ` | ${author}` : author}`;
return [captionValue,sourceValue,authorValue].filter(Boolean).join('').trim();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment