Skip to content

Commit

Permalink
Add option parameter to parse, stringify method
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jul 23, 2014
1 parent 1ad932a commit 39beb4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Front-matter parser.

## API

### parse(str)
### parse(str, [options])

Parses YAML front-matter.
Parses YAML front-matter. See [js-yaml] for more info.

### stringify(obj)
### stringify(obj, [options])

Converts an object to YAML front-matter string.
Converts an object to YAML front-matter string. See [js-yaml] for more info.

### split(str)

Expand All @@ -24,4 +24,6 @@ Converts hard tabs to soft tabs.

## License

MIT
MIT

[js-yaml]: https://github.com/nodeca/js-yaml
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ var escapeYaml = exports.escape = function(str){
});
};

var parse = exports.parse = function(str){
var parse = exports.parse = function(str, options){
var splitData = split(str),
raw = splitData.data,
content = splitData.content;

if (!raw) return {_content: str};

try {
var data = yaml.load(escapeYaml(raw));
var data = yaml.load(escapeYaml(raw), options);

if (typeof data === 'object'){
data._content = content;
Expand Down Expand Up @@ -63,7 +63,7 @@ var formatDate = function(date){
return out;
};

exports.stringify = function(obj){
exports.stringify = function(obj, options){
var content = obj._content || '',
keys = Object.keys(obj);

Expand Down Expand Up @@ -93,7 +93,7 @@ exports.stringify = function(obj){

if (!Object.keys(data).length) return content;

var result = yaml.dump(data);
var result = yaml.dump(data, options);

if (dateKeys.length){
var date;
Expand Down

0 comments on commit 39beb4f

Please sign in to comment.