yaml-hook

minimal require() hook to load .yml/.yaml YAML files as JS objects

OTHER License

Downloads
1.2K
Stars
2
Committers
1

yaml-hook

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

Install

npm install yaml-hook

Usage

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'

License

Apache-2.0