npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aftabmk/cookie

v1.0.2

Published

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

Downloads

11

Readme

Installing

Using npm:

$ npm i @aftabmk/cookie

Using bower:

$ bower install @aftabmk/cookie

Using yarn:

$ yarn add @aftabmk/cookie

Using pnpm:

$ pnpm add @aftabmk/cookie

Documentation

Functions

setCookie

const cookie : setCookie(String,String,Number,Number)

filterCookie

const bool : filterCookie(String,Number,String)

Example

setCookie inputs

Name

const cookie = setCookie('kizhissery','-',7,5)
/*{
    cookie:'kizhissery-101010000.........
    here input is Kizhissery
}*/

Symbol

const cookie = setCookie('kizhissery','=',7,20)
/*{
    cookie:'kizhissery-101010000.........
    here input is Kizhissery
}*/

Key

const cookie = setCookie('aftab','-',7,20)
/*{
    cookie:'kizhissery-101010000.........
    here secret key is 7, it can be any +ve integer Only, decimal and -ve integer will not function
}*/

Repeat

const cookie = setCookie('aftab','-',7,5)
/*{
    cookie:'kizhissery-101010000.........
    here length of cookie detemined length here it is 5
    cookie:'kizhissery-101010000.........*4
    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
}*/

result

const cookie = setCookie(name,symbol,key,length)
/*{
    cookie:'kizhissery-101010000.........
    here length of cookie detemined length here it is 5
    cookie:'kizhissery-101010000.........*4
    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
}*/

filterCookie inputs

result

const filter = filterCookie(name,key,cookie)
/*{
    cookie is the the derived value of the above function "setCookie" which is passed to filter function.
    Note the name and key of setCookie must match the inputs of filterCookie.
}*/

Starter Code

example 1

const { setCookie , filterCookie } = require('@aftabmk/cookie')

const cookie = setCookie('aftab','=',30,5)
const filter = filterCookie('aftab',30,cookie)

console.log({cookie},{filter})

example 2

// imports
const express = require("express");
const cookieParser = require('cookie-parser')
const { setCookie , filterCookie } = require('@aftabmk/cookie');
//setting up express
app.use(ex.json())
app.use(ex.urlencoded({ extended: true }))
//auth
function Auth(req, res, next)
{
    if(!req.headers.cookie) return res.status(403).send('403 access forbidden')
    if(filterCookie('user',77,req.headers.cookie))
    // name was set to user and key to 77 at setCookie function
    // filterCookie return true
    // so it will lead to next() , if authentication fails it will send 403 to unauthorised api/json scrapper
    // for true return /api route and access the data from those route
        {
            next();return
        }
        else
        {
            res.status(401).send([{'status':401,'description':'Invalid certificate'}]);
        }
}
// the user in front end redirect to setCookie end point to initialise setCookie function to set cookie inside cookie-parser option
app.get(`/setCookie`, async (req, res) => 
{ try 
    { 
        return res.status(202)
        .cookieParser( setCookie('user','=',77,20) , cookieOptions)
        // here name is user , symbol is '=' , secret key = 77 and length = 20
        // cookieOption { sameSite: 'strict', path: '/', expires: new Date(Date.now() + 900000), httpOnly: true }
        // IMPORTANT htmlonly to true
        .send('User cookie is  set') 
    } 
    catch (err) 
    { 
        return res.status(500).json({ err: err.toString() }) 
    } })

// Express router import whereapi are stored hence we introduce Auth middleware , to prevent unwanted scrapers
app.use('/api',Auth,api)


app.listen(port, () => { console.log(`running on port http://localhost:5000`) })