A tool that will make setting, getting and deleting cookie's easier in your Svelte project.
Report Bug
.
Request Feature
Cookies are very often used in today's websites and web applications, but handling cookies in plain Javascript can be complicated. With Svelte-Cookie the complicated and complex cookie handling is over.
Here's why:
It's very easy to get started with Svelte-Cookie. Follow the instructions below, and you will be working with cookies in no time.
To install, please write the following in your terminal:
npm install --save svelte-cookie
To use svelte-cookie, please start by importing the desired functions to your project. As of this moment, svelte-cookie contains 3 functions which are:
You can import them by using the following line:
import { getCookie, setCookie, deleteCookie } from 'svelte-cookie';
Underneath here you will find some examples of ways to use the individual functions:
getCookie: The getCookie function is as the name says, getting a cookie. You do that by providing the name of the cookie. If the cookie exists the value length will be longer than 0.
let co = getCookie('userEmail');
If the userEmail cookie exist, you will get back the value. If it doesn't exist you will get back an empty string.
setCookie: The setCookie allows you to add a cookie to the web browser in only a few steps. The setCookie has some options which you have to provide:
setCookie('userEmail', '[email protected]', 30, true);
The above code will create a cookie named "userEmail", with the value "example-name@example.com". It will expire in 30 days and it will be set as secure.
deleteCookie: The deleteCookie function is very simple, and it will allow you to quickly erase a cookie from the web browser. You simply provide the name of the cookie as shown in the example below:
deleteCookie('userEmail');
Distributed under the MIT License. See LICENSE for more information.
SustainableWWW - Learn about environmentally friendly and ethical web design.