Sweet Cookies is a lightweight JavaScript library for handling cookies in the browser. It provides a simple and efficient way to set, get, and remove cookies, making it convenient for storing small pieces of information on the client-side.
- Simplicity: Easy-to-use API for managing cookies.
- Lightweight: A small library with no external dependencies.
- Cross-browser Support: Works in modern browsers.
- Expiration and Options: Set cookies with expiration date and additional options.
Include the script directly in your HTML:
<script src="path/to/sweet-cookies.js"></script>
Instead of downloading it you can use this script
<script src="https://dalia-alawneh.github.io/sweet-cookies/dist/index.js"></script>
To use Sweet Cookies, include it in your project and access its methods via the SweetCookie
object.
// Set a cookie that expires in 1 day
SweetCookie.set('name', 'dalia', '1d');
const name = SweetCookie.get('name');
console.log(name);
SweetCookie.remove('name');
Set a cookie with the given name
and value
. The expiresIn
parameter accepts a string with time format in 's' (seconds), 'm' (minutes), 'h' (hours), or 'd' (days).
Example usage: SweetCookie.set('name', 'dalia', '1d');;
Retrieve the value of the cookie with the specified name
. If the cookie does not exist, it returns null
.
Example usage: const name = SweetCookie.get('name');
Remove the cookie with the given name
.
Example usage: SweetCookie.remove('name');
This project is licensed under the MIT License.