Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kenmueller/web-cookies
Cookie package for the browser
https://github.com/kenmueller/web-cookies
Last synced: about 2 months ago
JSON representation
Cookie package for the browser
- Host: GitHub
- URL: https://github.com/kenmueller/web-cookies
- Owner: kenmueller
- Created: 2019-09-15T02:26:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T10:22:58.000Z (about 2 years ago)
- Last Synced: 2024-05-28T15:30:20.996Z (7 months ago)
- Language: TypeScript
- Size: 329 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# **web-cookies**
**Manipulate cookies in the browser**
## **Use in the browser**
```html
```
## **npm**
```bash
npm i web-cookies
```## **Functions**
- **[`all`](#all-function)**
- **[`get`](#get-function)**
- **[`set`](#set-function)**
- **[`remove`](#remove-function)**
- **[`exists`](#exists-function)**```typescript
/**
* Get all the cookies on the page
*
* @returns A key/value pair of all the cookies on the page
* @type `{ [name: string]: string }`
*/
function all(): { [name: string]: string }
``````typescript
/**
* Get the value for the specified cookie
*
* @param name The name of the cookie
* @returns The cookie's value of type `string`. Returns `undefined` if the cookie doesn't exist.
*/
function get(name: string): string | undefined
``````typescript
/**
* Set the value of a cookie
*
* @param name The name of the cookie
* @param value The cookie's value
* @param options.expiration
*
* The expiration of the cookie.
*
* If give an expiration of `'never'` or `null`, the cookie never expires.
*
* By default, the cookie expires on browser session end.
*
* Otherwise, you can specify a `Date` or a `string` for the expiration.
*
* @param options.path The path of the cookie. By default, it is `'/'`.
* @returns The cookie's record. Includes its name, value, expiration, and path
*/
function set(
name: string,
value: any,
options?: { expiration?: string | null | Date, path?: string }
): { name: string, value: any, expiration: Date | undefined, path: string }
``````typescript
/**
* Removes a cookie and returns the name
*
* @param name The name of the cookie
* @returns The name of the cookie that was removed
*/
function remove(name: string): string
``````typescript
/**
* Check if a cookie exists
*
* @param name The name of the cookie
* @returns Whether the cookie exists or not
*/
function exists(name: string): boolean
```