# @mercierkevin35/cookiemanager

> A simple cookie manager written in JS

Latest version **1.0.4** (published 2021-05-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @mercierkevin35/cookiemanager
pnpm add @mercierkevin35/cookiemanager
yarn add @mercierkevin35/cookiemanager
bun add @mercierkevin35/cookiemanager
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-05-15 |
| First published | 2021-05-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kévin Mercier |
| Maintainers | mercierkevin35 |
| Keywords | cookie, cookies |

## Links

- npm: https://www.npmjs.com/package/@mercierkevin35/cookiemanager
- Repository: https://github.com/mercierkevin35/CookieManager
- Homepage: https://github.com/mercierkevin35/CookieManager#readme
- Issues: https://github.com/mercierkevin35/CookieManager/issues
- npm.io page: https://npm.io/package/@mercierkevin35/cookiemanager

## Recent versions

- 1.0.4 (latest) — 2021-05-15
- 1.0.3 — 2021-05-14
- 1.0.2 — 2021-05-14
- 1.0.1 — 2021-05-14
- 1.0.0 — 2021-05-14

## README

# CookieManager
A simple JS class to manage cookies\
CookieManager provides a way to simply manage cookies.

## Installation
Using npm, run the following command :
```
npm i @mercierkevin35/cookiemanager
```
Then use it in your file
```javascript
import CookieManager from '@mercierkevin35/cookiemanager';
```

## Create a cookie
To create a cookie whose name is "myCookie" and value is "my cookie value",\
proceed as follows :

```javascript
//Create
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value";
manager.setCookie(key, value);
```
If not specified, the cookie expires at the end of the session.
To explicitly specify the expiration delay, proceed like so :

```javascript
//Create
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value",
    expireDays = 7;
manager.setCookie(key, value, expireDays); // this cookie expires in 7 days
```

## Get a cookie value
The getCookies method returns a JS object containing each cookie as attributes\
You can get a specific value like this :

```javascript
//Create
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value",
    expireDays = 7;
manager.setCookie(key, value, expireDays); // this cookie expires in 7 days

//Read
let myValue = manager.getCookies().myCookie // myValue == "my cookie value"
```
You can also specify a key dynamically into brackets like this :

```javascript
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value",
    expireDays = 7;
manager.setCookie(key, value, expireDays); // this cookie expires in 7 days

//Read
let myValue = manager.getCookies().myCookie; // myValue == "my cookie value"

let dynamicKey = "myCookie";
let theValue = manager.getCookies()[dynamicKey]; // theValue == "my cookie value"
```

## Update a cookie value
To update a cookie value, just set a cookie with the same key

```javascript
//Create
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value",
    expireDays = 7;
manager.setCookie(key, value, expireDays); // this cookie expires in 7 days

//Read
let myValue = manager.getCookies().myCookie; // myValue == "my cookie value"
let dynamicKey = "myCookie";

let theValue = manager.getCookies()[dynamicKey]; // theValue == "my cookie value"

//Update
manager.setCookie("myCookie", "my new cookie value");
```

## Delete a cookie
To delete a cookie, use the deleteCookie method with the key as argument

```javascript
//Create
const manager = new CookieManager(),
    key = "myCookie",
    value = "my cookie value",
    expireDays = 7;
manager.setCookie(key, value, expireDays); // this cookie expires in 7 days

//Read
let myValue = manager.getCookies().myCookie; // myValue == "my cookie value"
let dynamicKey = "myCookie";

let theValue = manager.getCookies()[dynamicKey]; // theValue == "my cookie value"

//Update
manager.setCookie("myCookie", "my new cookie value");

//Delete
manager.deleteCookie("myCookie");
//myCookie no more exists
```

---
_Source: https://npm.io/package/@mercierkevin35/cookiemanager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
