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

cc-parse

v0.0.3

Published

A Conventional Comments parser

Downloads

3

Readme

CC Parse

Current status: in development.

Pipeline status

A Conventional Comments parser for Javascript.

See a demo of this package in action.

This is a simple package that exposes a function which can parse a conventional comment string into a JSON object. For example, it will take the comment:

question (non-blocking): At this point, does it matter which thread has won?

Maybe to prevent a race condition we should keep looping until they've all won?

and turn this into:

{
  "label": "question",
  "decoration": "non-blocking",
  "subject": "At this point, does it matter which thread has won?",
  "discussion": [
    "Maybe to prevent a race condition we should keep looping until they've all won?",
  ]
}

Allowing you to do anything with the resulting object. :)

How does it work?

The parser expects the string passed in to match the Conventional Comments specification. If the string doesn't, then the parser will return either null or optionally can throw.

The resulting object will look like:

interface ParseResult {
  label: 'chore' | 'issue' | 'nitpick' | 'praise' | 'question' | 'suggestion' | 'thought';
  decoration: string | '';
  subject: string;
  discussion: string[];
}

Where:

  • label should always match one of the specified labels in Conventional Commits
  • decoration: can either be a supplied decoration or an empty string
  • subject is always required
  • discussion will always be an array of strings or an empty array

Getting Started

TODO: This is not hosted on any package registries yet, to be done. For now, you can clone this repo and run npm pack, then npm install path-to-the-tgz.

Once installed in your project, you can use it like so:

import parse from 'cc-parse';

const myString = `**thought (non-blocking):** Is it worth grouping these imports?`

const result = parse(myString);

// Do something with your result, e.g. console.log(result);

Misc

The parsing uses nearley.js and this package includes a grammar that describes how to parse the comments and a function that wraps this with some other checks. I am by no means a nearley expert (this is the first time I've ever used it), so I suspect the grammar is ripe for improvements, bug fixes and optimisations - some of which I hope to tackle as I learn more.

As of right now, it works for basic comment formats, including some basic markdown variations, but it hasn't been extensively tested yet so I'm sure there's problems.

My goal is to use this to add more features to Tal Tal.

Building

This is a simple project but it still uses Typescript and Webpack. Simply clone the repo then:

yarn install

To run tests:

yarn test

To build:

yarn build

This will produce a dist folder with the necessary files.