# opencrypto-data-js

> Universal Javascript client library for Opencrypto Data

Latest version **0.1.5** (published 2018-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install opencrypto-data-js
pnpm add opencrypto-data-js
yarn add opencrypto-data-js
bun add opencrypto-data-js
```

Provides the command `ocd`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2018-07-28 |
| First published | 2018-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 158.8 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | Opencrypto.io |
| Maintainers | tree |

## Links

- npm: https://www.npmjs.com/package/opencrypto-data-js
- npm.io page: https://npm.io/package/opencrypto-data-js

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [jmespath](https://npm.io/package/jmespath.md) ^0.15.0

## Recent versions

- 0.1.5 (latest) — 2018-07-28
- 0.1.4 — 2018-07-28
- 0.1.3 — 2018-07-28
- 0.1.2 — 2018-07-28
- 0.1.1 — 2018-07-27
- 0.1.0 — 2018-07-27

## README

# opencrypto-data-js

[![Build Status](https://travis-ci.org/opencrypto-io/data-js.svg?branch=master)](https://travis-ci.org/opencrypto-io/data-js)
 [![dependencies Status](https://david-dm.org/opencrypto-io/data-js/status.svg)](https://david-dm.org/opencrypto-io/data-js)
 [![npm bundle size (minified + zipped)](https://img.shields.io/bundlephobia/minzip/opencrypto-data-js.svg)](https://bundlephobia.com/result?p=opencrypto-data-js)
 [![npm](https://img.shields.io/npm/v/opencrypto-data-js.svg)](https://www.npmjs.com/package/opencrypto-data-js)


Universal Javascript client library for [Opencrypto Data](https://github.com/opencrypto-io/data)

## Installation

### Node.js / Webpack

Install package using NPM:
```bash
npm install --save opencrypto-data-js
```

And include library in your script:
```js
const ocd = require('opencrypto-data-js')
```

### Browser

Insert script loader into your html:
```html
<script src="https://opencrypto-io.github.io/data-js/dist/ocd.lib.min.js"></script>
```

Now you can access library thru `ocd` global variable.

## Usage

There is two methods how to use this library:

### Static usage
You dont need build a client instance, you can just use library:
```js
// require library
const ocd = require("opencrypto-data-js")

// get data
let data = await ocd.get("project", "ethereum")
```

### Client instance
Alternatively, you can build a custom client instance (and optionally specify your `options`):
```js
// require library
const ocd = require("opencrypto-data-js")

// construct client instance
const client = new ocd.Client({ preload: true })

// get data
let data = await client.get("project", "ethereum")
```

### Promises & async/await
This library has full support of Promises and async/await so you can use it as normal.

Async/await version:
```js
let data = await ocd.query("metadata.commit")
```

Promise variant:
```js
ocd.query("metadata.commit").then(res => {
  let data = res
})
```

## API

### Client(options = {}) constructor
Constructor for a new client.

Available `options`:
* `preload` (default: `false`)
* `dataUrl` (default: `https://data.opencrypto.io/data.json`)

### async raw()
Get complete raw data.
```js
let data = await ocd.raw()
```

### async query(query)
Query database by JMESPath query.
```js
await ocd.query("projects[].name")
```

### async get(model, id, query = "@")
Get object from database and run query against it (optional).
```js
await ocd.get("project", "ethereum")
await ocd.get("asset", "ethereum:eth")
```

### on(event, handler = (data) => data)
Bind to specified event. Not available as static method.
Available events:
* `loaded`

For example:
```js
let client = new ocd.Client({ preload: true })
await client.on("loaded")
```

### emit(event, data)

### version()

## CLI

To install CLI binary `ocd`, you need install package with `-g` option:
```bash
npm install -g opencrypto-data-js
```

Every command have simple command-line alternative:
```bash
ocd get asset bitcoin:btc
ocd query metadata.commit
ocd version
```

## License
MIT

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