Skip to main content

Built and signed on GitHub Actions

A very simple cookie library

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Bun, Cloudflare Workers
JSR Score
100%
Published
3 months ago (0.2.3)

HT Cookie

Build Publish npm

A very simple cookie and local storage library with no dependencies.

NPM JSR

Add to project

Using npm: npm add ht-cookie

Using pnpm: pnpm add ht-cookie

Using yarn: yarn add ht-cookie

How to use

Cookies

import { Cookie } from "ht-cookie";

function syncExample() {
    Cookie.set(name: string, data: string, options?: CookieOptions): void;
    Cookie.get(name: string): string | null;
    Cookie.remove(name: string): void;
}

async function asyncExample() {
    await Cookie.aSet(name: string, data: string, options?: CookieOptions) : Promise<void>;
    await Cookie.aGet(name: string): Promise<string | null>;
    await Cookie.aRemove(name: string): Promise<void>;
}
interface CookieOptions {
    maxAge?: number,
    expires?: Date,
    domain?: string,
    path?: string,
    sameSite?: "strict" | "lax" | "none",
    secure?: boolean,
    partitioned?: boolean,
}

Local Storage

import { LocalStorage } from "ht-cookie";

function syncExample() {
    LocalStorage.set(name: string, data: string, maxAge?: number): void;
    LocalStorage.get(name: string): string | null;
    LocalStorage.remove(name: string): void;
}

async function asyncExample() {
    await LocalStorage.aSet(name: string, data: string, maxAge?: number) : Promise<void>;
    await LocalStorage.aGet(name: string): Promise<string | null>;
    await LocalStorage.aRemove(name: string): Promise<void>;
}
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @harmless/ht-cookie

Import symbol

import * as mod from "@harmless/ht-cookie";

Add Package

npx jsr add @harmless/ht-cookie

Import symbol

import * as mod from "@harmless/ht-cookie";

Add Package

yarn dlx jsr add @harmless/ht-cookie

Import symbol

import * as mod from "@harmless/ht-cookie";

Add Package

pnpm dlx jsr add @harmless/ht-cookie

Import symbol

import * as mod from "@harmless/ht-cookie";

Add Package

bunx jsr add @harmless/ht-cookie

Import symbol

import * as mod from "@harmless/ht-cookie";