Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gray-matter

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gray-matter - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

1

index.js

@@ -47,3 +47,2 @@ 'use strict';

}
return {

@@ -50,0 +49,0 @@ orig: o.orig,

2

package.json
{
"name": "gray-matter",
"description": "A simple to use and extend front matter library. Supports parsing and extracting YAML, JSON, TOML or Coffee Front-Matter, with options to set custom delimiters.",
"version": "0.6.1",
"version": "0.6.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Jon Schlinkert",

@@ -5,12 +5,4 @@ # gray-matter [![NPM version](https://badge.fury.io/js/gray-matter.svg)](http://badge.fury.io/js/gray-matter)

Used by [assemble](https://github.com/assemble/assemble), [verb](https://github.com/assemble/verb), and thousands of other projects!
Used by [assemble](https://github.com/assemble/assemble), [verb](https://github.com/assemble/verb), and many other projects!
**v0.5.0 has breaking changes!**
* YAML is now parsed using the `.safeLoad()` method from [js-yaml](http://github.com/nodeca/js-yaml).
* To parse coffee, CSON or javascript front matter, you must set `options.eval` to true.
* `stringify()` has been renamed to `toJSON()`
* `stringifyYAML()` has been renamed to `toYAML()`
## Highlights

@@ -28,2 +20,3 @@

#### TOC

@@ -33,3 +26,3 @@ <!-- toc -->

## Install
### Install with [npm](npmjs.org)
## Install with [npm](npmjs.org)

@@ -54,107 +47,111 @@ ```bash

## API
## [matter](index.js#L47)
Expects a string and returns and object:
* `str` **{String}**: The string to parse
* `options` **{Object}**: Object of options
* `returns` **{Object}** `file`: Object with the following properties.
```js
matter('---\ntitle: Blog\n---\nThis is content.');
```
## Options
> All methods will accept an options object to be passed as a second parameter
Returns:
## options.eval
Type: `Boolean`
```json
{
"data": {"title": "Blog"},
"content": "This is content.",
"original": "---\ntitle: Blog\n---\nThis is content."
}
```
Default: `false`
## [.read](index.js#L109)
Evaluate coffee-script, CSON or JavaScript in front-matter. If you aren't aware of the dangers, google is your friend.
Read a file then pass the string and `options` to `matter()` for parsing:
## options.lang
Type: `String`
* `filepath` **{String}**
* `options` **{Object}**
* `returns` **{Object}** `file`: Same object as `matter()`, with an additional `path` property
Default: `yaml`
```js
matter.read('file.md');
```
The parser to use on the extracted front matter. Valid options include:
Returns something like:
* `yaml`
* `json`
* `coffee`
* `cson`
* `toml`
* `js`|`javascript`
```json
{
"data": {"title": "Blog"},
"content": "This is content.",
"original": "---\ntitle: Blog\n---\nThis is content."
}
```
## options.delims
Type: `Object`
## [.exists](index.js#L130)
Default: `{delims: ['---', '---']}`
Return `true` if front-matter exists.
Open and close delimiters can be passed in as an array of strings. Example:
* `str` **{String}**: The string to parse
* `options` **{Object}**: Options to pass to `matter()`
* `returns` **{Boolean}** `true`: or `false`
```js
matter.exists(str);
matter.read('file.md', {delims: ['~~~', '~~~']});
```
## [.extend](index.js#L150)
Extend and stringify **YAML** front matter. Takes an object as the second parameter, and returns either the extended, stringified object (YAML), or if no front matter is found an empty string is returned.
## Examples
* `str` **{String}**: The string to parse
* `obj` **{Object}**: The object to use to extend the front matter.
* `returns` **{String}**: String with extended YAML front matter.
Let's say our page, `foo.html` contains
```js
matter.extend(str, obj);
```html
---
title: YAML Front matter
description: This is a page
---
<h1>{{title}}</h1>
```
## [.reconstruct](index.js#L175)
then running the following in the command line:
A convenience wrapper around the `matter()` and `matter.extend()` methods.
```js
console.log(matter('foo.html'));
```
returns
* `str` **{String}**: The string to parse
* `obj` **{Object}**: The object to use to extend the front matter.
* `returns` **{String}**: Original string with extended front matter.
```json
{
"data": {
"title": "YAML Front matter",
"description": "This is a page"
},
"content": "<h1>{{title}}</h1>",
"original": "---\ntitle: YAML Front matter\n---\n<h1>{{title}}</h1>"
}
```
and
Extends YAML front matter, then re-assembles front matter with
the content of the file.
```js
matter.reconstruct(str, obj);
console.log(matter('foo.html').data);
```
returns
## [.toJSON](index.js#L190)
* `str` **{String}**
* `options` **{Object}**
* `returns` **{Object}**: Parsed front matter as JSON.
```json
{"title": "YAML Front matter", "description": "This is a page"}
```
Convenience wrapper around the `matter(str).data()` method.
## [.toYAML](index.js#L203)
## Why?
* `str` **{String}**
* `options` **{Object}**
* `returns` **{String}**: Stringified YAML.
> Why another YAML Front Matter library?
Stringify parsed front matter back to YAML.
Because other libraries we tried failed to meet our requirements with [Assemble](http://assemble.io). Some most of the libraries met most of the requirements, but _none had all of them_. Here are the most important:
* Be usable, if not simple
* Allow custom delimiters
* Use a dependable and well-supported library for parsing YAML and other languages
* Don't fail when no content exists
* Don't fail when no front matter exists
* Have no problem reading YAML files directly
* Have no problem with complex content, including fenced code blocks that contain examples of YAML front matter. Other parsers fail on this.
* Should return an object that contains the parsed YAML front matter and content, as well as the "original" content.
## Options
__async_helper_id__wnyS0VRoq9lszTfEFhYyEHJkzUbnN0NnP7jzbFY7lk__
## Changelog
**v0.6.0 breaking changes!**
**v0.5.0 breaking changes!**
* YAML is now parsed using the `.safeLoad()` method from [js-yaml](http://github.com/nodeca/js-yaml).
* To parse coffee, CSON or javascript front matter, you must set `options.eval` to true.
* `stringify()` has been renamed to `toJSON()`
* `stringifyYAML()` has been renamed to `toYAML()`
## Authors

@@ -173,3 +170,3 @@

_This file was generated by [verb](https://github.com/jonschlinkert/verb) on November 11, 2014._
_This file was generated by [verb](https://github.com/assemble/verb) on December 04, 2014._

@@ -179,2 +176,2 @@

[coffee-script]: https://github.com/jashkenas/coffeescript
[toml-node]: https://github.com/BinaryMuse/toml-node
[toml-node]: https://github.com/BinaryMuse/toml-node

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc