UNPKG

@ampush/centaurus

Version:

Centaurus, is an Ampush repository designed to house common UI components, JS classes, templates and API methods in a central place that can be imported and reused across other Ampush partner repositories as needed.

20 lines (17 loc) 740 B
const { hostname } = window.location; const [subDomain, domainName, top] = hostname.split('.'); const host = hostname; const isLocalhost = hostname.indexOf('localhost') !== -1 || hostname.indexOf('0.0.0.0') !== -1; const parsedDomain = isLocalhost ? host : domainName ? `${domainName}.${top || 'com'}` : ''; const setCookie = (cookieStr, doExpires) => { if (doExpires) { const date = new Date(); date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000); const expires = `expires=${date.toUTCString()}`; document.cookie = `${cookieStr};${expires};domain=${parsedDomain};path=/`; } else { document.cookie = `${cookieStr};domain=${parsedDomain};path=/`; } }; export default setCookie;