gray-matter
Advanced tools
Comparing version 0.3.1 to 0.3.4
{ | ||
"name": "gray-matter", | ||
"version": "0.3.1", | ||
"version": "0.3.4", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "index.js" |
32
index.js
/** | ||
* Gray Matter | ||
* gray-matter <https://github.com/assemble/gray-matter> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors. | ||
@@ -7,15 +8,20 @@ * Licensed under the MIT license. | ||
'use strict'; | ||
const YAML = require('js-yaml'); | ||
const delims = require('delims'); | ||
const file = require('fs-utils'); | ||
const _ = require('lodash'); | ||
// node_modules | ||
var YAML = require('js-yaml'); | ||
var delims = require('delims'); | ||
var file = require('fs-utils'); | ||
var _ = require('lodash'); | ||
const parsers = require('./lib/parsers'); | ||
const utils = require('./lib/utils'); | ||
// Local libs | ||
var parsers = require('./lib/parsers'); | ||
var utils = require('./lib/utils'); | ||
// Parse the given string | ||
/** | ||
* Parse the given string | ||
* | ||
* @param {String} the string to parse | ||
* @param {Object} object of options | ||
* | ||
* @return {Object} | ||
*/ | ||
function matter(str, options) { | ||
@@ -35,4 +41,4 @@ var opts = _.defaults({}, options, { | ||
if(opts.autodetect) { | ||
opts.lang = utils.detectLang(opts.delims[0], content); | ||
content = content.replace(opts.lang, ''); | ||
opts.lang = utils.detectLang(opts.delims[0], content) || 'yaml'; | ||
content = utils.stripLang(opts.delims[0], content); | ||
} | ||
@@ -39,0 +45,0 @@ |
/** | ||
* Gray Matter | ||
* gray-matter <https://github.com/assemble/gray-matter> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors. | ||
@@ -7,11 +8,9 @@ * Licensed under the MIT license. | ||
'use strict'; | ||
// node_modules | ||
var YAML = require('js-yaml'); | ||
// The module to export | ||
var parse = module.exports = {}; | ||
parse.yaml = function(src) { | ||
@@ -18,0 +17,0 @@ return YAML.load(src); |
/** | ||
* Gray Matter | ||
* gray-matter <https://github.com/assemble/gray-matter> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors. | ||
@@ -19,8 +20,18 @@ * Licensed under the MIT license. | ||
utils.detectLang = function (delim, content) { | ||
var re = new RegExp('^(?:' + delim + ')\s*(.+)\n'); | ||
var re = new RegExp('^' + delim + ' ?([\\S]+)'); | ||
try { | ||
return content.match(re)[1].replace(/^\s+/, ''); | ||
return content.match(re)[1]; | ||
} catch(e) { | ||
return 'yaml'; | ||
return; | ||
} | ||
}; | ||
// Strip the language after the first delim | ||
utils.stripLang = function (delim, content) { | ||
var re = new RegExp('^' + delim + ' ?[\\S]+'); | ||
if (re.test(content)) { | ||
return content.replace(re, delim); | ||
} else { | ||
return content; | ||
} | ||
}; |
{ | ||
"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.3.1", | ||
"version": "0.3.4", | ||
"author": { | ||
@@ -19,18 +19,2 @@ "name": "Jon Schlinkert", | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"dependencies": { | ||
"delims": "~0.1.0", | ||
"fs-utils": "~0.1.6", | ||
"js-yaml": "~3.0.1", | ||
"lodash": "~2.4.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.3", | ||
"chai": "~1.8.1", | ||
"mocha": "~1.17.1", | ||
"toml": "~2.0.4" | ||
}, | ||
"keywords": [ | ||
@@ -50,5 +34,22 @@ "front-matter", | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha" | ||
}, | ||
"dependencies": { | ||
"delims": "~0.1.2", | ||
"fs-utils": "~0.3.8", | ||
"js-yaml": "~3.0.2", | ||
"lodash": "~2.4.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.3", | ||
"chai": "~1.8.1", | ||
"mocha": "~1.17.1", | ||
"toml": "~2.0.4", | ||
"verb": "~0.1.22" | ||
} | ||
} | ||
} |
@@ -295,2 +295,2 @@ # gray-matter [![NPM version](https://badge.fury.io/js/gray-matter.png)](http://badge.fury.io/js/gray-matter) | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 17, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 25, 2014._ |
@@ -277,5 +277,5 @@ /** | ||
context: { | ||
categories: "front matter toml", | ||
title: "TOML", | ||
description: "Front matter", | ||
categories: "front matter toml" | ||
}, | ||
@@ -282,0 +282,0 @@ content: "\n\n# This page has toml front matter!\n", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57689
38
664
5
3
+ Addedasync@0.6.2(transitive)
+ Addedfs-utils@0.3.100.4.3(transitive)
+ Addedgraceful-fs@2.0.3(transitive)
+ Addedtemplate@0.1.8(transitive)
+ Addedunderscore.string@2.3.3(transitive)
- Removedfs-utils@0.1.11(transitive)
- Removediconv-lite@0.2.11(transitive)
Updateddelims@~0.1.2
Updatedfs-utils@~0.3.8
Updatedjs-yaml@~3.0.2