Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 3 months ago
JSON representation

This project contains tools to help manage cookies: Delete cookie, check existence, check value

Awesome Lists containing this project

README

        

# cookies-utils



NPM Version





Build Status

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();
```