Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/yaml-hook
minimal require() hook to load .yml/.yaml YAML files as JS objects
https://github.com/goto-bus-stop/yaml-hook
Last synced: 27 days ago
JSON representation
minimal require() hook to load .yml/.yaml YAML files as JS objects
- Host: GitHub
- URL: https://github.com/goto-bus-stop/yaml-hook
- Owner: goto-bus-stop
- License: other
- Created: 2019-02-27T15:20:31.000Z (over 5 years ago)
- Default Branch: default
- Last Pushed: 2021-04-29T21:12:11.000Z (over 3 years ago)
- Last Synced: 2024-10-05T16:25:53.586Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# yaml-hook
require() hook to load .yml/.yaml YAML files as JS objectsCompared to [yamlify](https://github.com/dmapper/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](#install) - [Usage](#usage) - [License: Apache-2.0](#license)
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url][npm-image]: https://img.shields.io/npm/v/yaml-hook.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/yaml-hook
[travis-image]: https://img.shields.io/travis/goto-bus-stop/yaml-hook.svg?style=flat-square
[travis-url]: https://travis-ci.org/goto-bus-stop/yaml-hook
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard## Install
```
npm install yaml-hook
```## Usage
This hook supports .yml and .yaml files. It uses [js-yaml](https://github.com/nodeca/js-yaml)'s `safeLoad` function, so YAML-native things are supported, and JS-specific regex/function types are not supported.```js
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:
```js
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.
```js
import 'yaml-hook/register'
```## License
[Apache-2.0](LICENSE.md)