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

hardtack

v5.0.1

Published

An ultra-light (373 bytes) library for working with cookies in JavaScript

Downloads

12,757

Readme

hardtack

NPM GitHub Actions Coverage Status

An ultra-light library for working with cookies in JavaScript.

Features

  • Simple API
  • Ultra-light (373 bytes minified and gzipped). No dependencies. Size Limit controls the size.
  • Encoding of forbidden characters
  • Load only the necessary method

Table of contents

Quick start

Installation

yarn add hardtack -E
# or
npm i hardtack -E

Usage

// Load the full library
import hardtack from 'hardtack';
// Load the necessary method
import get from 'hardtack/src/get';
import set from 'hardtack/src/set';
import remove from 'hardtack/src/remove';

hardtack.set('name', 'Ali', {
  path: '/',
  domain: 'gasymov.com',
  maxAge: 31536000, // 1 year
  samesite: 'lax'
});

hardtack.get(); // { name: 'Ali' };

hardtack.get('name'); // Ali;

hardtack.remove('name', {
  path: '/',
  domain: 'gasymov.com'
});

Methods

set(name: string, value: string, options)

Create a cookie

options.path: string

For example: '/', '/mydir'

If not specified, defaults to the current path of the current document location.

options.domain: string

For example: example.com or subdomain.example.com

If not specified, this defaults to the host portion of the current document location. Contrary to earlier specifications, leading dots in domain names are ignored, but browsers may decline to set the cookie containing such dots. If a domain is specified, subdomains are always included.

options.maxAge: number

You can use options['max-age'], the result will be the same.

Max age in seconds. For example: 60*60*24*365 or 31536000 for a year

options.expires: string

Date in GMT format. See Date.toUTCString() for help formatting this value.

options.secure: boolean

Cookie to only be transmitted over secure protocol as https.

options.samesite: string

SameSite prevents the browser from sending this cookie along with cross-site requests. Possible values for the flag are lax or strict.

More about the options of cookies on MDN.

get(name: string)

Get cookie value

remove(name: string, options)

Remove cookie. When you delete a cookie, you must pass the same options.path and options.domain that you passed when you created the cookie.