front-matter
Advanced tools
Comparing version 0.1.5 to 0.2.0
@@ -5,3 +5,3 @@ --- | ||
- yaml | ||
- toes | ||
- front-matter | ||
- dashes | ||
@@ -15,2 +15,2 @@ expaned-description: with some --- crazy stuff in it | ||
ALso this shouldn't be a problem | ||
Also this shouldn't be a problem |
@@ -5,5 +5,5 @@ --- | ||
- yaml | ||
- toes | ||
- front-matter | ||
- dashes | ||
expaned-description: with some --- crazy stuff in it | ||
--- |
47
index.js
@@ -1,27 +0,36 @@ | ||
var parser = require('yaml-js') | ||
module.exports = function(string){ | ||
var body = string | ||
, attributes = {} | ||
, match = matcher(string, '= yaml =') || matcher(string, '---') | ||
const parser = require('yaml-js') | ||
const seperators = [ '---', '= yaml ='] | ||
const pattern = pattern = '^(' | ||
+ '((= yaml =)|(---))' | ||
+ '$([\\s\\S]*?)' | ||
+ '\\2' | ||
+ '$' | ||
+ (process.platform === 'win32' ? '\\r?' : '') | ||
+ '(?:\\n)?)' | ||
const regex = new RegExp(pattern, 'm') | ||
if (match){ | ||
attributes = parser.load(match[2].replace(/^\s+|\s+$/g, '')) || {} | ||
body = string.replace(match[0], '') | ||
} | ||
module.exports = extractor | ||
module.exports.test = test | ||
function extractor(string) { | ||
string = string || '' | ||
if (regex.test(string)) return parse(string) | ||
else return { attributes: {}, body: string } | ||
} | ||
function parse(string) { | ||
var match = regex.exec(string) | ||
var yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '') | ||
var attributes = parser.load(yaml) || {} | ||
var body = string.replace(match[0], '') | ||
return { attributes: attributes, body: body } | ||
} | ||
function matcher(string, seperator){ | ||
function test(string){ | ||
string = string || '' | ||
var seperator = seperator || '---' | ||
, pattern = '^(' | ||
+ seperator | ||
+ '$([\\s\\S]*?)' | ||
+ seperator+'$' + (process.platform === 'win32' ? '\\r?' : '') + '(?:\\n)?)' | ||
, regex = new RegExp(pattern, 'm') | ||
, match = regex.exec(string) | ||
if (match && match.length > 0) return match | ||
return regex.test(string) | ||
} |
@@ -11,3 +11,3 @@ { | ||
"license": "MIT", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jxson/front-matter", | ||
@@ -21,3 +21,3 @@ "bugs": "https://github.com/jxson/front-matter/issues", | ||
"scripts": { | ||
"test": "mocha tests/ --reporter spec" | ||
"test": "mocha tests/*-test.js --reporter spec" | ||
}, | ||
@@ -31,4 +31,3 @@ "engines": { | ||
"devDependencies": { | ||
"chai": "1.4.2", | ||
"mocha": "1.7.4" | ||
"mocha": "~1.17.0" | ||
}, | ||
@@ -40,4 +39,5 @@ "contributors": [ | ||
"Jean-Philippe Monette <contact@jpmonette.net> (https://github.com/jpmonette)", | ||
"Marc-André Arseneault <marc-andre@arsnl.ca> (https://github.com/arsnl)" | ||
"Marc-André Arseneault <marc-andre@arsnl.ca> (https://github.com/arsnl)", | ||
"Bret Comnes <bcomnes@gmail.com> (http://bret.io)" | ||
] | ||
} |
@@ -66,2 +66,10 @@ | ||
# fm.test(string) | ||
Check if a string contains a front matter header of "---" or "= yaml =". Primarily used internally but is useful outside of the module. | ||
Returns `true` or `false` | ||
fm.test(string) #=> true || false | ||
# Contributing | ||
@@ -80,2 +88,3 @@ | ||
* **Marc-André Arseneault**: [github](https://github.com/arsnl) - [twitter](https://twitter.com/im_arsnl) | ||
* **Bret Comnes**: [github](https://github.com/bcomnes) - [bret.io](http://bret.io) | ||
@@ -82,0 +91,0 @@ # LICENSE (MIT) |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
1
104
11482
105
1