1.0.4 ā€¢ Published 5 months ago

uncookie v1.0.4

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

uncookie - Javascript cookie

:cookie: A simple, lightweight JavaScript API for handling browser cookies, it is easy to pick up and use, has a reasonable footprint (~1.4kb) (gzipped: 0.78kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.

Features:

šŸš€ Has no dependencies

šŸŒ± Works in all browsers

šŸ Support TypeScript, including d.ts

šŸ“¦ Supports AMD/CommonJS

šŸ”„ Tree-shakable

šŸ’„ index.min.js 1.4kb(gzipped: 0.78kb)

Installation

npm install uncookie

Usage

import * as cookie from 'uncookie';

cookie.set('name', 'value', 1); // Set cookie
cookie.get('name'); // Get cookie
cookie.remove('name'); // Remove cookie

// # Options
cookie.set('name', 'value', {
  'expires': 30,
  'path': '/',
  'domain':''
});

API

cookie.set(name, value, options)
interface CookieOptions {
    expires?: number | Date | string;
    path?: string;
    domain?: string;
    secure?: boolean;
    sameSite?: 'None' | 'Strict' | 'Lax';
}
interface CookieValuesObj {
    [key: string]: string;
}
type CookieValues = string | CookieValuesObj;

declare function all(cookie?: string): Record<string, string>;

declare function get(name: string): string | false;
declare function set(name: CookieValues, value: CookieValues, options?: CookieOptions): void;
declare function remove(names: string | string[]): string | string[];
declare function clear(name?: string | string[]): string | string[];

Browser Support

<script src="https://unpkg.com/uncookie/dist/index.min.js"></script>

<script type="text/javascript">
  cookie.set("test", "tank");
</script>
1.0.4

5 months ago

1.0.3

6 months ago

1.0.1

8 months ago

1.0.0

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago

0.6.1

6 years ago

0.6.0

6 years ago