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

als-cookie-options

v1.6.0

Published

A library for managing cookie settings in Node.js applications, providing structured ways to define and serialize cookie options with built-in security and validation.

Downloads

109

Readme

als-cookie-options

als-cookie-options is a library for managing cookie settings in Node.js applications, providing a structured way to define and serialize cookie options with built-in security and validation.

V1.5 Expired fixed to toLocaleString

Features

  • Validation: Ensures that all cookie settings comply with standard specifications before serialization.
  • Security: Integrates checks to ensure cookies are created with secure attributes when required.
  • Flexibility: Offers customization for most cookie attributes, such as domain, path, expires, httpOnly, secure, and more.

Installation

Install als-cookie-options using npm:

npm install als-cookie-options

Usage

Here's a basic example of how to use als-cookie-options to create cookie settings:

const { serializeOptions } = require('als-cookie-options');
const http = require('http');

const options = {
   domain: 'example.com',
   path: '/',
   secure: true,
   httpOnly: true,
   maxAge: 3600,
   sameSite: 'strict'
};
http.createServer((req, res) => {
    const cookieHeader = serializeOptions(options, req);
    res.setHeader('Set-Cookie', 'somecookie=value;'+cookieHeader);
    res.end();
}).listen(3000);

API Reference

serializeOptions(options, req)

Serializes the cookie options into a string that can be used in a Set-Cookie header.

Parameters

  • options (Object): Cookie options to serialize. Supported properties:
    • domain (String, optional): Specifies the domain for the cookie.
    • path (String, optional): Specifies the path for the cookie.
    • expires (Date, optional): Specifies the expiration date of the cookie.
    • maxAge (Number, optional): Specifies the number of seconds until the cookie expires.
    • httpOnly (Boolean): Specifies whether the cookie is HTTP-only.
    • secure (Boolean): Specifies whether the cookie should be secure.
    • partitioned (Boolean, optional): Specifies whether the cookie should be partitioned (experimental).
    • priority (String, optional): Specifies the priority of the cookie (low, medium, high).
    • sameSite (String, optional): Specifies the SameSite attribute of the cookie (strict, lax, none).
  • req (Object): The request object from the HTTP server. Used to determine the correct security settings.

Returns

  • (String): A string suitable for use in a Set-Cookie HTTP header.

Examples

Setting a secure cookie with HTTP-only flag

const options = {
    secure: true,
    httpOnly: true,
    maxAge: 3600,
    domain: 'example.com',
    path: '/secure',
    sameSite: 'strict'
};

const cookieHeader = serializeOptions(options, { secure: true });
console.log(cookieHeader);