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

yfm

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yfm

A YAML Front-Matter parsing and extraction Library.

  • 0.1.1
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

yfm NPM version

A YAML Front-Matter parsing and extraction Library.

npm i yfm --save

Usage

var yfm = require('yfm');
yfm('yfm.html');

Options

You may pass an options object as a second parameter.

custom delimiters

Type: object

Default: {close: '---', open: '---'}

Open and close delimiters can be a string or an array of strings. If an array of strings is passed for a delimiter then all patterns supplied will be used to check for YAML front matter.

Example:

{
  close: ['---', '~~~'],
  open: ['...', '---']
}

Checks for this:

---

title: Foo
---

this

~~~
title: Foo
---

this

---

title: Foo
...

and this

~~~
title: Foo
...

Passing multiple delimiters will likely provide unpredictable results, but the option is included for testing purposes.

read

Type: boolean

Default: true

Specify whether or not to read a file from the file system. When set to false a raw string may be passed to the function. Example:

yfm('---\nTitle: YFM\n---\nContent.', {read: false})

Examples

Extract front matter

Let's say our page, foo.html contains

---
title: YAML Front matter
---
<h1>{{title}}</h1>

then running the following in the command line:

console.log(yfm('foo.html'));

returns

{
  "context": {
    "title": "YAML Front matter"
  },
  "content": "<h1>{{title}}</h1>",
  "original": "---\ntitle: YAML Front matter\n---\n<h1>{{title}}</h1>"
}

and

console.log(yfm('foo.html').context);

returns

{"title": "YAML Front matter"}
Check for YAML front matter
var hasYFM = function (src, options) {
  var obj = yfm(src, options).context;
  return _.keys(obj).length > 0;
};

Authors

Jon Schlinkert

Brian Woodward

License

Copyright (c) 2014 Jon Schlinkert, contributors. Released under the MIT license


This file was generated by grunt-readme on Friday, January 17, 2014.

Keywords

FAQs

Package last updated on 05 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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