/** * @prettier * @flow */ import React from 'react'; import type { Element } from 'react'; import { spacing } from '../../utils/styles/mixings'; import Tag from '../Tag'; import { formatDate, formatDateDistance } from '../../utils/package'; import { IProps } from './types'; import { WrapperLink, Header, MainInfo, Name, Version, Overview, Published, OverviewItem, Description, Icon, Text, Details, Avatar, Author, Field, Content, Footer, } from './styles'; const getInitialsName = (name: string) => name .split(' ') .reduce((accumulator, currentValue) => accumulator.charAt(0) + currentValue.charAt(0), '') .toUpperCase(); const Package = ({ name: label, version, time, author: { name, avatar }, description, license, keywords = [] }: IProps): Element => { const renderMainInfo = () => ( {label} {`v${version}`} ); const renderAuthorInfo = () => ( {!avatar && getInitialsName(name)}
); const renderLicenseInfo = () => license && ( {license} ); const renderPublishedInfo = () => ( {`Published on ${formatDate(time)} •`} {`${formatDateDistance(time)} ago`} ); const renderDescription = () => description && ( {description} ); return (
{renderMainInfo()} {renderLicenseInfo()} {renderPublishedInfo()}
{renderAuthorInfo()} {renderDescription()} {keywords.length > 0 && ( )}
); }; export default Package;