0.2.2 • Published 5 months ago

ht-cookie v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

HT Cookie

Build Publish npm

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

NPM

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>;
}
0.2.2

5 months ago

0.2.1

6 months ago

0.2.0

11 months ago

0.1.1

1 year ago

0.1.0

1 year ago