# flexible-cookies

> Flexible tool to manage cookies in javascript

Latest version **1.0.2** (published 2018-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install flexible-cookies
pnpm add flexible-cookies
yarn add flexible-cookies
bun add flexible-cookies
```

## 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.2 |
| Published | 2018-03-15 |
| First published | 2018-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hello@pierrecabriere.fr |
| Maintainers | pierrecabriere |
| Keywords | javascript, cookies, universal, flexible, server-rendering |

## Links

- npm: https://www.npmjs.com/package/flexible-cookies
- Repository: https://github.com/pierrecabriere/flexible-cookies
- Homepage: https://github.com/pierrecabriere/flexible-cookies#readme
- Issues: https://github.com/pierrecabriere/flexible-cookies/issues
- npm.io page: https://npm.io/package/flexible-cookies

## Recent versions

- 1.0.2 (latest) — 2018-03-15
- 1.0.1 — 2018-03-03
- 1.0.0 — 2018-03-03

## README

# Flexible Cookies 🍪

[![NPM version](https://img.shields.io/npm/v/flexible-cookies.svg)](https://www.npmjs.com/package/flexible-cookies)
[![Build Status](https://travis-ci.org/pierrecabriere/flexible-cookies.svg?branch=master)](https://travis-ci.org/pierrecabriere/flexible-cookies)

**flexible-cookies is a flexible way to manage cookies in javascript/node.js.**

---

# Installation
```
npm install --save flexible-cookies
```

# Basic Usage

```js
import { Cookies } from 'flexible-cookies';
// or default import
import Cookies from 'flexible-cookies/cookies'
```

## Set cookie

```js
Cookies.set('COOKIE-NAME', 'COOKIE-VALUE', options);
```

## Get cookie

```js
const cookieValue = Cookies.get('COOKIE-NAME', options);
```

## Delete cookie

```js
Cookies.delete('COOKIE-NAME', options);
```

# Configuration

You can specify a source where **flexible-cookies** will read/edit the cookie.<br/>
By default, the source is `document` (which is the browser working-behavior) but you can change it to make cookies working in a server context:
```js
Cookies.set('CONTEXT-COOKIE', 'Hello !', {
  source: ctx.req.headers
});
const cookieValue = Cookies.get('CONTEXT-COOKIE', {
  source: ctx.req.headers
});
console.log(cookieValue) // Hello !
```

## Cookie validity duration

By default, the cookie is valid until the browser session is closed, but you can increase the validity duration of the cookie:
```js
Cookies.set('ONE-YEAR-VALID-COOKIE', 'COOKIE-VALUE', {
  days: 365
});
```

## Cookie path

```js
Cookies.set('SPECIFIC-PATH-COOKIE', 'COOKIE-VALUE', {
  path: '/'
});
```

# 🚀

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