
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
tokenize-comment
Advanced tools
Uses snapdragon to tokenize a single JavaScript block comment into an object, with description, tags, and code example sections that can be passed to any other comment parsers for further parsing.
Uses snapdragon to tokenize a single JavaScript block comment into an object, with description, tags, and code example sections that can be passed to any other comment parsers for further parsing.
Install with npm:
$ npm install --save tokenize-comment
The main export is a function that takes a string with a single javascript comment only, no code.
var tokenize = require('tokenize-comment');
var token = tokenize(commentString);
console.log(token);
The comment can be a "raw" comment with leading stars:
/**
* foo bar baz
* @param {String} abc Some description
* @param {Object} def Another description
*/
Or a comment with stars already stripped (with or without leading whitespace):
foo bar baz
@param {String} abc Some description
@param {Object} def Another description
Recognizes gfm, javadoc and indented code examples. See the unit tests for a number of more complex examples.
Supports GFM style code examples. The following comment:
/**
* foo bar baz
*
* ```js
* var foo = "bar";
* ```
* @param {string} something
* @param {string} else
*/
Results in:
{
description: 'foo bar baz',
footer: '',
examples: [
{
type: 'gfm',
val: '```js\nvar foo = "bar";\n```',
description: '',
language: 'js',
code: '\nvar foo = "bar";\n'
}
],
tags: [
{
type: 'tag',
raw: '@param {string} something',
key: 'param',
val: '{string} something'
},
{
type: 'tag',
raw: '@param {string} else',
key: 'param',
val: '{string} else'
}
]
}
Supports indented code examples:
/**
* foo bar baz
*
* var foo = "bar";
*
* @param {string} something
* @param {string} else
*/
Supports javadoc-style code examples:
/**
* foo bar baz
*
* @example
* var foo = "bar";
* var baz = "qux";
*
* @param {string} something
* @param {string} else
*/
Results in:
{
description: 'foo bar baz',
footer: '',
examples: [
{
type: 'javadoc',
language: '',
description: '',
raw: '@example\nvar foo = "bar";\nvar baz = "qux";\n',
val: '\nvar foo = "bar";\nvar baz = "qux";\n'
}
],
tags: [
{
type: 'tag',
raw: '@param {string} something',
key: 'param',
val: '{string} something'
},
{
type: 'tag',
raw: '@param {string} else',
key: 'param',
val: '{string} else'
}
]
}
It will also recognize a mixture of formats (javadoc-style examples must always be last):
/**
* This is a comment with
* several lines of text.
*
* An example
*
* ```js
* var foo = bar;
* var foo = bar;
* var foo = bar;
* ```
* * Another example
* * ```var baz = fez;
```* ```var baz = fez;
```* ```var baz = fez;
```* * Another example
* * ```var baz = fez;
```* ```var baz = fez;
```* * * * And another example
* *
```js
Results in:
```js
{
description: 'This is a comment with\nseveral lines of text.',
footer: '',
examples: [
{
type: 'gfm',
language: 'js',
description: 'An example',
raw: '```js\nvar foo = bar;\nvar foo = bar;\nvar foo = bar;\n```',
val: '\nvar foo = bar;\nvar foo = bar;\nvar foo = bar;\n'
},
{
type: 'indented',
language: '',
description: 'Another example',
raw: ' var baz = fez;\n var baz = fez;\n var baz = fez;\n',
val: 'var baz = fez;\nvar baz = fez;\nvar baz = fez;\n'
},
{
type: 'indented',
language: '',
description: 'Another example',
raw: ' var baz = fez;\n var baz = fez;\n',
val: 'var baz = fez;\nvar baz = fez;\n'
},
{
type: 'gfm',
language: 'js',
description: 'And another example',
raw: '```js\nvar foo = bar;\nvar foo = bar;\n```',
val: '\nvar foo = bar;\nvar foo = bar;\n'
},
{
type: 'javadoc',
language: '',
description: 'Another example',
raw: '@example\nvar baz = fez;\n',
val: '\nvar baz = fez;\n'
},
{
type: 'javadoc',
language: '',
description: '',
raw: '@example\n// this is a comment\nvar alalla = zzzz;\n',
val: '\n// this is a comment\nvar alalla = zzzz;\n'
}
],
tags: [
{
type: 'tag',
raw: '@param {String} foo bar',
key: 'param',
val: '{String} foo bar'
},
{
type: 'tag',
raw: '@returns {Object} Instance of Foo',
key: 'returns',
val: '{Object} Instance of Foo'
},
{
type: 'tag',
raw: '@api public',
key: 'api',
val: 'public'
}
]
}
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.4.3, on March 10, 2017.
FAQs
Uses snapdragon to tokenize a single JavaScript block comment into an object, with description, tags, and code example sections that can be passed to any other comment parsers for further parsing.
The npm package tokenize-comment receives a total of 5,404 weekly downloads. As such, tokenize-comment popularity was classified as popular.
We found that tokenize-comment demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.