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

front-matter

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

front-matter - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

tests/fm-test.js

4

examples/dashes-seperator.md

@@ -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
---

@@ -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

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