Skip to content

Commit da329cd

Browse files
isempty (#66)
- adds support for empty front matter - upgraded to es6 - update docs closes #65
1 parent 1eb7d19 commit da329cd

37 files changed

+487
-367
lines changed

.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
{
2+
"extends": [
3+
"eslint:recommended",
4+
"./package.json"
5+
],
6+
27
"env": {
38
"browser": false,
49
"es6": true,
510
"node": true,
611
"mocha": true
712
},
813

14+
"parserOptions":{
15+
"ecmaVersion": 9,
16+
"sourceType": "module",
17+
"ecmaFeatures": {
18+
"modules": true,
19+
"experimentalObjectRestSpread": true
20+
}
21+
},
22+
923
"globals": {
1024
"document": false,
1125
"navigator": false,

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# always ignore files
22
*.DS_Store
33
.idea
4+
.vscode
45
*.sublime-*
56

67
# test related, or directories generated by tests

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ os:
55
language: node_js
66
node_js:
77
- node
8+
- '9'
89
- '8'
910
- '7'
1011
- '6'
11-
- '5'
12-
- '4'
13-
- '0.12'
14-
- '0.10'

.verb.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Please see the [changelog](CHANGELOG.md) to learn about breaking changes that we
1010
Add the HTML in the following example to `example.html`, then add the following code to `example.js` and run `$ node example` (without the `$`):
1111

1212
```js
13-
var fs = require('fs');
14-
var matter = require('gray-matter');
15-
var str = fs.readFileSync('example.html', 'utf8');
13+
const fs = require('fs');
14+
const matter = require('gray-matter');
15+
const str = fs.readFileSync('example.html', 'utf8');
1616
console.log(matter(str));
1717
```
1818

@@ -72,10 +72,10 @@ Some libraries met most of the requirements, but _none met all of them_.
7272
* 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.
7373
* Support stringifying back to front-matter. This is useful for linting, updating properties, etc.
7474
* Allow custom delimiters, when it's necessary for avoiding delimiter collision.
75-
* Should return an object with at least these three properties (for debugging):
75+
* Should return an object with at least these three properties:
7676
- `data`: the parsed YAML front matter, as a JSON object
7777
- `content`: the contents as a string, without the front matter
78-
- `orig`: the "original" content
78+
- `orig`: the "original" content (for debugging)
7979

8080
</details>
8181

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

8787
```js
88-
var matter = require('gray-matter');
88+
const matter = require('gray-matter');
8989
```
9090

9191
Or with [typescript](https://www.typescriptlang.org)
@@ -126,6 +126,7 @@ gray-matter returns a `file` object with the following properties.
126126
- `file.data` **{Object}**: the object created by parsing front-matter
127127
- `file.content` **{String}**: the input string, with `matter` stripped
128128
- `file.excerpt` **{String}**: an excerpt, if [defined on the options](#optionsexcerpt)
129+
- `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.
129130

130131
**Non-enumerable**
131132

@@ -134,7 +135,7 @@ In addition, the following non-enumberable properties are added to the object to
134135
- `file.orig` **{Buffer}**: the original input string (or buffer)
135136
- `file.language` **{String}**: the front-matter language that was parsed. `yaml` is the default
136137
- `file.matter` **{String}**: the _raw_, un-parsed front-matter string
137-
- `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`.
138+
- `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`.
138139

139140

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

161+
**Links to examples**
162+
160163
{%= examples() %}
161164

162165

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

181184
```js
182-
var file = matter([
183-
'---',
184-
'foo: bar',
185-
'---',
186-
'This is an excerpt.',
187-
'---',
188-
'This is content'
189-
].join('\n'), {excerpt: true});
185+
const str = '---\nfoo: bar\n---\nThis is an excerpt.\n---\nThis is content';
186+
const file = matter(str, { excerpt: true });
190187
```
191188

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

212-
var file = matter([
209+
const file = matter([
213210
'---',
214211
'foo: bar',
215212
'---',
@@ -282,13 +279,13 @@ Engines may either be an object with `parse` and (optionally) `stringify` method
282279
**Examples**
283280

284281
```js
285-
var toml = require('toml');
282+
const toml = require('toml');
286283

287284
/**
288285
* defined as a function
289286
*/
290287

291-
var file = matter(str, {
288+
const file = matter(str, {
292289
engines: {
293290
toml: toml.parse.bind(toml),
294291
}
@@ -298,7 +295,7 @@ var file = matter(str, {
298295
* Or as an object
299296
*/
300297

301-
var file = matter(str, {
298+
const file = matter(str, {
302299
engines: {
303300
toml: {
304301
parse: toml.parse.bind(toml),

CHANGELOG.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# Release history
22

3-
## Unreleased
3+
## 4.0.0 - 2018-04-01
4+
5+
### Breaking changes
6+
7+
- Now requires node v4 or higher.
8+
49

510
## 3.0.0 - 2017-06-30
11+
612
### Breaking changes
7-
* `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.
13+
14+
- `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.
815

916
### Added
10-
* Support for [excerpts](README.md#optionsexcerpt).
11-
* The returned object now has non-enumerable `matter` and `stringify` properties.
17+
18+
- Support for [excerpts](README.md#optionsexcerpt).
19+
- The returned object now has non-enumerable `matter` and `stringify` properties.
1220

1321
### Changed
14-
* Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
15-
* `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)
22+
23+
- Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
24+
- `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

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

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

0 commit comments

Comments
 (0)