Links

Cookies

Create, update, delete and read cookies.

cookieCreate

Creates a cookie. Requires name {string}, value {string}, and days {number}. Also used for updating and deleting cookies.
import {cookieCreate} from '@elkfox/shopify-theme/scripts/cookies';
​
const someCookie = cookieCreate('some_cookie', 'test_value', 30);
​
someCookie();

Update cookies

Cookies are updated the same way they are created.
const updatedCookie = cookieCreate('some_cookie', 'some_new_value', 5);
​
updatedCookie();

Deleting cookies

Assign the days variable as a negative number.

cookieRead

Retreive values from a cookie.
import {cookieRead} from '@elkfox/shopify-theme/scripts/cookies';
​
cookieRead('some_cookie');

cookieTest

Test for cookie support, replacing a class from your document HTML object, when found, with a new class.
The first variable is the default class {string}, that should be added to your HTML (theme.liquid). Defaults to `no-cookies`
theme.liquid
<html class="no-cookies">
The second variable is the class {string} that will replace the initial value. Defaults to `cookies`
import {cookieTest} from '@elkfox/shopify-theme/scripts/cookies';
​
cookieTest('no-cookies', 'cookies');
When cookies are supported by the user's browser, the class applied to the HTML object will changed:
<html class="cookies">