No hidden undefined

This commit is contained in:
Michael Novotny 2023-08-11 10:30:08 -05:00
parent 2c87e1b769
commit f332d0ff85
No known key found for this signature in database
3 changed files with 7 additions and 8 deletions

View File

@ -8,8 +8,8 @@ const { TWITTER_CREATOR, TWITTER_SITE, SITE_NAME } = process.env;
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
: 'http://localhost:3000';
const twitterCreator = ensureStartsWith(TWITTER_CREATOR, '@');
const twitterSite = ensureStartsWith(TWITTER_SITE, 'https://');
const twitterCreator = TWITTER_CREATOR ? ensureStartsWith(TWITTER_CREATOR, '@') : undefined;
const twitterSite = TWITTER_SITE ? ensureStartsWith(TWITTER_SITE, 'https://') : undefined;
export const metadata = {
metadataBase: new URL(baseUrl),

View File

@ -50,7 +50,9 @@ import {
ShopifyUpdateCartOperation
} from './types';
const domain = ensureStartsWith(process.env.SHOPIFY_STORE_DOMAIN, 'https://') || '';
const domain = process.env.SHOPIFY_STORE_DOMAIN
? ensureStartsWith(process.env.SHOPIFY_STORE_DOMAIN, 'https://')
: '';
const endpoint = `${domain}${SHOPIFY_GRAPHQL_API_ENDPOINT}`;
const key = process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN!;

View File

@ -7,8 +7,5 @@ export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyUR
return `${pathname}${queryString}`;
};
export const ensureStartsWith = (stringToCheck?: string, startsWith?: string) => {
if (!stringToCheck || !startsWith) return stringToCheck;
return stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;
};
export const ensureStartsWith = (stringToCheck: string, startsWith: string) =>
stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;