import { kebabCase , startCase , toLower } from 'lodash' ; import { PASTE_PACKAGE_PREFIX , SidebarCategoryRoutes } from '../constants' ; const hasWindowObject = ( ) : boolean => typeof window !== `undefined` && window . location != null ; export function getCurrentPathname ( ) { if ( ! hasWindowObject ( ) ) { return '' ; } return window . location . pathname ; } export function getCurrentPathHash ( ) { if ( ! hasWindowObject ( ) ) { return '' ; } return window . location . hash ; } export function getCurrentOrigin ( ) { if ( ! hasWindowObject ( ) ) { return 'https://paste.twilio.design' ; } return window . location . origin ; } export function getNameFromPackageName ( packageName ) { return packageName . replace ( PASTE_PACKAGE_PREFIX , '' ) ; } export function getHumanizedNameFromPackageName ( packageName ) { return startCase ( toLower ( packageName . replace ( PASTE_PACKAGE_PREFIX , '' ) ) ) ; } export function getPackagePath ( categoryRoute , packageName ) { return `${ categoryRoute }/${ packageName . replace ( /\s+/g , '-' ) . toLowerCase ( ) }` ; } export function slugify ( text ) { return kebabCase ( text . toLowerCase ( ) . replace ( /[&+]/g , '-and-' ) ) ; } export function getOpengraphServiceUrl ( path ) { return `${ getCurrentOrigin ( ) }/.netlify/functions/opengraph/${ path }` ; } export const getCategoryNameFromRoute = ( categoryRoute ) : string => { switch ( categoryRoute ) { case SidebarCategoryRoutes . COMPONENTS : return 'Components' ; case SidebarCategoryRoutes . PRIMITIVES : return 'Primitives' ; case SidebarCategoryRoutes . LAYOUT : return 'Layout' ; case SidebarCategoryRoutes . TOKENS : return 'Tokens' ; case SidebarCategoryRoutes . LIBRARIES : return 'Libraries' ; case SidebarCategoryRoutes . CUSTOMIZATION : return 'Customization' ; case SidebarCategoryRoutes . CORE : return 'Core' ; case SidebarCategoryRoutes . PATTERNS : return 'Patterns' ; default : return 'Layout' ; } } ;