gray-matter
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -163,4 +163,4 @@ # {%= name %} {%= badge("fury") %} | ||
``` | ||
front-matter.js x 209 ops/sec ±2.75% (78 runs sampled) | ||
gray-matter.js x 3,792 ops/sec ±0.81% (93 runs sampled) | ||
front-matter.js x 271 ops/sec ±2.68% (80 runs sampled) | ||
gray-matter.js x 4,294 ops/sec ±0.86% (91 runs sampled) | ||
``` | ||
@@ -167,0 +167,0 @@ |
@@ -12,6 +12,9 @@ 'use strict'; | ||
fixtures = fixtures || 'fixtures/{complex,empty,matter,no-{matter,content}}.js'; | ||
// fixtures = fixtures || 'fixtures/no-matter.js'; | ||
code = code || 'code/{gray,front}-matter.js'; | ||
// fixtures = fixtures || 'fixtures/{complex,empty,matter,no-{matter,content}}.js'; | ||
// code = code || 'code/{gray,front}-matter.js'; | ||
// blog | ||
fixtures = fixtures || 'bulk/fixtures/*.js'; | ||
code = code || 'bulk/code/*.js'; | ||
if (dryrun) { | ||
@@ -18,0 +21,0 @@ require('./support')({ |
@@ -34,2 +34,3 @@ 'use strict'; | ||
res[lib][filename] = actual; | ||
console.log(name(fixture, lib), actual); | ||
@@ -45,2 +46,3 @@ }); | ||
fs.writeFileSync(filepath, util.inspect(res, null, 10)); | ||
@@ -47,0 +49,0 @@ }); |
@@ -55,2 +55,3 @@ 'use strict'; | ||
var alen = a.length; | ||
var len = str.length; | ||
@@ -61,3 +62,3 @@ // find the index of the next delimiter before | ||
if (end === -1) { | ||
return res; | ||
end = len; | ||
} | ||
@@ -64,0 +65,0 @@ |
@@ -46,3 +46,3 @@ /** | ||
if (opts.strict) { | ||
throw new Error(msg('js-yaml', err)); | ||
throw new SyntaxError(msg('js-yaml', err)); | ||
} else { | ||
@@ -69,3 +69,3 @@ return {}; | ||
if (opts.strict) { | ||
throw new Error(msg('JSON', err)); | ||
throw new SyntaxError(msg('JSON', err)); | ||
} else { | ||
@@ -115,3 +115,3 @@ return {}; | ||
} catch (err) { | ||
throw new Error(msg('javascript', err)); | ||
throw new SyntaxError(msg('javascript', err)); | ||
} | ||
@@ -157,3 +157,3 @@ return {}; | ||
} catch (err) { | ||
throw new Error(msg('coffee-script', err)); | ||
throw new SyntaxError(msg('coffee-script', err)); | ||
} | ||
@@ -194,3 +194,3 @@ } else { | ||
if (opts.strict) { | ||
throw new Error(msg('TOML', err)); | ||
throw new SyntaxError(msg('TOML', err)); | ||
} else { | ||
@@ -197,0 +197,0 @@ return {}; |
{ | ||
"name": "gray-matter", | ||
"description": "Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML front matter by default, but also has support for YAML, JSON, TOML or Coffee Front-Matter, with options to set custom delimiters.", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Jon Schlinkert", |
@@ -72,3 +72,3 @@ # gray-matter [![NPM version](https://badge.fury.io/js/gray-matter.svg)](http://badge.fury.io/js/gray-matter) | ||
### [.read](index.js#L117) | ||
### [.read](index.js#L118) | ||
@@ -85,3 +85,3 @@ Read a file and parse front matter. Returns the same object as `matter()`. | ||
### [.stringify](index.js#L148) | ||
### [.stringify](index.js#L149) | ||
@@ -222,4 +222,4 @@ Stringify an object to front-matter-formatted YAML, and concatenate it to the given string. | ||
``` | ||
front-matter.js x 209 ops/sec ±2.75% (78 runs sampled) | ||
gray-matter.js x 3,792 ops/sec ±0.81% (93 runs sampled) | ||
front-matter.js x 271 ops/sec ±2.68% (80 runs sampled) | ||
gray-matter.js x 4,294 ops/sec ±0.86% (91 runs sampled) | ||
``` | ||
@@ -226,0 +226,0 @@ |
@@ -72,3 +72,11 @@ /*! | ||
}); | ||
it('should correctly parse a string that only has an opening delimiter.', function () { | ||
var fixture = '---\nname: "troublesome --- value"\n'; | ||
var actual = matter(fixture); | ||
actual.should.have.property('data', {name: 'troublesome --- value'}); | ||
actual.should.have.property('content', ''); | ||
actual.should.have.property('orig', '---\nname: "troublesome --- value"\n'); | ||
}); | ||
}); | ||
@@ -28,3 +28,14 @@ /*! | ||
}); | ||
it('should use custom delimiters.', function () { | ||
var res = matter.stringify('Name: {{author.name}}', pkg.author, {delims: '~~~'}); | ||
res.should.equal([ | ||
'~~~', | ||
'name: Jon Schlinkert', | ||
'url: "https://github.com/jonschlinkert"', | ||
'~~~', | ||
'Name: {{author.name}}\n' | ||
].join('\n')); | ||
}); | ||
}); | ||
@@ -16,3 +16,3 @@ /*! | ||
it('should parse toml front matter.', function () { | ||
var actual = matter.read('./test/fixtures/lang-toml.md', { | ||
var actual = matter('---\ntitle = "TOML"\ndescription = "Front matter"\ncategories = "front matter toml"\n---\n\n# This file has toml front matter!\n', { | ||
lang: 'toml' | ||
@@ -27,3 +27,3 @@ }); | ||
it('should auto-detect TOML as the language.', function () { | ||
var actual = matter.read('./test/fixtures/autodetect-toml.md'); | ||
var actual = matter('---toml\ntitle = "autodetect-TOML"\n[props]\nuser = "jonschlinkert"\n---\nContent\n'); | ||
actual.data.title.should.equal('autodetect-TOML'); | ||
@@ -34,3 +34,15 @@ actual.should.have.property('data'); | ||
}); | ||
it('should NOT throw on TOML syntax errors when `strict` is NOT defined.', function () { | ||
(function () { | ||
matter('---toml\n[props\nuser = "jonschlinkert"\n---\nContent\n'); | ||
}).should.not.throw(); | ||
}); | ||
it.skip('should throw on TOML syntax errors when `strict` IS defined.', function () { | ||
(function () { | ||
matter('---toml\n[props\nuser = "jonschlinkert"\n---\nContent\n', {strict: true}); | ||
}).should.throw('gray-matter parser [TOML]: SyntaxError: Expected "]" but "\n" found.'); | ||
}); | ||
}); | ||
@@ -38,2 +38,10 @@ /*! | ||
}); | ||
it('should use safeLoad when specified.', function () { | ||
var fixture = '---\nabc: xyz\nversion: 2\n---\n\n<span class="alert alert-info">This is an alert</span>\n'; | ||
var actual = matter(fixture, {safeLoad: true}); | ||
actual.should.have.property('data', {abc: 'xyz', version: 2}); | ||
actual.should.have.property('content', '\n\n<span class="alert alert-info">This is an alert</span>\n'); | ||
actual.should.have.property('orig'); | ||
}); | ||
}); |
88441
1861
77