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

svelte-cookie

v1.0.1

Published

An easy way to handle cookies in Svelte.

Downloads

2,047

Readme

Downloads Contributors Issues License

Table Of Contents

About The Project

Cookies are very often used in today's websites and web applications, but handling cookies in plain Javascript can be complicated. With Svelte-Cookie the complicated and complex cookie handling is over.

Here's why:

  • With the getCookie function, you can quickly get a cookie from the browser.
  • With the setCookie function, you can easily create a new cookie that will be set in the web browser.
  • With the deleteCookie function, you can quickly erase an existing cookie from the web browser.

Getting Started

It's very easy to get started with Svelte-Cookie. Follow the instructions below, and you will be working with cookies in no time.

Installation

To install, please write the following in your terminal:

npm install --save svelte-cookie

Usage

To use svelte-cookie, please start by importing the desired functions to your project. As of this moment, svelte-cookie contains 3 functions which are:

  • getCookie
  • setCookie
  • deleteCookie

You can import them by using the following line:

import { getCookie, setCookie, deleteCookie } from 'svelte-cookie';

Examples

Underneath here you will find some examples of ways to use the individual functions:

getCookie: The getCookie function is as the name says, getting a cookie. You do that by providing the name of the cookie. If the cookie exists the value length will be longer than 0.

let co = getCookie('userEmail');

If the userEmail cookie exist, you will get back the value. If it doesn't exist you will get back an empty string.

setCookie: The setCookie allows you to add a cookie to the web browser in only a few steps. The setCookie has some options which you have to provide:

  • Name - The first parameter is the name of the cookie.
  • Value - The second parameter is the string value you want to cookie to have.
  • Expiration days - Provide a number of how many days your cookie should stay in the web browser.
  • Secure - Write either true or false depending on whether you want your cookie to have the secure attribute.
setCookie('userEmail', '[email protected]', 30, true);

The above code will create a cookie named "userEmail", with the value "[email protected]". It will expire in 30 days and it will be set as secure.

deleteCookie: The deleteCookie function is very simple, and it will allow you to quickly erase a cookie from the web browser. You simply provide the name of the cookie as shown in the example below:

deleteCookie('userEmail');

License

Distributed under the MIT License. See LICENSE for more information.

Authors

  • Michael Andersen - Frontend web developer - Michael Andersen - Built Svelte-Cookie

SustainableWWW - Learn about environmentally friendly and ethical web design.