require-data

2.0.1 • Public • Published

require-data

Travis Build Status Coverage Status Dependencies Greenkeeper badge

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

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) => {})
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.

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

Parameters

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

Returns

  • {Promise<*>} Data of file.

Package Sidebar

Install

npm i require-data

Weekly Downloads

88

Version

2.0.1

License

MIT

Unpacked Size

10.6 kB

Total Files

6

Last publish

Collaborators

  • electerious