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

@langlois/cookies

v1.0.0

Published

A read/write library for browser cookies.

Downloads

4

Readme

Cookie Library

A javascript library that helps set, get and expire browser cookies.

Usage

import {cookies} from '@langlois/cookies';

// setting a cookie
cookies.set('testCookie', 'helloWorld');

// getting a cookie
cookies.get('testCookie'); // returns 'helloWorld'

// removing/expiring a cookie
cookies.expire('testCookie');
cookies.get('testCookie'); // returns undefined as cookie is expired

/*
	One can chain certain methods together.

	This chain will return:
		{
			testCookie: 'helloWorld',
			testCookie2: 'goodbyeWorld'
		}
*/
cookies.set('testCookie', 'helloWorld').set('testCookie2', 'goodbyeWorld', {
	domain: '.langlois.dev',
	expires: Infinity,
	path: '/',
	secure: true
}).getAll();

cookies.expire('testCookie2').get('testCookie') // returns 'helloWorld'
cookies.expireAll().get('testCookie'); // returns undefined

API

.enabled()

Determines we can set, get and remove a cookie.

Returns a Boolean.

Usage

cookies.enabled();

.expire(cookieName)

Expires the cookie with the passed cookieName.

Returns this to allow chaining.

Params

| Name | Type | Description | |------------|--------|-----------------------------------------------| | cookieName | String | The name/key of the cookie one wants expired. |

Usage

cookies.expire('testCookie');

.expireAll()

Expires all the cookies.

Returns this to allow chaining.

Usage

cookies.expireAll();

.get(cookieName)

Gets a cookie with the passed cookieName.

Returns a String representing the value of the cookie or undefined if the cookie doesn't exist.

Params

| Name | Type | Description | |------------|--------|---------------------------------------------------| | cookieName | String | The name/key of the cookie one wants to retrieve. |

Usage

cookies.get('testCookie');

.getAll()

Gets all the currently set cookies.

Returns an Object containing all the cookies and their values or undefined if there are no cookies.

Usage

cookies.getAll();

.set(cookieName, cookieValue, options)

Sets a cookie with the cookieName and cookieValue passed.

Returns this to allow chaining.

Params

| Name | Type | Default | Description | |-----------------|--------------------------------|-------------------------------------------|-----------------------------------------------------| | cookieName | String | | The name/key of the cookie to be set. | | cookieValue | String | | The value of the cookie to be set. | | options | Object | | Different cookie options to set | | options.domain | String | "" | Domain name that the cookie should be accessible to | | options.expires | String|Number|Infinity|Date | new Date('Fri, 31 Dec 9999 23:59:59 UTC') | Date that the cookie expires | | options.path | String | '/' | Path that has access to cookie | | options.secure | Boolean | false | Cookie to always use HTTPS or not |

Usage

cookies.set('testCookie', 'helloWorld', {
	domain: '',
	expires: new Date('Fri, 31 Dec 9999 23:59:59 UTC'),
	path: '/',
	secure: false
});

Chaining

One can chain the following methods:

  • .expire
  • .expireAll
  • .set

Example

cookies.expire('testCookie').get('testCookie'); // returns undefined
cookies.set('testCookie', 'helloWorld').set('testCookie2', 'goodbyeWorld').get('testCookie'); // returns 'helloWorld'