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

smart-matter

v1.0.1

Published

Parses front matter Yaml from a file path or a string and returns an Object. Used by squido.org.

Downloads

25

Readme

Install

Install with npm:

$ npm install --save start-matter

How does it work

start-matter parses front-matter either from a file path or from a string containing front-matter.

If supplied, smart-matter will parse a date input into a Javascript Date Object. When using the file(path) API, smart-matter will return last modified date of the file.

API

File

Input is a string with the full path to the input file.

Params

  • input {String}: A full path string to the file with front matter.

Contents

Input is a string contents which returns an object.

Params

  • input {String}: String with the contents of the file with front matter.

Examples

file (path)

const path = require('path');
const { file } = require('start-matter');
const sm = file(path.join(__dirname, 'file.markdown'));
console.log('matter', sm(str));

This assumes that file.markdown is formatted similar to this:

---
title: Hello World
permalink: hello-world
date: '2021-07-03 19:17:00'
tags: 
  - my
  - tags
---

## Hello world

smart-matter will parse this file and return an object like this:

{
    title: "Hello World",
    permalink: "hello-world",
    date: "2021-07-03 19:17:00",
    tags: [ "my", "tags" ],
    matter: "title: Hello World\n
        permalink: hello-world\n
        date: 2021-07-03 19:17:00\n
        tags: \n
          - my\n
          - tags\n",
    file: "/Users/mark/Documents/Code/smart-matter/tests/test.markdown",
    lastupdated: 2021-08-03T06:45:46.170Z,
    hash: "b10a8db164e0754105b7a99be72e3fe5",
    content: "\n\n## Hello world",
    dateObject: 2021-07-03T09:47:00.000Z,
    dateISO: "2021-07-03T09:47:00.000Z",
    error: null,
    empty: false
}

contents (string)

const fs = require('fs');
const { contents } = require('start-matter');
const filePath = fs.readFileSync('file.markdown', 'utf8');
const sm = contents(filePath);
console.log('matter', sm(str));

This assumes that file.markdown is formatted similar to this:

---
title: Hello World
permalink: hello-world
date: '2021-07-03 19:17:00'
tags: 
  - my
  - tags
---

## Hello world

smart-matter will parse this file and return an object like this:

{
    title: "Hello World",
    permalink: "hello-world",
    date: "2021-07-03 19:17:00",
    tags: [ "my", "tags" ],
    matter: "title: Hello World\n
        permalink: hello-world\n
        date: 2021-07-03 19:17:00\n
        tags: \n
          - my\n
          - tags\n",
    hash: "b10a8db164e0754105b7a99be72e3fe5",
    content: "\n\n## Hello world",
    dateObject: 2021-07-03T09:47:00.000Z,
    dateISO: "2021-07-03T09:47:00.000Z",
    error: null,
    empty: false
}

Object returned

Added values to the object are:

  • matter: {String} The raw front-matter string
  • content: {String} The contents of the file outside of the front-matter data
  • date: {String} The original date value
  • dateObject: {Date} The date value parsed onto a Javascript Date
  • dateISO: {String} The date value parsed and formatted into an ISO Date
  • hash: {String} This is the md5 hash of the front-matter title (if supplied)
  • lastupdated: {Date} The last updated value of the file on the disk

Note: When using the file API more options are returned. Eg: file (the input file path) and lastupdated (the last updated date of the file on the disk)