11/**
22 * @typedef {import('vfile').VFile } VFile
3- * @typedef {import('js-yaml').LoadOptions } LoadOptions
3+ * @typedef {import('yaml').ParseOptions } ParseOptions
4+ * @typedef {import('yaml').DocumentOptions } DocumentOptions
5+ * @typedef {import('yaml').SchemaOptions } SchemaOptions
6+ * @typedef {import('yaml').ToJSOptions } ToJsOptions
7+ * @typedef {ParseOptions & DocumentOptions & SchemaOptions & ToJsOptions } YamlOptions
48 *
5- * @typedef Options VFile matter options
6- * @property {boolean } [strip=false] Remove the YAML front matter from the file
7- * @property {Omit<LoadOptions, 'filename'> } [yaml] Options for the YAML parser
9+ * @typedef Options
10+ * Configuration (optional).
11+ * @property {boolean } [strip=false]
12+ * Remove the YAML front matter from the file.
13+ * @property {YamlOptions } [yaml]
14+ * Options for the YAML parser.
15+ * These are passed as `x` in `yaml.parse('', x)`, which is equivalent to
16+ * `ParseOptions & DocumentOptions & SchemaOptions & ToJsOptions`.
817 */
918
1019import buffer from 'is-buffer'
11- import { load } from 'js- yaml'
20+ import yaml from 'yaml'
1221
1322/**
14- * Parse the YAML front matter in a [ `vfile`](https://github.com/vfile/vfile) , and add it as `file.data.matter`.
23+ * Parse the YAML front matter in a `vfile`, and add it as `file.data.matter`.
1524 *
16- * If no matter is found in the file, nothing happens, except that `file.data.matter` is set to an empty object (`{}`).
25+ * If no matter is found in the file, nothing happens, except that
26+ * `file.data.matter` is set to an empty object (`{}`).
1727 *
1828 * @template {VFile} File
1929 * @param {File } file
@@ -31,10 +41,7 @@ export function matter(file, options = {}) {
3141 / ^ - - - (?: \r ? \n | \r ) (?: ( [ \s \S ] * ?) (?: \r ? \n | \r ) ) ? - - - (?: \r ? \n | \r | $ ) / . exec ( doc )
3242
3343 if ( match ) {
34- file . data . matter = load (
35- match [ 1 ] ,
36- Object . assign ( { } , yamlOptions , { filename : file . path } )
37- )
44+ file . data . matter = yaml . parse ( match [ 1 ] , yamlOptions )
3845
3946 if ( strip ) {
4047 doc = doc . slice ( match [ 0 ] . length )
0 commit comments