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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bjnstnkvc/cookie

v1.0.2

Published

Simple wrapper for JavaScript Cookie.

Readme

Cookie

A class that provides a set of methods for interacting with the browser's local storage.

Installation & setup

NPM

You can install the package via npm:

npm install @bjnstnkvc/cookie

and then import it into your project

import { Cookie } from '@bjnstnkvc/cookie';

CDN

You can install the package via jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/@bjnstnkvc/cookie/lib/main.min.js"></script>

Usage

set

Set the value for a given key in the Cookie object.

Parameters

  • key - String containing the name of the key.
  • value - The value to be stored.
  • attributes (optional) - Cookie configuration options.

Example

Cookie.set('key', 'value'); 

get

Retrieve the value associated with the given key from the Cookie object.

Parameters

  • key - String containing the name of the key.
  • fallback (optional) - The fallback value in case the key does not exist. Defaults to null.

Example

Cookie.get('key', 'default');

You can also pass a closure as the default value. If the specified item is not found in the Cookie object, the closure will be executed and its result returned. This allows you to lazily load default values from other sources:

Cookie.get('key', () => 'default');

remember

Retrieve the value associated with the given key, or execute the given callback and store the result in the Cookie object.

Parameters

  • key - String containing the name of the key.
  • fallback - Function you want to execute.
  • attributes (optional) - Cookie configuration options.

Example

Cookie.remember('key', () => 'default');

all

Retrieve an array containing all keys and their associated values stored in the Cookie object.

Example

Cookie.all();

Note: The all method returns an array of objects with key and value properties (e.g. [{ key: 'key', value: 'value' }])

remove

Remove the key and its associated value from the Cookie object.

Parameters

  • key - String containing the name of the key to be deleted.
  • attributes (optional) - Cookie attributes (only path is allowed).

Example

Cookie.remove('key');

Optionally, you can pass attributes to the remove method to remove cookies from a specific path:

Cookie.remove('key', { path: '/' });

clear

Clear all keys and their associated values from the Cookie object.

Parameters

  • attributes (optional) - Cookie attributes (only path is allowed).

Example

Cookie.clear();

Optionally, you can pass attributes to the clear method to remove cookies from a specific path:

Cookie.clear({ path: '/' });

has

Check if a key exists in the Cookie object.

Parameters

  • key - String containing the name of the key to be checked.

Example

Cookie.has('key');

hasAny

Check if any of the provided keys exist in the Cookie object.

Parameters

  • keys - String or an array of strings containing the names of the keys to be checked.

Example

Cookie.hasAny(['key1', 'key2']);

isEmpty

Check if the Cookie object is empty.

Example

Cookie.isEmpty();

isNotEmpty

Check if the Cookie object is not empty.

Example

Cookie.isNotEmpty();

keys

Retrieve an array containing all keys stored in the Cookie object.

Example

Cookie.keys();

count

Retrieve the total number of items stored in the Cookie object.

Example

Cookie.count();

touch

Update the expiration time of a key in the Cookie object.

Parameters

  • key - String containing the name of the key.
  • ttl (optional) - Time to live in seconds for the key. Defaults to null (no expiration) or equal to Cookie.ttl value.
  • attributes (optional) - Cookie attributes (only path is allowed).

Example

Cookie.touch('key', 60);

Optionally, you can pass attributes to the touch method to update cookies from a specific path:

Cookie.touch('key', 60, { path: '/' });

dump

Print the value associated with a key to the console.

Parameters

  • key - String containing the name of the key.

Example

Cookie.dump('key');

ttl

Define a global Time-To-Live (TTL) in seconds for all items saved using the Cookie.set or Cookie.touch method, without specifying a TTL for each item. This can be particularly useful for applications needing a consistent expiry policy for most stored data.

Example

Cookie.ttl(7200);

If a default TTL has been set using Cookie.ttl, it will be applied to all items set without a specified TTL.

Cookie Attributes

When setting cookies, you can provide the following attributes:

  • ttl - Time to live in seconds (overrides expires if both are provided)
  • expires - Date object or date string for cookie expiration
  • path - Path for the cookie (defaults to current path)
  • domain - Domain for the cookie (defaults to current domain)
  • sameSite - SameSite attribute (Strict, Lax, or None)
  • secure - Whether the cookie should only be sent over secure protocols

Note: If sameSite is set to None, the secure attribute must be set to true.