1.0.0 • Published 6 years ago

yaml-hook v1.0.0

Weekly downloads
307
License
Apache-2.0
Repository
github
Last release
6 years ago

yaml-hook

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

Install - Usage - License: Apache-2.0

npm travis standard

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