Skip to content

Instantly share code, notes, and snippets.

@grimen
Created December 26, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grimen/f5bf33f519db926baa8ae05e85c677a8 to your computer and use it in GitHub Desktop.
Save grimen/f5bf33f519db926baa8ae05e85c677a8 to your computer and use it in GitHub Desktop.
/* =========================================
IMPORTS
-------------------------------------- */
const fs = require('fs')
const path = require('path')
const _yaml = require('js-yaml')
/* =========================================
FUNCTIONS
-------------------------------------- */
function require_yml (filePath) {
return require_yaml(filePath)
}
function require_yaml (filePath) {
const data = fs.readFileSync(filePath, 'utf8')
return yaml.safeLoad(data)
}
function _require (filePath) {
const fileExtension = path.basename(filePath).split('.').pop()
const requireFunctionName = `require_${fileExtension}`
const requireFunction = eval(requireFunctionName)
console.log(fileExtension, requireFunction)
return requireFunction(filePath)
}
/* =========================================
EXPORTS
-------------------------------------- */
module.exports = _require
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment