Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eemeli/yaml.macro
A Babel macro for loading YAML files
https://github.com/eemeli/yaml.macro
Last synced: about 2 months ago
JSON representation
A Babel macro for loading YAML files
- Host: GitHub
- URL: https://github.com/eemeli/yaml.macro
- Owner: eemeli
- License: isc
- Created: 2019-08-24T16:17:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T13:39:04.000Z (about 2 years ago)
- Last Synced: 2024-11-30T20:44:52.407Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/yaml.macro
- Size: 472 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml.macro
A [Babel macro](https://github.com/kentcdodds/babel-plugin-macros) for loading YAML files.
```
npm install --save-dev yaml.macro
```Source:
```yaml
# file.yaml
- YAML file
- with: some contents
``````js
import yaml from 'yaml.macro'const foo = yaml('./file.yaml')
```Result:
```js
const foo = ['YAML file', { with: 'some contents' }];
```## `yaml(path: string, options?: {}): any`
Relative `path` values should start with `.`. Internally, the macro uses [`yaml`](https://www.npmjs.com/package/yaml) and supports its [parser `options`](https://eemeli.org/yaml/#options) as a second argument. As the macro arguments are [evaluated](https://github.com/babel/babel/blob/master/packages/babel-traverse/src/path/evaluation.js) at build time, they should not be dynamically modified by preceding code.
Multiple calls to load the same YAML file will not be cached.