# cookie-interceptor

> A simple JavaScript utility library for intercepting browser cookies

Latest version **1.0.0** (published 2020-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install cookie-interceptor
pnpm add cookie-interceptor
yarn add cookie-interceptor
bun add cookie-interceptor
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-02-05 |
| First published | 2018-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Qingrong Ke |
| Maintainers | dearke |
| Keywords | cookie, interceptor |

## Links

- npm: https://www.npmjs.com/package/cookie-interceptor
- Repository: https://github.com/keqingrong/cookie-interceptor
- Homepage: https://github.com/keqingrong/cookie-interceptor#readme
- Issues: https://github.com/keqingrong/cookie-interceptor/issues
- npm.io page: https://npm.io/package/cookie-interceptor

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-02-05
- 0.1.7 — 2018-11-05
- 0.1.6 — 2018-11-04
- 0.1.5 — 2018-10-29
- 0.1.4 — 2018-10-25
- 0.1.3 — 2018-10-25
- 0.1.2 — 2018-10-14
- 0.1.1 — 2018-10-14
- 0.1.0 — 2018-10-14
- 0.0.2 — 2018-09-15
- 0.0.1 — 2018-09-12

## README

# cookie-interceptor

[![npm version](https://img.shields.io/npm/v/cookie-interceptor.svg)](https://www.npmjs.com/package/cookie-interceptor)

> A simple JavaScript utility library for intercepting browser cookies

Live demo available at
[here](https://keqingrong.github.io/cookie-interceptor/example/).

## Installation

```sh
$ npm install cookie-interceptor
```

The CDN build is also available on unpkg:

- [unpkg.com/cookie-interceptor/dist/cookie-interceptor.umd.js](https://unpkg.com/cookie-interceptor/dist/cookie-interceptor.umd.js)
- [unpkg.com/cookie-interceptor/dist/cookie-interceptor.umd.min.js](https://unpkg.com/cookie-interceptor/dist/cookie-interceptor.umd.min.js)

## Usage

```js
import CookieInterceptor from 'cookie-interceptor';

CookieInterceptor.init(); // Hijack the `document.cookie` object

CookieInterceptor.read.use(function (cookie) {
  console.log('logger: ', cookie);
  return cookie;
});

CookieInterceptor.disableRead().disableWrite();

document.cookie = 'date=20180915';
console.log(document.cookie); // => ''

CookieInterceptor.enableRead().enableWrite();

document.cookie = 'name=john';
console.log(document.cookie); // => 'name=john'
```

## API

### Interceptors

You can intercept `document.cookie` before it is read or written.

```js
CookieInterceptor.read.use(function (cookie) {
  console.log(cookie);
  return cookie;
});

CookieInterceptor.write.use(function (val) {
  console.log(val);
  return val;
});
```

### Access Control

- `read.enabled` / `readEnabled`: Check if the cookie is readable.
- `read.enable()` / `enableRead()`: Enable `READ` flag. You can read all cookies
  with `document.cookie` property.
- `read.disable()` / `disableRead()`: Disable `READ` flag. `document.cookie`
  will return an empty string.
- `write.enabled` / `writeEnabled`: Check if the cookie is writable.
- `write.enable()` / `enableWrite()`: Enable `WRITE` flag. You can write a new
  cookie or update an existing cookie.
- `write.disable()` / `disableWrite()`: Disable `WRITE` flag. 
  `document.cookie="key=value"` will not write a new cookie or update an 
  existing cookie.

## Browsers support

| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Opera |
| --------- | --------- | --------- | --------- | --------- |
| IE9, IE10, IE11, Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions

## License

MIT

## References

- [Proxying of document.cookie - Stack Overflow](https://stackoverflow.com/questions/32410331/proxying-of-document-cookie)

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