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

pastryjs

v0.1.0

Published

Platform and environment agnostic cookie module; Manage cookies on the browser and the backend.

Downloads

4

Readme

pastryjs

Platform and environment agnostic cookie module; Manage cookies on the browser and the backend.

Importing

// ES6 Module
import pastry, { SetWebCookieOptions, WebCookieHelpers, SetServerCookieOptions } from "pastryjs";

const cookie = pastry();

// Commonjs Module
const pastry, { SetWebCookieOptions, WebCookieHelpers, SetServerCookieOptions } = require("pastryjs");

You can also add the CDN via jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"></script>

Usage

On the web

import pastry from "pastryjs";

// for the web; has internal method
const webCookie = pastry().web()

// create a new cookie
webCookie.set(...)

On the server

import pastry from "pastryjs";
import server from "...";

const app = server();

app.get("/", (request, response) => {
	response.header.set(
		"Set-Cookie",
		pastry().server("foo", "bar", {
			domain: "https://www.foo.bar",
			maxAge: 3600,
		})
	);
	return response.json({ message: "Cookie set!" });
});

app.listen(8080);

Exports

pastry()

Initialise it as follows:

const cookie = pastry();

// This has five internal methods
const webCookie = cookie.web();

// server(...) is it's own method
const serverCookie = cookie.server(...);

web()

Used for setting cookies on the web. It returns the following methods.

set(key: string, value: string, options?: SetWebCookieOptions) => boolean

Set a cookie client side using javascript.

get(key: string) => string | null

Get the specific value of a cookie string.

delete(key: string) => boolean

Delete a cookie that was already set.

update(key: string, value: string, options?: SetWebCookieOptions) => boolean

Update a cookie client side using javascript; It calls cookie().set(...) under the hood but with the extra step of validating whether or not the cookie exists.

keys() => string[] | null

View all available cookie keys.

values() => string[] | null

View all available cookie values.

server(key: string, value: string, options?: SetServerCookieOptions)

It returns a string that you can use to set a Set-Cookie header.

Types

WebCookieHelpers

Typings for the internal methods of the cookie().web() method.

{
	set: (key: string, value: string, options?: SetCookieOptions) => boolean;
	get: (key: string) => string | null;
	delete: (key: string) => boolean;
	update: (key: string, value: string, options?: SetCookieOptions) => boolean;
	keys: () => string[] | null;
	values: () => string[] | null;
}

SetWebCookieOptions

Options for setting the cookie.

{
	domain?: string;
	expiry?: Date;
	maxAge?: number;
	partitioned?: boolean;
	path?: string;
	sameSite?: "Lax" | "Strict" | "None";
	secure?: boolean;
	httpOnly?: boolean;
}

SetServerCookieOptions

Options for setting the cookie on the server.

{
	domain?: string;
	expiry?: Date;
	maxAge?: number;
	partitioned?: boolean;
	path?: string;
	sameSite?: "Lax" | "Strict" | "None";
	secure?: boolean;
	httpOnly?: boolean;
}

Changelog

v0.1.x

  • Initial release