npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

meta-matter

v1.3.3

Published

A fast, easy to use, and customizable extractor for front matter in various formats (YAML, TOML, etc.) between a pair of delimiters.

Downloads

13

Readme

meta-matter

Build Status NPM version

A customizable extractor for front matter in various formats (YAML, TOML, etc.) between a pair of delimiters and at the start of a string.

Features:

  • Delimiters are customizable. (a language name can be placed next to the first delimiter)
  • Parsers are customizable. (with builtin YAML and TOML parsers)
  • LF (0x0A) and CRLF (\x0D\x0A) are both recognizable newlines.

Installation

npm install meta-matter

Usage

var matter = require('meta-matter');

matter('---\nfoo: bar\n---\nbaz');
/* return {
  src: "---\nfoo: bar\n---\nbaz",
  body: "baz",
  data: {foo: "bar"}
}
*/

matter.readFileSync('example.md', {delims: ['--[', ']--']});

/* example.md:

--[ TOML
foo = "bar"
]--
baz
*/

Methods

matter(string[, options])

Parse a string with or without front matter and return an object.

Options:

  • options.loose {Boolean?}: Whether to tolerate ambiguous delimiters. Default: false
  • options.lang {String?}: The name of the parser to use if options.parsers is not a function. Default: 'yaml'
  • options.delims {(String|Array)?}: Custom delimiters. Default: '---' or ['---', '---']
  • options.parsers {(Function|Object)?}: Custom parser(s). Default: {'yaml': matter.parsers.yaml,'toml': matter.parsers.toml}
    • {function(text, {loose: Boolean}): Mixed} A parser function. options.lang will be ignored.
    • {Object.<String, Function>}: A map from languages to parser functions. If no parser is found in it, then search the builtin parsers.

A language name (case-insensitive, lower-case preferred) can be appended to the first delimiter in the source text, e.g. --- YAML, and it will override options.lang but not options.parsers. All builtin languages are "yaml" and "toml".

The returned object has three properties:

  • src {String}: The original input string.
  • body {String}: The input string without front matter. (body.length <= src.length)
  • data {Mixed}: The data returned from the parsers. Default: null (if front matter is missing or whitespace only)

matter.test(string[, options])

Check if a string contains front matter. Only options.loose and options.delims are useful options.

matter.readFile(path[, options], callback)

Read and parse a file asynchronously. The callback function is of type function(error, object).

The returned object will have one more property "path" for the real file path.

matter.readFileSync(path[, options])

Read and parse the file synchronously. It may throw an error when the file is not readable.

The returned object will have one more property "path" for the real file path.

Other properties of matter.

matter.modules

An object with the cache of required modules (lazily loaded):

  • {Object} matter.modules.yaml: require('js-yaml')
  • {Object} matter.modules.toml: require('toml-j0.4')

matter.parsers

All builtin parsers (allowed to be modified):

  • {function(str, opts): Mixed} matter.parsers.yaml: The YAML parser.
  • {function(str, opts): Mixed} matter.parsers.toml: The TOML parser.

Currently, opts only has one property loose, which comes from the provided options.

All builtin parsers will return null when an error occurs.

License

Copyright (c) 2015 Jak Wings. This project was released under the MIT license.