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

gray-matter

Package Overview
Dependencies
Maintainers
1
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.2.1 to 0.2.3

test/fixtures/autodetect-json.md

2

bower.json
{
"name": "matter",
"version": "0.2.1",
"version": "0.2.3",
"main": [

@@ -5,0 +5,0 @@ "index.js"

@@ -20,3 +20,7 @@ /**

var re = new RegExp('^(?:' + delim + ')\s*(.+)\n');
return content.match(re)[1].replace(/^\s+/, '');
try {
return content.match(re)[1].replace(/^\s+/, '');
} catch(e) {
return 'yaml';
}
};
{
"name": "gray-matter",
"description": "A simple to use YAML, JSON or Coffee Front-Matter parsing and extraction library, with options to set custom delimiters.",
"version": "0.2.1",
"version": "0.2.3",
"author": {

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

--- coffee
user = 'jonschlinkert'
data =
user: 'jonschlinkert'
---
Content

@@ -17,17 +17,35 @@ /**

// Local libs
var matter = require('../');
var expected = {context: {foo: 'bar'}, content: '', original: '---\nfoo: bar\n---'};
/**
* Expected
*/
var expected = {
context: {
foo: 'bar'
},
content: '',
original: '---\nfoo: bar\n---'
};
var complexExpected = {
context: {foo: 'bar', version: 2},
context: {
foo: 'bar',
version: 2
},
content: '\n\n<span class="alert alert-info">This is an alert</span>\n',
original: '---\nfoo: bar\nversion: 2\n---\n\n<span class="alert alert-info">This is an alert</span>\n'
};
var customDelims = {
context: {"foo": 'bar', "version": 2},
context: {
foo: 'bar',
version: 2
},
content: '\n\n<span class="alert alert-info">This is an alert</span>\n',
original: '~~~\nfoo: bar\nversion: 2\n~~~\n\n<span class="alert alert-info">This is an alert</span>\n'
};
var empty = {

@@ -46,7 +64,11 @@ context: {},

describe('Read from strings:', function() {
/**
* Tests
*/
describe('Read from strings:', function () {
var matterOnly = '---\nfoo: bar\n---';
var matterAndContent = '---\nfoo: bar\nversion: 2\n---\n\n<span class="alert alert-info">This is an alert</span>\n';
it('should extract YAML front matter directly from a string when with "read: false" is defined', function(done) {
it('should extract YAML front matter directly from a string when with "read: false" is defined', function (done) {
var actual = matter(matterOnly);

@@ -56,4 +78,3 @@ expect(actual).to.deep.equal(expected);

});
it('should extract YAML front matter and content directly from a string when with "read: false" is defined', function(done) {
it('should extract YAML front matter and content directly from a string when with "read: false" is defined', function (done) {
var actual = matter(matterAndContent);

@@ -66,4 +87,5 @@ expect(actual).to.deep.equal(complexExpected);

describe('Read from file system:', function() {
it('should extract YAML front matter from files with content.', function(done) {
describe('Read from file system:', function () {
it('should extract YAML front matter from files with content.', function (done) {
var actual = matter.read('./test/fixtures/alpha.hbs');

@@ -73,4 +95,3 @@ expect(actual).to.deep.equal(complexExpected);

});
it('should have no problem with complex content.', function(done) {
it('should parse complex YAML front matter.', function (done) {
var actual = matter.read('./test/fixtures/complex.md');

@@ -84,5 +105,7 @@ var expected = file.readJSONSync('./test/expected/complex.json');

describe('Use custom delimiters:', function() {
it('should use custom delimiters.', function(done) {
var actual = matter.read('./test/fixtures/custom-delims.md', {delims: ['~~~', '~~~']});
describe('Use custom delimiters:', function () {
it('should use custom delimiters.', function (done) {
var actual = matter.read('./test/fixtures/custom-delims.md', {
delims: ['~~~', '~~~']
});
expect(actual).to.deep.equal(customDelims);

@@ -94,4 +117,3 @@ done();

describe('Parse JSON:', function() {
describe('Parse JSON:', function () {
var expected = {

@@ -106,24 +128,82 @@ context: {

it('should parse JSON front matter.', function(done) {
var actual = matter.read('./test/fixtures/json.md', {lang: 'json'});
it('should parse JSON front matter.', function (done) {
var actual = matter.read('./test/fixtures/json.md', {
lang: 'json'
});
expect(actual).to.deep.equal(expected);
done();
});
it('should parse JSON front matter with custom delimiters.', function(done) {
it('should parse JSON front matter with custom delimiters.', function (done) {
expected.original = ";;;\n{\n \"title\": \"JSON\",\n \"description\": \"Front Matter\"\n}\n;;;\n\n# This page has JSON front matter!";
var actual = matter.read('./test/fixtures/json-semi-colons.md', {lang: 'json', delims: [';;;', ';;;']});
var actual = matter.read('./test/fixtures/json-semi-colons.md', {
lang: 'json',
delims: [';;;', ';;;']
});
expect(actual).to.deep.equal(expected);
done();
});
});
it('should autodetect language and parse JSON front matter.', function(done) {
describe('autodetect language', function () {
var expected = {
context: {
title: "JSON",
description: "Front Matter"
},
content: "\n\n# This page has JSON front matter!",
original: "---\n{\n \"title\": \"JSON\",\n \"description\": \"Front Matter\"\n}\n---\n\n# This page has JSON front matter!"
};
it('should detect language without a language defined.', function (done) {
expected.original = ";;; json\n{\n \"title\": \"JSON\",\n \"description\": \"Front Matter\"\n}\n;;;\n\n# This page has JSON front matter!";
var actual = matter.read('./test/fixtures/json-autodetect.md', {autodetect: 'true', delims: [';;;', ';;;']});
var actual = matter.read('./test/fixtures/autodetect-json.md', {
autodetect: true,
delims: [';;;', ';;;']
});
expect(actual).to.deep.equal(expected);
done();
});
it('should detect CoffeeScript as the language.', function (done) {
var actual = matter.read('./test/fixtures/autodetect.md', {
autodetect: true
});
var expected = {
context: {user: "jonschlinkert"},
content: "\nContent",
original: "--- coffee\ndata =\n user: 'jonschlinkert'\n---\nContent"
};
expect(actual).to.deep.equal(expected);
done();
});
it('should detect YAML as the language, although no language is defined after the first fence.', function (done) {
var actual = matter.read('./test/fixtures/autodetect-no-lang.md', {
autodetect: true
});
var expected = {
context: {user: "jonschlinkert"},
content: "\nContent",
original: "---\nuser: jonschlinkert\n---\nContent"
};
expect(actual).to.deep.equal(expected);
done();
});
it('should detect YAML as the language.', function (done) {
var actual = matter.read('./test/fixtures/autodetect-yaml.md', {
autodetect: true
});
var expected = {
context: {user: "jonschlinkert"},
content: "\nContent",
original: "---yaml\nuser: jonschlinkert\n---\nContent"
};
expect(actual).to.deep.equal(expected);
done();
});
});
describe('Parse coffee:', function() {
describe('Parse coffee:', function () {
var expected = {

@@ -139,9 +219,13 @@ context: {

it('should parse coffee front matter.', function(done) {
var actual = matter.read('./test/fixtures/coffee.md', {lang: 'coffee'});
it('should parse coffee front matter.', function (done) {
var actual = matter.read('./test/fixtures/coffee.md', {
lang: 'coffee'
});
expect(actual).to.deep.equal(expected);
done();
});
it('should evaluate functions in coffee front matter.', function(done) {
var actual = matter.read('./test/fixtures/coffee-fn.md', {autodetect: true});
it('should evaluate functions in coffee front matter.', function (done) {
var actual = matter.read('./test/fixtures/coffee-fn.md', {
autodetect: true
});
expect(typeof actual.context).to.equal('function');

@@ -152,17 +236,6 @@ done();

describe('Autodetect language:', function() {
var expected = {
context: 'jonschlinkert',
content: "\nContent",
original: "--- coffee\nuser = 'jonschlinkert'\n---\nContent"
};
it('should autodetect front matter language, and use the correct parser.', function(done) {
var actual = matter.read('./test/fixtures/autodetect.md', {autodetect: true});
expect(actual).to.deep.equal(expected);
done();
});
});
describe('Read empty files:', function() {
it('should return an object, even if the file is empty.', function(done) {
describe('Read empty files:', function () {
it('should return an object, even if the file is empty.', function (done) {
var actual = matter.read('./test/fixtures/empty.md');

@@ -174,4 +247,4 @@ expect(actual).to.deep.equal(empty);

describe('Read files with no matter:', function() {
it('should correctly parse files that have content but no YAML front matter.', function(done) {
describe('Read files with no matter:', function () {
it('should correctly parse files that have content but no YAML front matter.', function (done) {
var actual = matter.read('./test/fixtures/content-only.md');

@@ -183,4 +256,4 @@ expect(actual).to.deep.equal(contentOnly);

describe('Read YAML files:', function() {
it('should parse YAML directly from .yaml files. e.g. files with no content.', function(done) {
describe('Read YAML files:', function () {
it('should parse YAML directly from .yaml files. e.g. files with no content.', function (done) {
var actual = matter.read('./test/fixtures/metadata.yml');

@@ -192,5 +265,4 @@ expect(actual).to.deep.equal(file.readJSONSync('test/expected/metadata.json'));

describe('Custom delimiters:', function() {
it('should use custom delimiters to read YAML front matter.', function(done) {
describe('Custom delimiters:', function () {
it('should use custom delimiters to read YAML front matter.', function (done) {
var actual = matter.read('./test/fixtures/alpha.hbs');

@@ -202,5 +274,4 @@ expect(actual).to.deep.equal(complexExpected);

describe('Check for matter:', function() {
it('should return true or false if YAML front matter exists.', function(done) {
describe('Check for matter:', function () {
it('should return true or false if YAML front matter exists.', function (done) {
var actual = matter.exists('./test/fixtures/alpha.hbs');

@@ -210,3 +281,2 @@ expect(actual).to.equal(true);

});
});
});
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