Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cookie-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-interceptor

A simple JavaScript utility library for intercepting browser cookies

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
476
increased by13.06%
Maintainers
1
Weekly downloads
 
Created
Source

npm version

A simple JavaScript utility library for intercepting browser cookies

Live demo available at here.

Installation

$ npm install cookie-interceptor

The CDN build is also available on unpkg:

Usage

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.

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

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
IE9, IE10, IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

License

MIT

References

Keywords

FAQs

Package last updated on 05 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc