UNPKG

cosmiconfig

Version:

Find and load configuration from a package.json property, rc file, or CommonJS module

30 lines (24 loc) 584 B
// 'use strict'; const parseJson = require('parse-json'); const yaml = require('js-yaml'); function loadJs(filepath ) { const result = require(filepath); return result; } function loadJson(filepath , content ) { try { return parseJson(content); } catch (err) { err.message = `JSON Error in ${filepath}:\n${err.message}`; throw err; } } function loadYaml(filepath , content ) { return yaml.safeLoad(content, { filename: filepath }); } module.exports = { loadJs, loadJson, loadYaml, };