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

text-metadata-parser

v3.0.4

Published

Text Metadata Parser was created for two reasons: to parse content and content metadata out of a single string or file, and to try to come up with the most boring library name ever!

Downloads

204

Readme

Build Status

Text Metadata Parser is a Jekyll Front Matter-like parser.

It was created in 2013, before Jekyll was widespread enough for me to just use Front Matter instead.

At this point, text-metadata-parser uses js-yaml internally, meaning that it supports all the YAML features that the other library supports.

In addition, for backwards compatibility, it also allows you to use a much looser syntax. If you do not enclose the metadata section in --- three dashes, they will be inferred. When parsing metadata in "loose mode", key: value sections that have colons in the value string will be allowed, even if they are not enclosed in double quotes.

API

parse(text, [options])

  • text is a string that contains a metadata section at the top
  • options is an optional object with options to create a weak-type-wizard to cast the metadata to whatever types you like

Install

npm install text-metadata-parser

Example

Say you wrote some random blog posts in a drunken stupor one night, and saved them all in text files in this format:

title:    Last will and testament
date:	    2019-09-13
attn:     Secret Family
lovers:   3
deceased: true

I leave everything to Janet.

Except my boots.  Those are *mine.*

Parse:

var my_drunken_ramblings = parse(that_big_string_from_earlier_in_the_example, {
	number: ['lovers', 'bagels'],
	string: ['title', 'attn'],
	date: ['date'],
	boolean: 'deceased',
	default: { lovers: 5, bagels: 3}
});

PROFIT!!!11

> my_drunken_ramblings.metadata.title
'Last will and testament'

> my_drunken_ramblings.metadata.date
Fri Sep 13 2019 00:00:00 GMT+0000 (Coordinated Universal Time)

> my_drunken_ramblings.metadata.lovers
3

> my_drunken_ramblings.metadata.bagels
3

> my_drunken_ramblings.content
'I leave everything to Janet.\n\nExcept my boots.  Those are *mine.*'

License

WTFPL