Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/urin/pico-cookie
Cookie mapper on browser by ECMAScript 2019+
https://github.com/urin/pico-cookie
cookie javascript
Last synced: 28 days ago
JSON representation
Cookie mapper on browser by ECMAScript 2019+
- Host: GitHub
- URL: https://github.com/urin/pico-cookie
- Owner: urin
- License: mit
- Created: 2020-03-07T05:26:16.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-22T08:23:17.000Z (almost 5 years ago)
- Last Synced: 2024-12-07T01:08:21.559Z (about 2 months ago)
- Topics: cookie, javascript
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pico-cookie - Cookie mapper on browser
===## Overview
[pico\-cookie](//github.com/urin/pico-cookie) provides the cookie object mapping to `document.cookie`.
Note that any direct operations to `document.cookie` are not reflected to the object `cookie`.
Keys and values are encoded and decoded by `encodeURIComponent` and `decodeURIComponent`.
## Requirement
- Chrome 73+
- Edge 79+
- Firefox 63+
- Safari 12.1+
- Opera 60+
- Internet Explorer is not supported
- Node.js 12.0.0+## Getting started
- Using npm
```shell
npm install pico-cookie
```- Using ES6 modules on browser
```html
import cookie from './pico-cookie.mjs'
// ...
```
- On browser
```html
```
## Usage
```js
// document.cookie is mapped to cookie
document.cookie // "SESSIONID=04ecb3d1b; APISID=ed724274d"
cookie // { SESSIONID: "04ecb3d1b", APISID: "ed724274d" }// Read
cookie.SESSIONID // "04ecb3d1b"
cookie.APISID // "ed724274d"// Update
cookie.SESSIONID = 'abcd'
cookie // { SESSIONID: "abcd", APISID: "ed724274d" }
document.cookie // "SESSIONID=abcd; APISID=ed724274d"// Add
cookie.NEWKEY = 'NEWVALUE'
cookie // { SESSIONID: "abcd", APISID: "ed724274d", NEWKEY: "NEWVALUE" }
document.cookie // "SESSIONID=abcd; APISID=ed724274d; NEWKEY=NEWVALUE"// Delete
delete cookie.NEWKEY
cookie // { SESSIONID: "abcd", APISID: "ed724274d" }
document.cookie // "SESSIONID=abcd; APISID=ed724274d"// Attributes
cookie.put('KEY', 'VALUE', { samesite: 'strict' }) // returns cookie itself// You can apply any methods same as plain object...
Object.keys(cookie) // ["SESSIONID", "APISID", "NEWKEY"]for (const [key, value] of Object.entries(cookie)) {
console.log(key, value)
}
```## License
[MIT](/LICENSE)
## Author
[urin](//github.com/urin)