# require-data

> Extracts data out of multiple file types

Latest version **2.0.1** (published 2020-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install require-data
pnpm add require-data
yarn add require-data
bun add require-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 | 2.0.1 |
| Published | 2020-03-20 |
| First published | 2018-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | electerious |
| Keywords | require, data, json, js, sync, async |

## Links

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

## 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

- 2.0.1 (latest) — 2020-03-20
- 2.0.0 — 2020-03-20
- 1.0.0 — 2018-12-20

## README

# require-data

[![Travis Build Status](https://travis-ci.org/electerious/require-data.svg?branch=master)](https://travis-ci.org/electerious/require-data) [![Coverage Status](https://coveralls.io/repos/github/electerious/require-data/badge.svg?branch=master)](https://coveralls.io/github/electerious/require-data?branch=master) [![Dependencies](https://david-dm.org/electerious/require-data.svg)](https://david-dm.org/electerious/require-data#info=dependencies) [![Greenkeeper badge](https://badges.greenkeeper.io/electerious/require-data.svg)](https://greenkeeper.io/)

A function that tries to get the data out of a file that is either…

- … a JSON file
- … a JS file exporting a value that is not a function
- … a JS file exporting a function
- … a JS file exporting an async function

## Install

```
npm install require-data
```

## Usage

```js
const requireData = require('require-data')

requireData('data.json').then((data) => {})
requireData('data.js').then((data) => {})
requireData('sync.js').then((data) => {})
requireData('async.js').then((data) => {})
```

```js
const requireData = require('require-data')
const customRequire = require('continuous-stealthy-require')

requireData('data.json', customRequire).then((data) => {})
```

## Files

`require-data` will return data for all of those four files.

```json
{
  "some": "data"
}
```

```js
module.exports = {
	some: "data"
}
```

```js
module.exports = () => ({
	some: "data"
})
```

```js
module.exports = async () => ({
	some: "data"
})
```

## Parameters

- `filePath` `{String}` Path to file.
- `requireFn` `{?Function}` Custom require function.

## Returns

- `{Promise<*>}` Data of file.

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