UNPKG

@helpscout/hsds-react

Version:

React component library for Help Scout's Design System

69 lines (52 loc) 1.51 kB
"use strict"; exports.__esModule = true; exports.nameToInitials = exports.getAnimationProps = exports.getImageSrc = void 0; var _easing = require("../../utilities/easing"); var getImageSrc = function getImageSrc(props) { var fallbackImage = props.fallbackImage, image = props.image; var src = [image]; if (fallbackImage) { src.push(fallbackImage); } return src.filter(function (i) { return !!i; }); }; exports.getImageSrc = getImageSrc; var getAnimationProps = function getAnimationProps(props) { var animationDuration = props.animationDuration, animationEasing = props.animationEasing, animation = props.animation; if (!animation) { return {}; } return { animationDuration: animationDuration, animationEasing: (0, _easing.getEasingTiming)(animationEasing), animation: animation }; }; exports.getAnimationProps = getAnimationProps; var nameToInitials = function nameToInitials(name) { if (name === void 0) { name = ''; } // Returning early if undefined to avoid casting undefined to "undefined" if (!name) { return ''; } // Trim trailing whitespace name = (name + '').trim(); if (!name.length) { return ''; } var words = name.split(' ').filter(function (w) { return w !== ''; }).map(function (w) { return w[0]; }).map(function (w) { return w.toUpperCase(); }); return words.length === 1 ? words[0] : words[0] + words[words.length - 1]; }; exports.nameToInitials = nameToInitials;