# coocal

> 🖖 A simple frontend library for manage cookies and local-storage easily.

Latest version **1.0.9** (published 2023-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install coocal
pnpm add coocal
yarn add coocal
bun add coocal
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2023-08-12 |
| First published | 2022-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 3 |
| Author | Can Çevik |
| Maintainers | canccevik |
| Keywords | cookies, local-storage |

## Links

- npm: https://www.npmjs.com/package/coocal
- Repository: https://github.com/canccevik/coocal
- Homepage: https://github.com/canccevik/coocal#readme
- Issues: https://github.com/canccevik/coocal/issues
- npm.io page: https://npm.io/package/coocal

## Dependencies (1)

- [cookie](https://npm.io/package/cookie.md) ^0.5.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2023-08-12
- 1.0.8 — 2022-08-24
- 1.0.7 — 2022-08-06

## README

<p align="center">
<img src="https://i.imgur.com/McR9nWr.png" alt="Coocal Logo" width="400"/>
</p>

<br>

<p align="center">🖖 A simple frontend library for manage cookies and local-storage easily.</p>

## Features

- Lightweight
- Supports ES modules
- Easy API for dealing with cookies
- Expire dates for local-storage items

## Installation

Using npm:

```js
npm install coocal
```

Using yarn:

```js
yarn add coocal
```

Using pnpm:

```js
pnpm add coocal
```

## Usage

```js
import Coocal from 'coocal'

const { cookies, localStorage } = Coocal
```

## Cookies

Create an accessible cookie from the entire site:

```js
cookies.set('name', 'value')
```

Create a 5-day cookie accessible from the entire site:

```js
cookies.set('name', 'value', { expires: { d: 5 } })
```

Read a cookie:

```js
cookies.get('name') // => "value"
```

Read all cookies:

```js
cookies.getAll() // => [cookie1, cookie2, ...]
```

Remove a cookie:

```js
cookies.remove('name')
```

Remove all of the cookies:

```js
cookies.removeAll()
```

## Cookie Options

Set expiration date of the cookie:

```js
cookies.set('name', 'value', { expires: { d: 7, h: 12, m: 40 } })
// Y: year, M: month, W: week, d: day, h: hour, m: minute, s: second

// or

cookies.set('name', 'value', { expires: '7d 12h 40m' })

// or

cookies.set('name', 'value', { expires: 650400 })
// 7 days, 12 hours and 40 minutes in seconds
```

Set path of the cookie:

```js
cookies.set('name', 'value', { path: '/profile.html' })
```

Set domain of the cookie:

```js
cookies.set('name', 'value', { domain: 'localhost' })
```

Set sameSite option of the cookie:

```js
cookies.set('name', 'value', { sameSite: 'Strict' })
// SameSite: Strict, Lax, None
```

Set secure option of the cookie:

```js
cookies.set('name', 'value', { secure: true })
```

## Local Storage

Create a local storage item:

```js
localStorage.set('name', 'value')
```

Create a local storage item for three days:

```js
localStorage.set('name', 'value', { expires: { d: 3 } })
```

Read a local storage item:

```js
localStorage.get('name') // => "value"
```

Read all local storage items:

```js
localStorage.getAll() // => [item1, item2, ...]
```

Remove a local storage item:

```js
localStorage.remove('name')
```

Remove all of the local storage items:

```js
localStorage.removeAll()
```

## Local Storage Options

Set expiration date of the local storage item:

```js
localStorage.set('name', 'value', { expires: { W: 2, m: 30 } })
// Y: year, M: month, W: week, d: day, h: hour, m: minute, s: second

// or

localStorage.set('name', 'value', { expires: '2W 30m' })

// or

localStorage.set('name', 'value', { expires: 1211400 })
// 2 weeks and 30 minutes in seconds
```

## Contributing

1. Fork this repository.
2. Create a new branch with feature name.
3. Create your feature.
4. Commit and set commit message with feature name.
5. Push your code to your fork repository.
6. Create pull request.

## License

[MIT](https://github.com/canccevik/coocal/blob/master/LICENSE)

---
_Source: https://npm.io/package/coocal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
