0.1.0 • Published 6 months ago

cookie-observer v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

CookieObserver

한국어

Provides an observer-style implementation for document.cookie and cookieStore, along with a polyfill class for cookieStore for unsupported browsers.

Installation

# npm
npm install cookie-observer
# yarn
yarn add cookie-observer
# pnpm
pnpm add cookie-observer

Usage

import { CookieStore, CookieObserver } from 'cookie-observer';

const store =
  typeof cookieStore !== 'undefined' ? cookieStore : new CookieStore(document);

const observer = new CookieObserver((entries) => {
  console.debug(entries);
});
observer.observe(store);

Limitations

Access to cookies at the JavaScript level is limited to the name and value of the cookie. To maintain compatibility and consistency, the fields other than name and value have intentionally been omitted.

TODO

  • Implement the cookieStore interface.
  • Add the observe option (adjust interval, maintain extra fields, etc.).
  • Add a polyfill like installation script.