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.0 to 0.2.1

test/fixtures/json-autodetect.md

2

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

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

@@ -19,4 +19,4 @@ /**

utils.detectLang = function (delim, content) {
var re = new RegExp('^(?:' + delim + ')[^\s]([^\\n]*)');
return content.match(re)[1]
var re = new RegExp('^(?:' + delim + ')\s*(.+)\n');
return content.match(re)[1].replace(/^\s+/, '');
};
{
"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.0",
"version": "0.2.1",
"author": {

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

@@ -1,2 +0,2 @@

---
---coffee
user = 'jonschlinkert'

@@ -3,0 +3,0 @@ reverse = (src) ->

@@ -7,3 +7,3 @@ ---

categories: '''
front matter coffee coffescript
front matter coffee coffee-script
'''

@@ -10,0 +10,0 @@ ---

@@ -89,29 +89,46 @@ /**

describe('Parse JSON:', 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 parse JSON front matter.', function(done) {
var actual = matter.read('./test/fixtures/json.md', {format: 'json'});
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!"
};
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) {
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: [';;;', ';;;']});
expect(actual).to.deep.equal(expected);
done();
});
it('should autodetect language and parse JSON front matter.', 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: [';;;', ';;;']});
expect(actual).to.deep.equal(expected);
done();
});
});
describe('Parse coffee:', function() {
var expected = {
context: {
categories: "front matter coffee coffee-script",
title: "Coffee",
description: "Front matter",
},
content: "\n\n# This page has coffee front matter!",
original: "---\ntitle: 'Coffee'\ndescription: '''\n Front matter\n '''\ncategories: '''\n front matter coffee coffee-script\n '''\n---\n\n# This page has coffee front matter!"
};
it('should parse coffee front matter.', function(done) {
var actual = matter.read('./test/fixtures/coffee.md', {lang: 'coffee'});
var expected = {
context: {
categories: "front matter coffee coffescript",
"title": "Coffee",
"description": "Front matter",
},
content: "\n\n# This page has coffee front matter!",
original: "---\ntitle: 'Coffee'\ndescription: '''\n Front matter\n '''\ncategories: '''\n front matter coffee coffescript\n '''\n---\n\n# This page has coffee front matter!"
}
expect(actual).to.deep.equal(expected);

@@ -121,3 +138,3 @@ done();

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

@@ -129,9 +146,9 @@ 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});
var expected = {
context: 'jonschlinkert',
content: "\nContent",
original: "--- coffee\nuser = 'jonschlinkert'\n---\nContent"
}
expect(actual).to.deep.equal(expected);

@@ -138,0 +155,0 @@ done();

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