Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/markcellus/cookie-store
A polyfill for the Cookie Store API
https://github.com/markcellus/cookie-store
cookie-polyfill cookie-store cookies polyfill
Last synced: 2 days ago
JSON representation
A polyfill for the Cookie Store API
- Host: GitHub
- URL: https://github.com/markcellus/cookie-store
- Owner: markcellus
- License: mit
- Created: 2019-09-22T13:24:34.000Z (over 5 years ago)
- Default Branch: next
- Last Pushed: 2023-07-18T21:34:35.000Z (over 1 year ago)
- Last Synced: 2024-04-14T07:43:20.982Z (9 months ago)
- Topics: cookie-polyfill, cookie-store, cookies, polyfill
- Language: JavaScript
- Homepage:
- Size: 677 KB
- Stars: 97
- Watchers: 1
- Forks: 14
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `cookie-store`
[![Build Status](https://travis-ci.org/markcellus/cookie-store.svg?branch=master)](https://travis-ci.org/markcellus/cookie-store)
[![npm version](https://badge.fury.io/js/cookie-store.svg)](https://www.npmjs.com/package/cookie-store)A ponyfill to allow use of the [Cookie Store API](https://wicg.github.io/cookie-store/) in modern browsers that don't support it natively, including IE11. Also compatible with TypeScript.
:warning: **EXPERIMENTAL:** _The Cookie Store API is not a W3C standard yet and the final implementation may differ from the current API of this project._
## Installation
To ensure the most up-to-date compatibility with browsers, we recommend that you install version 4 of the package with the `next` flag:
```sh
npm install cookie-store@next
```## Basic Example
```js
// import polyfill and declare types
import { cookieStore } from 'cookie-store';// set a cookie
await cookieStore.set('forgive', 'me');
// get a cookie
const foo = await cookieStore.get('forgive');
console.log(foo); // { name: 'forgive', value: 'me' }// set another cookie
await cookieStore.set('forget', 'it');// get multiple cookies
const cookies = await cookieStore.getAll();
console.log(cookies); // [{ name: 'forgive', value: 'me' }, { name: 'forget', value: 'it' }]// delete a cookie
await cookieStore.delete('forget');
```## Development
### Tests
Before running tests, you'll need to add the following entry to your `/etc/hosts` file on your machine:
```
127.0.0.1 foo.bar.localhost
```Then run `npm test`