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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mdj

v0.4.2

Published

Markdown (GFM) to JSON converter

Downloads

57

Readme

MDJ - Markdown (GFM) to JSON compiler

npm Travis typescript standard

Because sometimes you don't need HTML.

Why

I needed small, reasonably performant, extendable and reliable tool to convert Markdown (GFM) to JSON. Every small markdown parser, that I've found, couldn't generate JSON; every module, capable of generating JSON, is insanely bloated. Therefore I decided to make my own. MDJ is mostly based on marked with many improvements.

Usage

import MDJ from 'mdj'
import source from 'source.md'

const mdj = MDJ()
const parsedSource = mdj.parse(source)

// OR
import { parse }  from 'mdj'
import source from 'source.md'

const parsedSource = parse(source) // Note that this is less performant.

MDJ constructor accepts an optional settings argument:

interface IMDJOptions {
  html?: boolean // enables HTML support, false by default
}

Output

Parser returns an array of tokens. Each token contains at least one property - type, which can be heading, paragraph, code etc.

Other content of tokens may vary. For example tokens of types text, code, codeblock and html have a value property, which represents the raw content of that token.

const md = '`console.log("test")`'

parse(md) //
/*
 outputs
 [
   {
     type: 'paragraph',
     children: [
       {
         type: 'code',
         value: 'console.log("test")
       }
     ]
   }
 ]
*/

As you would have noticed, other tokens may have the children property, which will contain another array of tokens.

Adding new parser rules

Parsers are divided into two parts:

  1. Block parsers, e.g.: paragraph, lists, tables, block quotes etc.
  2. Inline parsers, e.g.: links, checkboxes, images, etc.

To add new parser rule use corresponding instance method:

const blockParser = (source: string) => {/* */}
const inlineParser = (source: string) => {/* */}
const priority = 300

mdj.useBlockParser(blockParser, priority)
mdj.useInlineParser(inlineParser, priority)

Before starting the parsing process all rules are sorted by priority. You may check priorities of default parsers in the source (./src/core/MDJ.ts)

Each parser receives from one to three parameters - source, which is, basically, non-parsed part of the initial source, and one or two lexers (block-level and inline-level for block-level parsers and only inline-level lexer for inline-level parser). Passed lexers use the same MDJ instance and can be used to parse whatever needs to be parsed inside your parser.

Parser should return null, if it did nothing, or an object, containing a new token, which will be added to JSON and a new source. See examples in ./src/parsers.

Roadmap to 1.0.0:

Support:

  • [ ] Reference links and images
  • [x] HTML
  • [ ] Checkbox lists

Performance:

  • [ ] Add public benchmarks
  • [x] Move to rollup
  • [x] Try prepack.io - tried, no benefit

License

MDJ is released under the MIT license.