import qs, { ParsedQuery } from 'query-string'; import { IMGIX_SOURCE } from 'meta-data'; const parseQueryString = (search: string): ParsedQuery => { return qs.parse(search); }; const getImgix = (url: string, squareDimensions?: number): string => `${IMGIX_SOURCE}${url}${squareDimensions ? `?fit=crop&w=${squareDimensions}&h=${squareDimensions}` : ``}`; const getCurrentPath = (window: Window): string => window.location.pathname.split('/')[1]; const isActivePath = (window: Window, slug: string) => { const path = getCurrentPath(window); return hasLeadingSlash(slug) ? ( path === slug.substring(1, slug.length) ) : (slug === 'index' ? path === '' : path === slug); }; const hasLeadingSlash = (slug: string) => slug.charAt(0) === '/'; export { parseQueryString, getImgix, isActivePath };