<commit_before># hoodie-client

> Hoodie Client Core

[![Build Status](https://travis-ci.org/hoodiehq/hoodie-client.svg?branch=master)](https://travis-ci.org/hoodiehq/hoodie-client)
[![Coverage Status](https://coveralls.io/repos/hoodiehq/hoodie-client/badge.svg?branch=master)](https://coveralls.io/r/hoodiehq/hoodie-client?branch=master)
[![Dependency Status](https://david-dm.org/hoodiehq/hoodie-client.svg)](https://david-dm.org/hoodiehq/hoodie-client)
[![devDependency Status](https://david-dm.org/hoodiehq/hoodie-client/dev-status.svg)](https://david-dm.org/hoodiehq/hoodie-client#info=devDependencies)

This is the hoodie client glue code that initialises the hoodie client core
including [store](https://github.com/hoodiehq/pouchdb-hoodie-store),
[account](https://github.com/hoodiehq/account-client), and
[task](https://github.com/hoodiehq/task-client)

`hoodie-client` exports a constructor that gets initialised in `hoodie-server`

```js
var Hoodie = require('hoodie-client')
global.hoodie = new Hoodie()
```

## Core client APIs

- `hoodie.id()`  
   Returns a unique, persistent identifier for the current user.
- `hoodie.on()`  
   Adds an event handler for the specified events
- `hoodie.one()`  
   Binds a one-time event handler to the specified event. Once the event has
   been caught, the listener will be unbound automatically.
- `hoodie.off()`
   Unbind event handlers from a certain event.
- `hoodie.trigger()`  
   Triggers a certain event. This includes both custom and predefined events.
- `hoodie.checkConnection()`  
   Sends request to the Hoodie Server to check if it is reachable
- `hoodie.isConnected()`  
   Returns true if Hoodie backend can currently be reached, otherwise false
- `hoodie.request(type, url/*, options/*)`  
   Sends a request
- `hoodie.log`  
   see https://github.com/hoodiehq/hoodie-client-log for more info
   - `hoodie.log(message)`
   - `hoodie.log.info(message)`
   - `hoodie.log.warn(message)`
   - `hoodie.log.error(message)`
   - `hoodie.log.scoped(name)`
- `hoodie.connectionStatus`  
   see https://github.com/hoodiehq/hoodie-client-connection-status for more info
   - `hoodie.connectionStatus.ok`
   - `hoodie.connectionStatus.check(options)`
   - `hoodie.connectionStatus.on(event, handler)`
- `hoodie.reset()`  
   Reset hoodie client and emit `reset` events so plugins can reset as well
- `hoodie.plugin(function (hoodie) {})`  
   Initialise hoodie plugin

Also compare docs of old hoodie client API, it's mostly the same:
http://docs.hood.ie/en/techdocs/api/client/hoodie.html

### Testing

```
npm test
```

### License

Apache 2.0<commit_msg>docs(README): adapt to new module names<commit_after># hoodie-client

> Hoodie’s front-end client for the browser

[![Build Status](https://travis-ci.org/hoodiehq/hoodie-client.svg?branch=master)](https://travis-ci.org/hoodiehq/hoodie-client)
[![Coverage Status](https://coveralls.io/repos/hoodiehq/hoodie-client/badge.svg?branch=master)](https://coveralls.io/r/hoodiehq/hoodie-client?branch=master)
[![Dependency Status](https://david-dm.org/hoodiehq/hoodie-client.svg)](https://david-dm.org/hoodiehq/hoodie-client)
[![devDependency Status](https://david-dm.org/hoodiehq/hoodie-client/dev-status.svg)](https://david-dm.org/hoodiehq/hoodie-client#info=devDependencies)

This is the hoodie client glue code that integrates the hoodie client core modules

## Example

```js
var Hoodie = require('hoodie-client')
var hoodie = new Hoodie(options)

hoodie.acount.signUp({
  username: '<EMAIL>',
  password: '<PASSWORD>'
}).then(function (accountAttributes) {
  hoodie.log.info('Signed up as %s', accountAttributes.username)
}).catch(function (error) {
  hoodie.log.error(error)
})
```

## API

- [Constructor](#constructor)
- [hoodie.id](#hoodieid)
- [hoodie.url](#hoodieurl)
- [hoodie.account](#hoodieaccount)
- [hoodie.store](#hoodiestore)
- [hoodie.task](#hoodietask)
- [hoodie.connectionStatus](#hoodieconnectionstatus)
- [hoodie.log](#hoodielog)
- [hoodie.request](#hoodierequest)
- [hoodie.plugin](#hoodieplugin)
- [hoodie.reset](#hoodiereset)
- [hoodie.on](#hoodieon)
- [hoodie.one](#hoodieone)
- [hoodie.off](#hoodieoff)
- [hoodie.trigger](#hoodietrigger)
- [Events](#events)

### Constructor

````js
hoodie = new Hoodie({
  // optional. set to hostname where Hoodie server runs, if your app runs on
  // a different host
  url: 'http://example.com',

  // optional: account options
  // https://github.com/hoodiehq/hoodie-client-account#constructor
  // options.url is always set to hoodie.url + '/account/api'
  account: {},

  // optional: store options
  // https://github.com/hoodiehq/hoodie-client-store#constructor
  // options.dbName is always set to hoodie.id
  // options.remote is always set to hoodie.url + '/store/api'
  store: {},

  // optional: task options
  // https://github.com/hoodiehq/hoodie-client-test#constructor
  // options.userId is always set to hoodie.id
  // options.remote is always set to hoodie.url + '/task/api'
  task: {},

  // optional: connectionStatus options
  // https://github.com/hoodiehq/hoodie-client-connection-status#constructor
  // options.url is always set to hoodie.url + '/connection-status/api'
  // options.method is always set to 'HEAD'
  connectionStatus: {},

  // optional: log options
  // https://github.com/hoodiehq/hoodie-client-log#constructor
  log: {}
})
```

### `hoodie.id`

Read-only, unique, persistent identifier for the current user. It gets generated
on first load, it does not depend on an user account

### `hoodie.url`

---

🐕 **TO BE DONE**: [#13](https://github.com/hoodiehq/hoodie-client/issues/13)

---

Read-only, full url to the hoodie server, e.g. `http://example.com/hoodie`

### `hoodie.account`

see [account API](https://github.com/hoodiehq/hoodie-client-account#api)

### `hoodie.store`

see [store API](https://github.com/hoodiehq/hoodie-client-store#api)

### `hoodie.task`

see [task API](https://github.com/hoodiehq/hoodie-client-account#api)

### `hoodie.connectionStatus`

see [connectionStatus API](https://github.com/hoodiehq/hoodie-client-connection-status#api)

---

🐕 **API DESIGN DISCUSSION IN PROGRESS**: [#6](https://github.com/hoodiehq/hoodie-client/issues/6)

---

### `hoodie.log`

see [log API](https://github.com/hoodiehq/hoodie-client-log#api)

### `hoodie.request`

---

🐕 **TO BE DONE**: [#9](https://github.com/hoodiehq/hoodie-client/issues/9)

---

Sends a request, returns a promise

```js
hoodie.request(options)
```

Examples

```js
// sends a GET request to hoodie.url + '/foo/api/bar'
hoodie.request('/foo/api/bar')
// sends a GET request to another host
hoodie.request('https://example.com/foo/bar')
// sends a PATCH request to /foo/api/bar
hoodie.request({
  method: 'PATCH',
  url: '/foo/api/bar',
  data: {
    foo: 'bar'
  }
})
```

### `hoodie.plugin`

---

🐕 **TO BE DONE**: [#2](https://github.com/hoodiehq/hoodie-client/issues/2)

---

Initialise hoodie plugin

```js
hoodie.plugin(objectOrfunction)
```

Examples

```js
hoodie.plugin({
  sayHi: function () { alert('hi') }
})
```

```js
hoodie.plugin(function (hoodie) {
  hoodie.sayHi = function () { alert('hi') }
})
```

### `hoodie.reset`

---

🐕 **TO BE DONE**: [#12](https://github.com/hoodiehq/hoodie-client/issues/12)

---

Reset hoodie client and emit `reset` events so plugins can reset as well.
Returns a promise

```js
hoodie.reset()
```

### `hoodie.on`

---

🐕 **TO BE DONE**: [#14](https://github.com/hoodiehq/hoodie-client/issues/14)

---

```js
hoodie.on(eventName, handler)
```

Example

```js
hoodie.on('account:signin', function (username) {
  alert('Hello there, ' + username)
})
```

### `hoodie.one`

---

🐕 **TO BE DONE**: [#14](https://github.com/hoodiehq/hoodie-client/issues/14)

---

```js
hoodie.one(eventName, handler)
```

Example

```js
hoodie.one('mycustomevent', function (options) {
  console.log('foo is %s', options.bar)
})
hoodie.trigger('mycustomevent', { foo: 'bar' })
hoodie.trigger('mycustomevent', { foo: 'baz' })
// logs "foo is bar"
// DOES NOT log "foo is baz"
```

### `hoodie.off`

---

🐕 **TO BE DONE**: [#14](https://github.com/hoodiehq/hoodie-client/issues/14)

---

Removes event handler that has been added before

```js
hoodie.off(eventName, handler)
```

Example

```js
hoodie.off('connectionstatus:disconnected', showNotification)
```

### `hoodie.trigger`

---

🐕 **TO BE DONE**: [#14](https://github.com/hoodiehq/hoodie-client/issues/14)

---

Trigger custom events

```js
hoodie.trigger(eventName[, option1, option2, ...])
```

Example

```js
hoodie.trigger('mycustomevent', { foo: 'bar' })
```

### Events

<table>
  <tr>
    <th align="left"><code>reset</code></th>
    <td>triggered when `hoodie.reset()` succeeded</td>
  </tr>
  <tr>
    <th align="left"><code>account:*</code></th>
    <td>events, see <a href="https://github.com/hoodiehq/hoodie-client-account#events">account events</a></td>
  </tr>
  <tr>
    <th align="left"><code>store:*</code></th>
    <td>events, see <a href="https://github.com/hoodiehq/hoodie-client-store#events">store events</a></td>
  </tr>
  <tr>
    <th align="left"><code>task:*</code></th>
    <td>events, see <a href="https://github.com/hoodiehq/hoodie-client-task#events">task events</a></td>
  </tr>
  <tr>
    <th align="left"><code>connectionStatus:*</code></th>
    <td>events, see <a href="https://github.com/hoodiehq/hoodie-client-connection-status#events">task events</a></td>
  </tr>
</table>

## Testing

Local setup

```
git clone <EMAIL>:hoodiehq/hoodie-client.git
cd hoodie-client
npm install
```

Run all tests

```
npm test
```

Run test from one file only

```
node tests/specs/id
```

## License

Apache 2.0

{'fraction_non_alphanumeric': 0.18406821963394343, 'fraction_numerical': 0.0037437603993344427, 'mean_word_length': 4.131803628601921, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 58, 'https://': 45, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '277218', 'n_tokens_mistral': 3590, 'n_tokens_neox': 3448, 'n_words': 691}