https://github.com/electerious/require-data
Extracts data out of multiple file types.
https://github.com/electerious/require-data
Last synced: about 1 year ago
JSON representation
Extracts data out of multiple file types.
- Host: GitHub
- URL: https://github.com/electerious/require-data
- Owner: electerious
- License: mit
- Created: 2018-12-20T09:41:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-01T13:59:03.000Z (over 3 years ago)
- Last Synced: 2025-04-18T11:48:59.831Z (about 1 year ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# require-data
 [](https://coveralls.io/github/electerious/require-data?branch=master)
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.