@arunvaradharajalu/common.cookies
v1.0.1
Published
This package contains Cookie Implementation class to set and parse cookies.
Maintainers
Readme
@arunvaradharajalu/common.cookies
Overview
This package provides a Cookie Implementation class to handle setting, retrieving, and clearing cookies, including signed cookies, in an Express application.
Installation
To install the package, run the following command:
npm install @arunvaradharajalu/common.cookiesUsage
Importing the Cookie Implementation
import { CookieImpl } from '@arunvaradharajalu/common.cookies';Setting a Cookie
const cookieImpl = new CookieImpl();
cookieImpl.setCookies(response, { name: Cookies.appnameCookieName, value: 'cookie_value' });Setting a Signed Cookie
cookieImpl.setSignedCookies(response, { name: SignedCookies.lifeverseChristmasEventAuthToken, value: 'signed_cookie_value' });Retrieving Cookies
const cookies = cookieImpl.getCookies(request);
console.log(cookies.appnameCookieName);Retrieving Signed Cookies
const signedCookies = cookieImpl.getSignedCookies(request);
console.log(signedCookies.lifeverseChristmasEventAuthToken);Clearing a Cookie
cookieImpl.clear(response, Cookies.appnameCookieName);Types
The package includes types for cookies and signed cookies:
Cookies: Enum for standard cookies.SignedCookies: Enum for signed cookies.CookieInput: Interface for passing cookie name and value.SignedCookieInput: Interface for passing signed cookie name and value.
Tests
Tests can be run using:
npm run testTest results will be available in an HTML format using the jest-html-reporter.
License
This project is licensed under the ISC License.
Issues
For any issues or bug reports, please visit the GitHub Issues Page.
Author
Arun Varadharajalu
