minimal require() hook to load .yml/.yaml YAML files as JS objects
OTHER License
require() hook to load .yml/.yaml YAML files as JS objects
Compared to yamlify, this package does not include a browserify transform and does not handle yaml includes. If you use yaml as a prettier JSON for a configuration or language file, this is more than enough!
Install - Usage - License: Apache-2.0
npm install yaml-hook
This hook supports .yml and .yaml files. It uses js-yaml's safeLoad
function, so YAML-native things are supported, and JS-specific regex/function types are not supported.
var yamlHook = require('yaml-hook')
// install the hook
var hook = yamlHook()
// require() a yaml file
console.log(require('./somefile.yml'))
// uninstall the hook
hook.revert()
// can no longer require yaml files
// → throws
require('./otherfile.yaml')
To install the hook globally, you can do this at the entry point of your app:
require('yaml-hook/register')
This also works with transpiled ES modules using Babel. Note that it does not work with native ES modules, because yaml-hook uses the CommonJS hooking mechanism.
import 'yaml-hook/register'