# client-cookies

> A modest package to easily set, get and delete cookies in Javacript.

Latest version **0.8.1** (published 2015-12-01) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.1 |
| Published | 2015-12-01 |
| First published | 2015-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Johnny Magrippis |
| Maintainers | jmagrippis |
| Keywords | client, browser, cookies, document, cookie |

## Links

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

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.8.1 (latest) — 2015-12-01
- 0.8.0 — 2015-11-27
- 0.7.0 — 2015-11-26
- 0.6.2 — 2015-11-26
- 0.6.1 — 2015-11-26
- 0.6.0 — 2015-11-26
- 0.5.0 — 2015-11-25
- 0.4.1 — 2015-11-25
- 0.2.0 — 2015-11-23
- 0.1.0 — 2015-11-23

## README

##Client Cookies

A modest package to easily set, get and delete cookies in Javacript.

Written on EcmaScript 2015, compiled to regular ES5.


### Usage
```javascript
import Cookies from 'client-cookies';

Cookies.set('language', 'javascript');
// Sets the 'language' cookie, expires at end of session

Cookies.get('language'); // Returns 'javascript'

Cookies.delete('language'); // Removes 'language' cookie

Cookies.get('language'); // Returns an empty string ''
```

#### Set Options
You may pass an Object as the third parameter of the set method.

The available tweakable options are:

| Name       | Type                       | Default | Description
|------------|----------------------------|---------|--------
| `expires`  | `Number`, `Date`, `String` | `''`    | When the property is not passed along, the set cookie will expire at the end of the session. When it is passed along, then the value's type will be evaluated. If it's a number, the cookie will expire that number of days later. If it's a Date instance, the cookie's expiry will be set for that date. Lastly, if it's a string, the code will try to parse a Date instance from it, and set the expiry for then; if it's not parsable, it will be the same as if the expires property had not be set at all, so the cookie will expire at the end of the session.
| `secure`   | `Boolean`                  | `false` | Setting this to true, or any "truthy" value, will only allow the cookie to be trasmitted over HTTPS.
| `HttpOnly` | `Boolean`                  | `false` | Setting this to true, or any "truthy" value, will only allow the cookie to be read by the server; **but only if the client adheres to standards**!

### Examples

```javascript
Cookies.set('set expiry', 'two days later', {expires: 2});
// Will expire two days later

Cookies.set('sensitive-info', '42', {secure: true, expires: 9});
// Will only be transmitted via HTTPS, and expire after 9 days.

Cookies.set('XSS protection', 'slight', {HttpOnly: 1, secure: 1});
// Will only be transmitted via HTTPS and read by the server,
// *if* the client adheres to standards.
```

### Testing
Simply run:

```bash
npm test
```

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