# read-data

> Read JSON or YAML files.

Latest version **1.1.0** (published 2017-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-data
pnpm add read-data
yarn add read-data
bun add read-data
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-04-02 |
| First published | 2014-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | async, data, file, fs, json, read, reader, sync, system, yaml |

## Links

- npm: https://www.npmjs.com/package/read-data
- Repository: https://github.com/jonschlinkert/read-data
- Issues: https://github.com/jonschlinkert/read-data/issues
- npm.io page: https://npm.io/package/read-data

## Dependencies (2)

- [read-yaml](https://npm.io/package/read-yaml.md) ^1.1.0
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2017-04-02
- 1.0.0 — 2016-12-31
- 0.3.0 — 2015-03-31
- 0.2.0 — 2014-10-24
- 0.1.1 — 2014-04-09
- 0.1.0 — 2014-04-09

## README

# read-data [![NPM version](https://img.shields.io/npm/v/read-data.svg?style=flat)](https://www.npmjs.com/package/read-data) [![NPM monthly downloads](https://img.shields.io/npm/dm/read-data.svg?style=flat)](https://npmjs.org/package/read-data)  [![NPM total downloads](https://img.shields.io/npm/dt/read-data.svg?style=flat)](https://npmjs.org/package/read-data) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/read-data.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/read-data)

> Read JSON or YAML files.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save read-data
```

**Heads up!**

Please read the [release history](#history), there were breaking changes in 1.0.0!

## Usage

```js
var read = require('read-data');

// sync
console.log(read.sync('foo.yml'));
console.log(read.sync('foo.yaml'));
console.log(read.sync('foo.json'));

// async
read('foo.yml', function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
read('foo.yaml', function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
read('foo.json', function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
```

## API

### [read](index.js#L41)

Asynchronously read a JSON or YAML file, automatically determining the reader based on extension.

**Params**

* `filepath` **{String}**: path of the file to read.
* `options` **{Object|String}**: to pass to [js-yaml](https://github.com/nodeca/js-yaml)
* `cb` **{Function}**: callback function
* `returns` **{Object}**: JSON

**Example**

```js
var read = require('read-data');

read('foo.json', function(err, data) {
  if (err) throw err;
  console.log(data);
});

read('foo.yml', function(err, data) {
  if (err) throw err;
  console.log(data);
});
```

### [.sync](index.js#L70)

Synchronously read a `.json` or `.(yaml|yml)` file, automatically determining the reader based on extension.

**Params**

* `filepath` **{String}**: path of the file to read.
* `options` **{Object|String}**: to pass to [js-yaml](https://github.com/nodeca/js-yaml)
* `returns` **{Object}**: JSON

**Example**

```js
var data = require('read-data').data;

var yaml = data.sync('foo.yml');
var json = data.sync('foo.json');
```

### [.yaml](index.js#L96)

Asynchronously read a YAML file.

**Params**

* `filepath` **{String}**: path of the file to read.
* `options` **{Object|String}**: to pass to [js-yaml](https://github.com/nodeca/js-yaml)
* `cb` **{Function}**: callback function
* `returns` **{Object}**: JSON

**Example**

```js
var yaml = require('read-data').yaml;

yaml('foo.yml', function(err, data) {
  if (err) throw err;
  console.log(data);
});
```

### [.yaml.sync](index.js#L113)

Synchronously read a YAML file.

**Params**

* `filepath` **{String}**: path of the file to read.
* `options` **{Object|String}**: to pass to [js-yaml](https://github.com/nodeca/js-yaml)
* `returns` **{Object}**: JSON

**Example**

```js
var yaml = require('read-data').yaml;
var data = yaml.sync('foo.yml');
```

### [.json](index.js#L134)

Asynchronously read a JSON file.

**Params**

* `filepath` **{String}**: path of the file to read.
* `callback` **{Function}**: callback function
* `returns` **{Object}**: JSON

**Example**

```js
var json = require('read-data');

json('foo.json', function(err, data) {
  if (err) throw err;
  console.log(data);
});
```

### [.json.sync](index.js#L166)

Synchronously read a JSON file.

**Params**

* `filepath` **{String}**: path of the file to read.
* `returns` **{Object}**: JSON

**Example**

```js
var json = require('read-data').json;
var data = json.sync('foo.json');
```

## History

### 1.0.0

**Breaking changes**

* The main export is now a function
* Use `read()` instead of `read.data()`
* Use `read.sync()` instead of `read.data.sync()`

Everything else is the same.

## About

### Related projects

* [copy](https://www.npmjs.com/package/copy): Copy files or directories using globs. | [homepage](https://github.com/jonschlinkert/copy "Copy files or directories using globs.")
* [read-yaml](https://www.npmjs.com/package/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files. | [homepage](https://github.com/jonschlinkert/read-yaml "Very thin wrapper around js-yaml for directly reading in YAML files.")
* [write](https://www.npmjs.com/package/write): Write files to disk, creating intermediate directories if they don't exist. | [homepage](https://github.com/jonschlinkert/write "Write files to disk, creating intermediate directories if they don't exist.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributors

| **Commits** | **Contributor** | 
| --- | --- |
| 14 | [jonschlinkert](https://github.com/jonschlinkert) |
| 1 | [tunnckoCore](https://github.com/tunnckoCore) |

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](http://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.3, on April 02, 2017._

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