Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

require-data

electerious341MIT2.0.1

Extracts data out of multiple file types

require, data, json, js, sync, async

readme

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.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[2.0.1] - 2020-03-20

Changed

  • Test with Node.js 10 and 12

[2.0.0] - 2020-03-20

Changed

  • Updated dependencies
  • Only support Node.js 10+
  • Test with Node.js 10 and 12

[1.0.0] - 2018-12-20

Added

  • Initial release