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

tunic

v2.0.0

Published

A documentation-block parser.

Downloads

97

Readme

tunic

NPM version Downloads Build Status Coverage Status Chat Tip

A documentation-block parser. Generates a DocTree abstract syntax tree using a customizable regular-expression grammar. Defaults to parsing C-style comment blocks, so it supports C, C++, Java, JavaScript, PHP, and even CSS right out of the box.

Documentation blocks follow the conventions of other standard tools such as Javadoc, JSDoc, Google Closure, PHPDoc, etc. The primary difference is that nothing is inferred from the code. If you want it documented, you must document it. This is why you can use tunic to parse inline documentation out of almost any language that supports multi-line comments.

Tags are parsed greedily. If it looks like a tag, it's a tag. What you do with them is completely up to you. Render something human-readable, perhaps?

Install

$ npm install --save tunic

Usage

var tunic = require('tunic');

// parse javadoc-style comments
var jsDocAst = tunic.parse('/** ... */');

// parse Mustache and Handlebars comments
var hbDocAst = tunic.parse('{{!--- ... --}}', {
    blockIndent: /^[\t !]/gm,
    blockParse: /^[\t ]*\{\{!---(?!-)([\s\S]*?)\s*--\}\}/m,
    blockSplit: /(^[\t ]*\{\{!---(?!-)[\s\S]*?\s*--\}\})/m,
    namedTags: ['element', 'attribute']
});

Or with ES6:

import {parse} from 'tunic';

// parse perlpod-style comments
const perlDocAst = parse('=pod\n ... \n=cut', {
    blockParse: /^=pod\n([\s\S]*?)\n=cut$/m,
    blockSplit: /(^=pod\n[\s\S]*?\n=cut$)/m,
    tagSplit: false
});

API

tunic.parse(code[, grammar]) : DocTree

  • code {String} - Block of code containing comments to parse.
  • grammar {?Object} - Optional grammar definition.
    • blockIndent {RegExp} - Matches any valid leading indentation characters, such as whitespace or asterisks. Used for unwrapping comment blocks.
    • blockParse {RegExp} - Matches the content of a comment block, where the first capturing group is the content without the start and end comment characters. Used for normalization.
    • blockSplit {RegExp} - Splits code and docblocks into alternating chunks.
    • tagParse {RegExp} - Matches the various parts of a tag where parts are captured in the following order:
      • 1: tag
      • 2: type
      • 3: name
      • 4: description
    • tagSplit {RegExp} - Matches characters used to split description and tags from each other.
    • namedTags {Array.<String>} - Which tags should be considered "named" tags. Non-named tags will have their name prepended to the description and set to undefined.

Parses a given string and returns the resulting DocTree AST object. Defaults to parsing C-style comment blocks.

Languages

Several pre-defined grammars are available. To use, import the desired grammar and pass it to the parser.

var parse = require('tunic').parse;
var grammar = require('tunic/grammars/css');

var cssDocAst = parse('/** ... */', grammar); // -> ast object

Or with ES6:

import {parse} from 'tunic';
import * as grammar from 'tunic/grammars/css';

const cssDocAst = parse('/** ... */', grammar); // -> ast object

Test

$ npm test

Contribute

Tasks

Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.


© 2016 Shannon Moeller [email protected]

Licensed under MIT