https://github.com/bytebodger/get-cookies
A utility function that parses cookies into an object
https://github.com/bytebodger/get-cookies
Last synced: 12 months ago
JSON representation
A utility function that parses cookies into an object
- Host: GitHub
- URL: https://github.com/bytebodger/get-cookies
- Owner: bytebodger
- License: mit
- Created: 2021-03-07T15:04:14.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-24T01:31:28.000Z (about 5 years ago)
- Last Synced: 2025-05-14T09:15:34.841Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 80.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# get-cookies
`get-cookies` is a utility function that parses cookies into an object. Its default behavior will also attempt to convert cookie values into their "logical" data types.
## Usage
After installation, import the package:
```javascript
import { getCookies } from '@toolz/get-cookies';
```
### getCookies()
The function returns an object containing any existing cookie values and attempts to convert those values into native JS data types.
```javascript
const API = {
arguments: {
convertDataTypes: {
optional,
format: Boolean,
defaultValue: true,
},
},
returns: Object,
}
```
**Examples:**
```javascript
// document.cookies = 'isKool=true; name=mary; pi=3.14; children=null; age=42'
const cookies = getCookies();
/*
cookies = {
isKool: true,
name: 'mary',
pi: 3.14,
children: null,
age: 42,
}
*/
```
```javascript
// document.cookies = 'isKool=true; name=mary; pi=3.14; children=null; age=42'
const cookies = getCookies(false);
/*
cookies = {
isKool: 'true',
name: 'mary',
pi: '3.14',
children: 'null',
age: '42',
}
*/
```