cookie-checker-js
v1.0.1
Published
A lightweight utility to parse and retrieve cookie values in **JavaScript (browser)** environments. Useful for checking if specific cookies exist and extracting their values from `document.cookie`.
Readme
cookie-checker-js
A lightweight utility to parse and retrieve cookie values in JavaScript (browser) environments. Useful for checking if specific cookies exist and extracting their values from document.cookie.
📦 Installation
npm install cookie-checker-jsUsage
Get a Cookie Value
import { getCookieValue } from "cookie-checker-js";
const token = getCookieValue("authToken");
console.log(token); // "abc123" or nullCheck if Cookie Key Exists
import { hasCookieKey } from "cookie-checker-js";
if (hasCookieKey("sessionId")) {
console.log("Session exists");
} else {
console.log("Session not found");
}API Reference
getCookieValue(key: string): string | null
- Retrieves the value of a cookie by name.
- Returns
nullif the cookie is not present.
hasCookieKey(key: string): boolean
- Checks if a cookie key exists.
- Returns
trueif present,falseotherwise.
How It Works
The utility parses document.cookie and maps it into key-value pairs:
document.cookie => "authToken=abc123; sessionId=xyz789"It then decodes the keys and values safely and provides a clean interface for retrieval.
Environment Support
- ✅ Browser (frontend JavaScript/TypeScript only)
- ❌ Not for Node.js (see
cookie-checker-nodefor Node.js environments)
📄 License
MIT License
✍️ Author
Developed by Utkarsh. Designed for simplicity and usability in real-world frontend projects.
