https://github.com/shigma/yml-register
Hooks into Node's require function to load `.yaml` and `.yml` files
https://github.com/shigma/yml-register
Last synced: 6 months ago
JSON representation
Hooks into Node's require function to load `.yaml` and `.yml` files
- Host: GitHub
- URL: https://github.com/shigma/yml-register
- Owner: shigma
- License: mit
- Created: 2022-05-14T07:57:16.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T08:11:28.000Z (over 2 years ago)
- Last Synced: 2025-10-25T18:11:29.639Z (10 months ago)
- Language: TypeScript
- Size: 20.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# yml-register
[](https://www.npmjs.com/package/yml-register)
[](https://www.npmjs.com/package/yml-register)
[](https://github.com/shigma/yml-register/blob/master/LICENSE)
Hooks into `require` / `import` to load `.yaml` and `.yml` files.
## Usage
### From CLI
CJS:
```sh
node -r yml-register path/to/index.cjs
```
ESM (Node.js 20.6.0 or later):
```sh
node --import yml-register path/to/index.mjs
```
### Manually import
CJS:
```js
require('yml-register')
require('path/to/file.yml') // now it works!
```
ESM:
```js
import 'yml-register'
const data = await import('path/to/file.yml') // now it works!
```
### TypeScript support
In order to fixing the error `Cannot find module 'file.yml' or its corresponding type declarations.` when using `import` statement in TypeScript, we provides a type declaration bundled in this package.
What you need is to append `compilerOptions.types` by `yml-register/types` in `tsconfig.json`.
```json
{
"compilerOptions": {
"types": [
"yml-register/types",
],
},
}
```