Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wherecani/svelte-cookie
A tool that will make setting, getting and deleting cookie's easier in your Svelte project.
https://github.com/wherecani/svelte-cookie
cookie svelte sveltejs
Last synced: 20 days ago
JSON representation
A tool that will make setting, getting and deleting cookie's easier in your Svelte project.
- Host: GitHub
- URL: https://github.com/wherecani/svelte-cookie
- Owner: WhereCanI
- License: mit
- Created: 2021-12-09T09:12:29.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-16T14:32:05.000Z (almost 3 years ago)
- Last Synced: 2024-04-26T04:04:58.087Z (7 months ago)
- Topics: cookie, svelte, sveltejs
- Language: Svelte
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Svelte-Cookie
A tool that will make setting, getting and deleting cookie's easier in your Svelte project.
Report Bug
.
Request Feature
[![npm version](https://badge.fury.io/js/svelte-cookie.svg)](https://badge.fury.io/js/svelte-cookie) ![Contributors](https://img.shields.io/github/contributors/WhereCanI/Svelte-Cookie?color=dark-green) ![Issues](https://img.shields.io/github/issues/WhereCanI/Svelte-Cookie) ![License](https://img.shields.io/github/license/WhereCanI/Svelte-Cookie)
## Table Of Contents
* [About the Project](#about-the-project)
* [Getting Started](#getting-started)
* [Installation](#installation)
* [Usage](#usage)
* [License](#license)
* [Authors](#authors)
* [Acknowledgements](#acknowledgements)## About The Project
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:
* With the getCookie function, you can quickly get a cookie from the browser.
* With the setCookie function, you can easily create a new cookie that will be set in the web browser.
* With the deleteCookie function, you can quickly erase an existing cookie from the web browser.## Getting Started
It's very easy to get started with Svelte-Cookie. Follow the instructions below, and you will be working with cookies in no time.
### Installation
To install, please write the following in your terminal:
```sh
npm install --save svelte-cookie
```## Usage
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:
* getCookie
* setCookie
* deleteCookieYou can import them by using the following line:
```sh
import { getCookie, setCookie, deleteCookie } from 'svelte-cookie';
```## Examples
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:* Name - The first parameter is the name of the cookie.
* Value - The second parameter is the string value you want to cookie to have.
* Expiration days - Provide a number of how many days your cookie should stay in the web browser.
* Secure - Write either true or false depending on whether you want your cookie to have the secure attribute.```
setCookie('userEmail', '[email protected]', 30, true);
```The above code will create a cookie named "userEmail", with the value "[email protected]". 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');
```## License
Distributed under the MIT License. See [LICENSE](https://github.com/WhereCanI/Svelte-Cookie/blob/main/LICENSE.md) for more information.
## Authors
* **Michael Andersen** - *Frontend web developer* - [Michael Andersen](https://github.com/WhereCanI/) - *Built Svelte-Cookie*
[SustainableWWW](https://sustainablewww.org) - Learn about environmentally friendly and ethical web design.