# cyclejs-cookie

> Cookie Driver for Cycle.js, based on cookie_js

Latest version **0.7.4** (published 2016-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install cyclejs-cookie
pnpm add cyclejs-cookie
yarn add cyclejs-cookie
bun add cyclejs-cookie
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.4 |
| Published | 2016-08-28 |
| First published | 2016-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Wiktor Obrębski |
| Maintainers | psychowico |

## Links

- npm: https://www.npmjs.com/package/cyclejs-cookie
- Repository: https://github.com/10clouds/cyclejs-cookie
- Homepage: https://github.com/10clouds/cyclejs-cookie#readme
- Issues: https://github.com/10clouds/cyclejs-cookie/issues
- npm.io page: https://npm.io/package/cyclejs-cookie

## Dependencies (1)

- [cookie_js](https://npm.io/package/cookie_js.md) git://github.com/10clouds/cookie.js.git#master

## Recent versions

- 0.7.4 (latest) — 2016-08-28
- 0.7.3 — 2016-08-28
- 0.7.2 — 2016-08-28
- 0.7.1 — 2016-08-07
- 0.7.0 — 2016-08-07
- 0.6.0 — 2016-04-14
- 0.5.2 — 2016-04-12
- 0.5.1 — 2016-04-12
- 0.5.0 — 2016-04-12

## README

# Cycle JS Cookie Driver

[Cycle.js](https://github.com/staltz/cycle) Cookie Driver, based on [cookie_js](https://www.npmjs.com/package/cookie_js) library.

## Install
```shell
$ npm install --save cyclejs-cookie xstream
```

## Usage

``` javascript
import xs from 'xstream';
import {run} from '@cycle/xstream-run';
import {makeCookieDriver} from 'cyclejs-cookie';

function main({cookie}) {
    const cookieChangeSource$ = xs.periodic(1000);

    const cookieValue$ = cookie.get('MyCookie');

    // just for print debug
    const noop = () => undefined;
    cookieValue$.debug('cookie current value').addListener({
        next: noop,
        error: noop,
        complete: noop,
    });

    return {
        cookie: cookieChangeSource$.map((counter) => ({
            key: 'MyCookie',
            value: 'cookieValue-' + counter,
            settings: {
                expires: 30, // expiring in 30 days
            }
        }))
    };
};

run(main, {
    cookie: makeCookieDriver()
});
```

## Api
 Library export only one function: `makeCookieDriver`

## makeCookieDriver(options = {}}
 Instantiates an new cookie driver function ([cookieDriver(sink$)](#cookiedriversink)).
 
#### options
 - `decode` - set `cookie.decode` attribute, check [cookie_js](https://github.com/florian/cookie.js#a-word-on-encoding) documentation for details.

## cookieDriver(sink$)
 `$sink` - driver assumes that sink$ is stream of [_cookie setter objects_](#cookie-setter-object). it interprete _cookie setter object_ and set new cookie (or delete if cookie value is undefined).

 Returning cookies observables functions object `{get(), all()}`.
 - `get(cookieName)` - returning stream of cookie `cookieName` changes, initiated by current cookie value
 - `all()` - returning stream of all cookies object changes, initiated by starting cookies object
 
## cookie setter object
 Driver assumes following objects on it $sink:
 ```js
 {
   key: 'cookieName',
   value: 'cookieValue', // if undefined, cookie will be deleted
   options: {..}
 }
 ```
 Options is cookie settings, like expires time.
 By [cookie_js documentation](https://github.com/florian/cookie.js):
 
The following fields can be added to the mentioned object:

| key | value | default value |
|:--|:--|:--|
| `expires` |  Either a `number` containing the days until the expiry, a date in the `GMTString` format or a `date object`. | Expires when the browser is closed. |
| `domain` |  A `string` that specifies the domain that can access the cookie. | The current domain. |
| `path` | A `string` that limits the access of the cookie to that path. | The current path. |
| `secure` | A `boolean` indicating whether the cookie shall only be accessable over a secure connection or not. | `false` |

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