Skip to content

Commit

Permalink
isempty (#66)
Browse files Browse the repository at this point in the history
- adds support for empty front matter
- upgraded to es6
- update docs

closes #65
  • Loading branch information
jonschlinkert committed Apr 2, 2018
1 parent 1eb7d19 commit da329cd
Show file tree
Hide file tree
Showing 37 changed files with 487 additions and 367 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.json
@@ -1,11 +1,25 @@
{
"extends": [
"eslint:recommended",
"./package.json"
],

"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},

"parserOptions":{
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},

"globals": {
"document": false,
"navigator": false,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
# always ignore files
*.DS_Store
.idea
.vscode
*.sublime-*

# test related, or directories generated by tests
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -5,10 +5,7 @@ os:
language: node_js
node_js:
- node
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
35 changes: 16 additions & 19 deletions .verb.md
Expand Up @@ -10,9 +10,9 @@ Please see the [changelog](CHANGELOG.md) to learn about breaking changes that we
Add the HTML in the following example to `example.html`, then add the following code to `example.js` and run `$ node example` (without the `$`):

```js
var fs = require('fs');
var matter = require('gray-matter');
var str = fs.readFileSync('example.html', 'utf8');
const fs = require('fs');
const matter = require('gray-matter');
const str = fs.readFileSync('example.html', 'utf8');
console.log(matter(str));
```

Expand Down Expand Up @@ -72,10 +72,10 @@ Some libraries met most of the requirements, but _none met all of them_.
* Have no problem with complex content, including **non-front-matter** fenced code blocks that contain examples of YAML front matter. Other parsers fail on this.
* Support stringifying back to front-matter. This is useful for linting, updating properties, etc.
* Allow custom delimiters, when it's necessary for avoiding delimiter collision.
* Should return an object with at least these three properties (for debugging):
* Should return an object with at least these three properties:
- `data`: the parsed YAML front matter, as a JSON object
- `content`: the contents as a string, without the front matter
- `orig`: the "original" content
- `orig`: the "original" content (for debugging)

</details>

Expand All @@ -85,7 +85,7 @@ Some libraries met most of the requirements, but _none met all of them_.
Using Node's `require()` system:

```js
var matter = require('gray-matter');
const matter = require('gray-matter');
```

Or with [typescript](https://www.typescriptlang.org)
Expand Down Expand Up @@ -126,6 +126,7 @@ gray-matter returns a `file` object with the following properties.
- `file.data` **{Object}**: the object created by parsing front-matter
- `file.content` **{String}**: the input string, with `matter` stripped
- `file.excerpt` **{String}**: an excerpt, if [defined on the options](#optionsexcerpt)
- `file.empty` **{String}**: when the front-matter is "empty" (either all whitespace, nothing at all, or just comments and no data), the original string is set on this property. See [#65](https://github.com/jonschlinkert/gray-matter/issues/65) for details regarding use case.

**Non-enumerable**

Expand All @@ -134,7 +135,7 @@ In addition, the following non-enumberable properties are added to the object to
- `file.orig` **{Buffer}**: the original input string (or buffer)
- `file.language` **{String}**: the front-matter language that was parsed. `yaml` is the default
- `file.matter` **{String}**: the _raw_, un-parsed front-matter string
- `file.stringify` **{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and appending it to `file.content`.
- `file.stringify` **{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and prepending it to `file.content`.


## Run the examples
Expand All @@ -157,6 +158,8 @@ Then run any of the [examples](./examples) to see how gray-matter works:
$ node examples/<example_name>
```

**Links to examples**

{%= examples() %}


Expand All @@ -179,14 +182,8 @@ If set to `excerpt: true`, it will look for the frontmatter delimiter, `---` by
**Example**

```js
var file = matter([
'---',
'foo: bar',
'---',
'This is an excerpt.',
'---',
'This is content'
].join('\n'), {excerpt: true});
const str = '---\nfoo: bar\n---\nThis is an excerpt.\n---\nThis is content';
const file = matter(str, { excerpt: true });
```

Results in:
Expand All @@ -209,7 +206,7 @@ function firstFourLines(file, options) {
file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}

var file = matter([
const file = matter([
'---',
'foo: bar',
'---',
Expand Down Expand Up @@ -282,13 +279,13 @@ Engines may either be an object with `parse` and (optionally) `stringify` method
**Examples**

```js
var toml = require('toml');
const toml = require('toml');

/**
* defined as a function
*/

var file = matter(str, {
const file = matter(str, {
engines: {
toml: toml.parse.bind(toml),
}
Expand All @@ -298,7 +295,7 @@ var file = matter(str, {
* Or as an object
*/

var file = matter(str, {
const file = matter(str, {
engines: {
toml: {
parse: toml.parse.bind(toml),
Expand Down
21 changes: 15 additions & 6 deletions CHANGELOG.md
@@ -1,15 +1,24 @@
# Release history

## Unreleased
## 4.0.0 - 2018-04-01

### Breaking changes

- Now requires node v4 or higher.


## 3.0.0 - 2017-06-30

### Breaking changes
* `toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.

- `toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.

### Added
* Support for [excerpts](README.md#optionsexcerpt).
* The returned object now has non-enumerable `matter` and `stringify` properties.

- Support for [excerpts](README.md#optionsexcerpt).
- The returned object now has non-enumerable `matter` and `stringify` properties.

### Changed
* Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
* `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)

- Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
- `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2017, Jon Schlinkert.
Copyright (c) 2014-2018, Jon Schlinkert.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit da329cd

Please sign in to comment.