Created
December 26, 2019 20:41
-
-
Save grimen/f5bf33f519db926baa8ae05e85c677a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ========================================= | |
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