https://github.com/hamzahamidi/cookies-utils
This project contains tools to help manage cookies: Delete cookie, check existence, check value
https://github.com/hamzahamidi/cookies-utils
check-cookies cookie cookies delete-cookies javascript set-cookie typescript
Last synced: 10 months ago
JSON representation
This project contains tools to help manage cookies: Delete cookie, check existence, check value
- Host: GitHub
- URL: https://github.com/hamzahamidi/cookies-utils
- Owner: hamzahamidi
- License: mit
- Created: 2020-10-30T21:02:39.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-07T16:36:53.000Z (over 5 years ago)
- Last Synced: 2025-04-07T23:35:49.024Z (about 1 year ago)
- Topics: check-cookies, cookie, cookies, delete-cookies, javascript, set-cookie, typescript
- Language: TypeScript
- Homepage:
- Size: 434 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# cookies-utils
This project contains functions to help manage cookies.
## Installation
### NPM
Install the library with `npm install cookies-utils`.
### CDN
Or use it directly in your browser via jsDelivr or unpkg:
```html
...
cookiesUtils.deleteCookie('name')
```
or
```html
...
cookiesUtils.deleteCookie('name')
```
## Usage
Set a cookie
```javascript
import { setCookie } from "cookies-utils";
// more information about the options in documentation https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
const cookieOptions = {
name: "name", // string,
value: "value", // string,
maxAge: 10 * 60, // optional number (value in seconds),
expires: new Date(2099, 10, 1), // optional Date,
path: "/path", // optional string,
domain: "site.com", // optional string,
secure: true, // optional boolean,
sameSite: "lax", // optional enum 'lax' | 'strict' | 'none'
};
setCookie(cookieOptions);
```
Check existence of cookie
```javascript
import { cookieExists } from "cookies-utils";
const isExist = cookieExists("name");
```
Delete a cookie
```javascript
import { deleteCookie } from "cookies-utils";
deleteCookie("name");
```
Check if cookie has specific value
```javascript
import { cookieHasValue } from "cookies-utils";
const hasValue = cookieHasValue("name", "value");
```
Delete all cookies
```javascript
import { deleteAllCookies } from "cookies-utils";
deleteAllCookies();
```