Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hunghg255/uncookie
A simple, lightweight JavaScript API for handling browser cookies
https://github.com/hunghg255/uncookie
cookies javascript npm
Last synced: about 2 months ago
JSON representation
A simple, lightweight JavaScript API for handling browser cookies
- Host: GitHub
- URL: https://github.com/hunghg255/uncookie
- Owner: hunghg255
- License: mit
- Created: 2023-09-19T02:50:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-02T20:52:34.000Z (11 months ago)
- Last Synced: 2024-10-31T10:52:07.463Z (2 months ago)
- Topics: cookies, javascript, npm
- Language: TypeScript
- Homepage:
- Size: 473 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A library to parse cookie string to object and vice versa.: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](https://unpkg.com/[email protected]/dist/index.min.js) 1.4kb(gzipped: 0.78kb)
## Installation
```bash
npm install uncookie
```## Usage
```javascript
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
```ts
cookie.set(name, value, options)
``````ts
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;
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
```html
cookie.set("test", "tank");
```