Skip to content
/ jsdoc Public

Blazing fast ๐Ÿš€ JSDoc generator/parser

License

Notifications You must be signed in to change notification settings

SlimIO/jsdoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

88 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

jsdoc

Version Maintenance MIT dep size Known Vulnerabilities Build Status

JSDoc Generator/Parser. (It use jsdoc-extractor and jsdoc-tokenizer under the hood).

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/jsdoc
# or
$ yarn add @slimio/jsdoc

Usage example

The method will search all JavaScript files at the given location to parse the inner JSDoc.

const { parseFile, groupData } = require("@slimio/jsdoc");

async function main() {
    const fileBlocks = [];
    for await (const block of parseFile("./yourFile.js")) {
        fileBlocks.push(block);
    }

    const finalResult = groupData(fileBlocks);
    console.log(JSON.stringify(finalResult, null, 4));
}
main().catch(console.error);

API

parseJSDoc(buf: Buffer): Block

Parse a JSDoc block (in Buffer format). Return an Object described by the following interface:

interface Descriptor {
    value: any;
    name?: string;
    desc?: string;
    default?: any;
    required?: boolean;
}

interface Block {
    [key: string]: Descriptor | Descriptor[];
}

Take the following example:

const block = parseJSDoc(Buffer.from(`/**
@const name
@type {String}
**/`));
console.log(block.const.value); // name
console.log(block.type.value); // String
parseFile(location: string): AsyncIterableIterator< Block >

This method will read a given file, extract and parse all JSDoc blocks. The method return a Asynchronous iterator to be able to stop the parsing at any time.

const jsdoc = [];
const iterator = parseFile("./yourFile.js");
for await (const block of iterator) {
    jsdoc.push(block);
}
groupData(blocks: Block[]): LinkedBlock

Link (group) blocks by namespace, modules or class (Else the block will be handled as an orphan). The method return an Object described by the following interface:

interface LinkedBlock {
    orphans: Block[];
    members: {
        [name: string]: Block[];
    }
}

Dependencies

Name Refactoring Security Risk Usage
jsdoc-extractor โš ๏ธMajor Low Extract JSDoc annotations from Javascript Files
jsdoc-tokenizer โš ๏ธMajor Low Parse JSDoc annotations and return Tokens

License

MIT

About

Blazing fast ๐Ÿš€ JSDoc generator/parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •