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

electrode-cookies

v1.0.5

Published

Electrode ISO cookies lib

Downloads

16

Readme

Electrode Cookies

Electrode isomorphic cookies lib.

Install

npm install electrode-cookies --save

Usage

This module offers reading and setting cookies in React code that works in both the browser or when doing Server Side Rendering.

In your pure server only code, you can also use this module to read and set cookies, but you MUST pass the request object in the options. Otherwise an assert error will be thrown.

In NodeJS land:

const Cookies = require("electrode-cookies");

Reading cookies

In ReactJS land:

import Cookies from "electrode-cookies";
const value = Cookies.get("test-cookie");

In NodeJS land:

Note the difference is that request is passed in options.

const Cookies = require("electrode-cookies");
const value = Cookies.get("test-cookie", { request });

Writing cookies

In ReactJS land:

import Cookies from "electrode-cookies";
Cookies.set( "foo", "bar", { path: "/", domain: ".walmart.com" } );

In NodeJS land:

Note the difference is that request is passed in options.

const Cookies = require("electrode-cookies");
Cookies.set( "foo", "bar", { request, path: "/", domain: ".walmart.com" } );

Electrode Server Setup

The cookie writing on server side requires support from a Hapi plugin. If you use electrode-server, then it should have setup the plugin for you by default. Otherwise, you need to register the hapi plugin.

APIs

Cookies.get

Cookies.get(key, [options])

Parameters:

  • key - name of the cookie
  • options - (optional) Available for Server side only. options for getting the cookie
    • request - The server request object (Required on server).
    • matchSubStr - If true, then do substring matching of key with all cookie keys.
      • skipEncoding - (applies only if matchSubStr is true) If true, then do not encode the key or decode the value.

Returns the value of the cookie for key.

Cookies.set

Cookies.set(key, value, [options])

Set a cookie with key and value.

Parameters:

  • key - name of the cookie
  • value - value of the cookie
  • options - (optional) options for the cookie
    • request - On the server side, the request object (Required on server).
    • path - string path of the cookie Default: "/"
    • domain - string domain of the cookie
    • expires - number of seconds the cookie will expire
    • secure - A boolean of whether or not the cookie should only be available over SSL Default: false
    • httpOnly - A boolean of whether or not the cookie should only be available over HTTP(S) Default: false
    • forceAuthEncoding - Forces non-standard encoding for + and / characters, use with auth cookies.
    • skipEncoding - Skip encoding/escaping of the cookie value. See source for details.

Cookies.expire

Cookies.expire(key, [options])

Expires a cookie specified by key.

Parameters:

  • key - name of the cookie
  • options - (optional) options for the cookie
    • path - string path of the cookie Default: "/"
    • domain - string domain of the cookie
    • secure - A boolean of whether or not the cookie should only be available over SSL Default: false
    • request - The server request object (Required on server)