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

cocookie

v1.0.0

Published

A minimalistic accurate JavaScript ES6 package to work with cookies

Downloads

3

Readme

CoCookie: Easy Cookies Interface

npm Dependencies Build Status License

CoCookie is a minimalistic accurate JavaScript ES6 package that provides a convenient interface to work with cookies.

The API is as simple as possible. The documented code is clean and transparent. See the usage in examples below.

Usage

import cookie from "cocookie";

// Set cookie "key" to value "bR6o1x"
cookie("key").set("bR6o1x");

// Set cookie "key" to value "bR6o1x" with additional attributes
cookie("key").set("bR6o1x", {
    domain: "my.domain.com",                         // domain to bind cookie to
    expires: new Date(Date.now() + 1000*60*60*24*7), // date when cookie expires
    maxAge: 60*60*24,                                // max time in seconds the cookie lives
    path: "/",                                       // the URL path the cookie will be bind to
    secure: true                                     // restrict cookie transport to HTTPS only
});

// Get value of cookie "key"
let key = cookie("key").get();

// Delete cookie "key"
cookie("key").delete();

// When cookie is already set, you can just update its without touching its value.
cookie("key").update({
    expires: new Date(Date.now() + 1000*60*60*24*7)  // refresh the cookie for 1 more week
});

// Delete cookie "key" with optional attributes
cookie("key").delete({
    domain: "my.domain.com",
    path: "/"
});

// Need the list of cookies to iterate through? Here you go:
import { cookies } from "cocookie";
cookies().forEach(name => cookie(name).delete());
// Note that you cannot delete cookies from other domains/paths in this way.
// Do delete the cookie from known path/domain use delete attributes (see delete above).

// If you need to store JSON in cookies (which is not common), use the following pattern.
cookie("key").set(JSON.stringify({ base: "bR6o1x", salt: "j5p9Qz" }));
let object = JSON.stringify(cookie("key").get());

Installation

npm install --save-dev cocookie

Install CoCookie as a npm dependency. Use this package with any module bundler like Webpack until ES6 modules standard will be implemented natively.

If your module bundler cannot resolve ES6 code, use import cookie from "cocookie/umd.js";. For usage from browser directly use the script tag (or download this script):

<script type="text/javascript" src="https://cdn.rawgit.com/ZitRos/cocookie/master/umd.js"></script>