diff --git a/index.js b/index.js index ff7eebb..b93fce7 100644 --- a/index.js +++ b/index.js @@ -5,21 +5,21 @@ var yamlParse = require('js-yaml').safeLoad var parse = require('remark-frontmatter/lib/parse') var matters = require('remark-frontmatter/lib/matters') -module.exports = frontmatter +module.exports = matter var matterParse = parse(matters('yaml')[0])[1] -function frontmatter(file, options) { +function matter(file, options) { var strip = (options || {}).strip var data = file.data var doc = String(file) var result = matterParse(mockEat, doc) var offset - data.frontmatter = {} + data.matter = {} if (result) { - data.frontmatter = yamlParse(result.value, {filename: file.path}) + data.matter = yamlParse(result.value, {filename: file.path}) if (strip) { offset = result.length diff --git a/package.json b/package.json index 2ed547f..7546989 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,18 @@ { - "name": "vfile-frontmatter", + "name": "vfile-matter", "version": "0.0.0", - "description": "Parse the YAML frontmatter in a vfile", + "description": "Parse the YAML front matter in a vfile", "license": "MIT", "keywords": [ "virtual", "file", "vfile", "frontmatter", + "matter", "yaml" ], - "repository": "vfile/vfile-frontmatter", - "bugs": "https://github.com/vfile/vfile-frontmatter/issues", + "repository": "vfile/vfile-matter", + "bugs": "https://github.com/vfile/vfile-matter/issues", "funding": { "type": "opencollective", "url": "https://opencollective.com/unified" diff --git a/readme.md b/readme.md index fb2049f..db84839 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# vfile-frontmatter +# vfile-matter [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] @@ -8,14 +8,14 @@ [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] -Parse the YAML frontmatter in a [`vfile`][vfile]. +Parse the YAML front matter in a [`vfile`][vfile]. ## Install [npm][]: ```sh -npm install vfile-frontmatter +npm install vfile-matter ``` ## Use @@ -33,11 +33,11 @@ And our script, `example.js`, looks like so: ```js var vfile = require('to-vfile') -var frontmatter = require('vfile-frontmatter') +var matter = require('vfile-matter') var file = vfile.readSync('example.html') -frontmatter(file, {strip: true}) +matter(file, {strip: true}) console.log(file.data) console.log(String(file)) @@ -46,7 +46,7 @@ console.log(String(file)) Now, running our script (`node example`) yields: ```js -{ frontmatter: { title: 'Hello, world!' } } +{ matter: { title: 'Hello, world!' } } ``` ```html @@ -55,20 +55,20 @@ Now, running our script (`node example`) yields: ## API -### `frontmatter(file[, options])` +### `matter(file[, options])` -Parse the YAML frontmatter in a [`vfile`][vfile], and add it as -`file.data.frontmatter`. +Parse the YAML front matter in a [`vfile`][vfile], and add it as +`file.data.matter`. -If no frontmatter is found in the file, nothing happens, except that -`file.data.frontmatter` is set to an empty object (`{}`). +If no matter is found in the file, nothing happens, except that +`file.data.matter` is set to an empty object (`{}`). ###### Parameters * `file` ([`VFile`][vfile]) — Virtual file * `options.strip` (`boolean`, default: `false`) - — Remove the YAML frontmatter from the file + — Remove the YAML front matter from the file ###### Returns @@ -90,21 +90,21 @@ abide by its terms. -[build-badge]: https://img.shields.io/travis/vfile/vfile-frontmatter.svg +[build-badge]: https://img.shields.io/travis/vfile/vfile-matter.svg -[build]: https://travis-ci.org/vfile/vfile-frontmatter +[build]: https://travis-ci.org/vfile/vfile-matter -[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-frontmatter.svg +[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-matter.svg -[coverage]: https://codecov.io/github/vfile/vfile-frontmatter +[coverage]: https://codecov.io/github/vfile/vfile-matter -[downloads-badge]: https://img.shields.io/npm/dm/vfile-frontmatter.svg +[downloads-badge]: https://img.shields.io/npm/dm/vfile-matter.svg -[downloads]: https://www.npmjs.com/package/vfile-frontmatter +[downloads]: https://www.npmjs.com/package/vfile-matter -[size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-frontmatter.svg +[size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-matter.svg -[size]: https://bundlephobia.com/result?p=vfile-frontmatter +[size]: https://bundlephobia.com/result?p=vfile-matter [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg diff --git a/test.js b/test.js index fd5a540..6f86ddf 100644 --- a/test.js +++ b/test.js @@ -3,39 +3,39 @@ var test = require('tape') var buffer = require('is-buffer') var vfile = require('to-vfile') -var frontmatter = require('.') +var matter = require('.') -var matter = '---\nkey: value\nlist:\n - 1\n - 2\n---' +var yaml = '---\nkey: value\nlist:\n - 1\n - 2\n---' var doc = 'Here is a document\nMore of the document\nOther lines\n' -var both = matter + '\n' + doc +var both = yaml + '\n' + doc -test('vfile-frontmatter', function(t) { +test('vfile-matter', function(t) { var file = vfile({contents: both}) - t.equal(frontmatter(file), file, 'should return the given file') + t.equal(matter(file), file, 'should return the given file') t.deepEqual( file.data, - {frontmatter: {key: 'value', list: [1, 2]}}, + {matter: {key: 'value', list: [1, 2]}}, 'should add data' ) - file = frontmatter(vfile({contents: doc})) - t.deepEqual(file.data, {frontmatter: {}}, 'should support no frontmatter') + file = matter(vfile({contents: doc})) + t.deepEqual(file.data, {matter: {}}, 'should support no matter') - file = frontmatter(vfile({contents: both}), {strip: true}) - t.deepEqual(String(file), doc, 'should strip frontmatter') + file = matter(vfile({contents: both}), {strip: true}) + t.deepEqual(String(file), doc, 'should strip matter') - file = frontmatter(vfile({contents: matter}), {strip: true}) - t.deepEqual(String(file), '', 'should strip frontmatter completely') + file = matter(vfile({contents: yaml}), {strip: true}) + t.deepEqual(String(file), '', 'should strip matter completely') - file = frontmatter(vfile({contents: doc}), {strip: true}) - t.deepEqual(String(file), doc, 'should support no frontmatter w/ strip') + file = matter(vfile({contents: doc}), {strip: true}) + t.deepEqual(String(file), doc, 'should support no matter w/ strip') - file = frontmatter(vfile({contents: Buffer.from(both)}), {strip: true}) + file = matter(vfile({contents: Buffer.from(both)}), {strip: true}) t.ok(buffer(file.contents), 'should supporting buffers') - file = frontmatter(vfile(), {strip: true}) + file = matter(vfile(), {strip: true}) t.ok(file.contents === undefined, 'should supporting empties') t.end()