Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 2, 2019
1 parent 87e7e5b commit 042d990
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
40 changes: 20 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# vfile-frontmatter
# vfile-matter

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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

Expand All @@ -90,21 +90,21 @@ abide by its terms.

<!-- Definitions -->

[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

Expand Down
32 changes: 16 additions & 16 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 042d990

Please sign in to comment.