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

cookiefile

v1.0.10

Published

Package for operating with Netscape HTTP Cookie File

Downloads

247,874

Readme

node-cookiefile

Package for operating with Netscape HTTP Cookie File using Node.JS

It can read and create Netscape HTTP Cookie File like this:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by node-httpcookie! Edit at your own risk

#HttpOnly_horatius.pro	FALSE	/	FALSE	0	httpOnlyCookie	httponly
horatius.pro	false	/	false	0	testKey	testValue
google.com   false	/	false	0	secondKey	secondValue

In addition to this it can read and create HTTP Response and Request (only generate) headers:

Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly
Cookie: name=value; test=horatius

Max-Age and Same-Site directives is not supported in actual version If you are interested to use it please make pull request

Install

npm install cookiefile --save

Usage

Loading library

let {Cookie, CookieMap, CookieError} = require('http-cookiefile')

Creating Cookie Object

It will provide JavaScript Map object with overloaded .set method

let cookie = new Cookie({
    domain: ".google.com",
    name: "testKey",
    value: "textValue",
    https: false, // default
    httpOnly: false, //default
    crossDomain: false, // default
    expire: Date.now() + 600 // default: 0
});

Reading Netscape Cookiefile

You can just enter your cookiefile path to load it into Map object

let cookieFile = new CookieMap('curl.cookiefile');

Or you can initialize it

let cookieFile = new CookieFile([
    cookie // Here is array of Cookie objects
]);

To read from Set-Cookie response header please use header method of CookieMap

const cookiesParsed = new CookieMap();
cookiesParsed.header('Set-Cookie: id=a3fWa');

Also, you can load cookie from request header Cookie: a=b;d=c:

const requestParsed = new CookieMap();

let options = {
    domain: ".google.com",
    secure: true,
}; // Options, which will be send to Cookie constructor

CookieMap.generate('Cookie: a=b;d=c', {htt})

Adding new cookies

Overloaded Map.set method. It will get name for the row from cookie object

cookieFile.set(cookie);

Reading values

You are able to use default Map methods like get, has, clear, and others.

let cookieValue = cookieFile.get('testKey')

Saving NetScape Cookie file

You can specify new name for new cookiefile. If you create CookieMap using filename it will be used by default.

cookieFile.save('new.cookiefile');
cookieFile.save(); // If you had specify filename when create object

toString methods

You are able to use toString methods for Cookie object

cookie.toString()

will return string like

google.com   false	/	false	0	secondKey	secondValue

For CookieMap toString is available too

cookieFile.toString();

will return string will full cookiefile

In addition to this you are able to use toRequestHeader and toResponseHeader method of CookieMap and Cookie objects:

cookieFile.toRequestHeader({http: true, secure:false});
cookieFile.toResponseHeader();

It will generate something like this:

Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly
Cookie: name=value; test=horatius

Tests

You are able to test this package using mocha

git clone https://github.com/horat1us/node-cookiefile
cd node-cookiefile
npm install
npm test