Installations
npm install @aftabmk/cookie
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
18.6.0
NPM Version
8.13.2
Releases
Unable to fetch releases
Download Statistics
Total Downloads
609
Last Day
2
Last Week
4
Last Month
16
Last Year
135
Bundle Size
495.00 B
Minified
281.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.2
Package Id
@aftabmk/cookie@1.0.2
Unpacked Size
190.23 kB
Size
186.41 kB
File Count
7
NPM Version
8.13.2
Node Version
18.6.0
Total Downloads
Cumulative downloads
Total Downloads
609
Last day
0%
2
Compared to previous day
Last week
100%
4
Compared to previous week
Last month
100%
16
Compared to previous month
Last year
-45.6%
135
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
Cookie generator
This package is used to create dynamic cookie value and authenticate the created cookie to prevent external tampering.This is simple and plain way to create advanced binaary based cookie with no effort.It primarly targeted for beginner coders.
Installing
Using npm:
1$ npm i @aftabmk/cookie
Using bower:
1$ bower install @aftabmk/cookie
Using yarn:
1$ yarn add @aftabmk/cookie
Using pnpm:
1$ pnpm add @aftabmk/cookie
Documentation
Functions
setCookie
1const cookie : setCookie(String,String,Number,Number)
filterCookie
1const bool : filterCookie(String,Number,String)
Example
setCookie inputs
Name
1const cookie = setCookie('kizhissery','-',7,5) 2/*{ 3 cookie:'kizhissery-101010000......... 4 here input is Kizhissery 5}*/
Symbol
1const cookie = setCookie('kizhissery','=',7,20) 2/*{ 3 cookie:'kizhissery-101010000......... 4 here input is Kizhissery 5}*/
Key
1const cookie = setCookie('aftab','-',7,20) 2/*{ 3 cookie:'kizhissery-101010000......... 4 here secret key is 7, it can be any +ve integer Only, decimal and -ve integer will not function 5}*/
Repeat
1const cookie = setCookie('aftab','-',7,5) 2/*{ 3 cookie:'kizhissery-101010000......... 4 here length of cookie detemined length here it is 5 5 cookie:'kizhissery-101010000.........*4 6 here length of cookie detemined length here it is 20, if you need bigger cookie value , should be more than 5 and less than 20 for optimal result 7}*/
result
1const cookie = setCookie(name,symbol,key,length) 2/*{ 3 cookie:'kizhissery-101010000......... 4 here length of cookie detemined length here it is 5 5 cookie:'kizhissery-101010000.........*4 6 here length of cookie detemined length here it is 20, if you need bigger cookie value , should be more than 5 and less than 20 for optimal result 7}*/
filterCookie inputs
result
1const filter = filterCookie(name,key,cookie) 2/*{ 3 cookie is the the derived value of the above function "setCookie" which is passed to filter function. 4 Note the name and key of setCookie must match the inputs of filterCookie. 5}*/
Starter Code
example 1
1const { setCookie , filterCookie } = require('@aftabmk/cookie') 2 3const cookie = setCookie('aftab','=',30,5) 4const filter = filterCookie('aftab',30,cookie) 5 6console.log({cookie},{filter})
example 2
1// imports 2const express = require("express"); 3const cookieParser = require('cookie-parser') 4const { setCookie , filterCookie } = require('@aftabmk/cookie'); 5//setting up express 6app.use(ex.json()) 7app.use(ex.urlencoded({ extended: true })) 8//auth 9function Auth(req, res, next) 10{ 11 if(!req.headers.cookie) return res.status(403).send('403 access forbidden') 12 if(filterCookie('user',77,req.headers.cookie)) 13 // name was set to user and key to 77 at setCookie function 14 // filterCookie return true 15 // so it will lead to next() , if authentication fails it will send 403 to unauthorised api/json scrapper 16 // for true return /api route and access the data from those route 17 { 18 next();return 19 } 20 else 21 { 22 res.status(401).send([{'status':401,'description':'Invalid certificate'}]); 23 } 24} 25// the user in front end redirect to setCookie end point to initialise setCookie function to set cookie inside cookie-parser option 26app.get(`/setCookie`, async (req, res) => 27{ try 28 { 29 return res.status(202) 30 .cookieParser( setCookie('user','=',77,20) , cookieOptions) 31 // here name is user , symbol is '=' , secret key = 77 and length = 20 32 // cookieOption { sameSite: 'strict', path: '/', expires: new Date(Date.now() + 900000), httpOnly: true } 33 // IMPORTANT htmlonly to true 34 .send('User cookie is set') 35 } 36 catch (err) 37 { 38 return res.status(500).json({ err: err.toString() }) 39 } }) 40 41// Express router import whereapi are stored hence we introduce Auth middleware , to prevent unwanted scrapers 42app.use('/api',Auth,api) 43 44 45app.listen(port, () => { console.log(`running on port http://localhost:5000`) })
No vulnerabilities found.
No security vulnerabilities found.