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

@kalimahapps/docblock-parser

v1.2.1

Published

Line-based docblock parser

Downloads

17

Readme

This parser provides an AST-like structure for docblocks. It is line based, meaning that it will parse docblock line by line. It provides location information for each node, and it will also parse tags and their values.

Usage

const Parser = new Parser();
Parser.parse(`Docblock content`);

Example

/**
* Summary.
*
* Description that spans multiple lines. This is
* the second line of the description. and this is the third line.
* This the last line of the description.
*
* @since x.x.x
*
* @param boolean $isItTrue Check if value is true.
* @param array $args List of arguments in an array format.
* @param string  $var Description of the parameter
* @param {number} $var Description.
* @return Response Add return description here. It can be multiline.
* This is the second line of the description.
*/`;

output:

{
	"summary": {
		"value": "Summary.",
		"position": {
			"start": {
				"line": 1,
				"column": 2,
				"offset": 6
			},
			"end": {
				"line": 1,
				"column": 10,
				"offset": 14
			}
		}
	},
	"description": [
		{
			"value": "Description that spans multiple lines. This is",
			"position": {
				"start": {
					"line": 3,
					"column": 2,
					"offset": 19
				},
				"end": {
					"line": 3,
					"column": 48,
					"offset": 65
				}
			}
		},
		{
			"value": "the second line of the description. and this is the third line.",
			"position": {
				"start": {
					"line": 4,
					"column": 2,
					"offset": 68
				},
				"end": {
					"line": 4,
					"column": 65,
					"offset": 131
				}
			}
		},
		{
			"value": "This the last line of the description.",
			"position": {
				"start": {
					"line": 5,
					"column": 2,
					"offset": 134
				},
				"end": {
					"line": 5,
					"column": 40,
					"offset": 172
				}
			}
		}
	],
	"tags": [
		{
			"name": {
				"value": "@since",
				"position": {
					"start": {
						"line": 7,
						"column": 2,
						"offset": 177
					},
					"end": {
						"line": 7,
						"column": 8,
						"offset": 183
					}
				}
			},
			"description": [
				{
					"value": "x.x.x",
					"position": {
						"start": {
							"line": 7,
							"column": 9,
							"offset": 184
						},
						"end": {
							"line": 7,
							"column": 14,
							"offset": 189
						}
					}
				}
			],
			"type": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"variable": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"position": {
				"start": {
					"line": 7,
					"column": 2,
					"offset": 177
				},
				"end": {
					"line": 7,
					"column": 14,
					"offset": 189
				}
			}
		},
		{
			"name": {
				"value": "@param",
				"position": {
					"start": {
						"line": 9,
						"column": 2,
						"offset": 194
					},
					"end": {
						"line": 9,
						"column": 8,
						"offset": 200
					}
				}
			},
			"description": [],
			"type": {
				"value": "$isItTrue",
				"position": {
					"start": {
						"line": 9,
						"column": 25,
						"offset": 217
					},
					"end": {
						"line": 9,
						"column": 34,
						"offset": 226
					}
				}
			},
			"variable": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"position": {
				"start": {
					"line": 9,
					"column": 2,
					"offset": 194
				},
				"end": {
					"line": 9,
					"column": 34,
					"offset": 226
				}
			}
		},
		{
			"name": {
				"value": "@param",
				"position": {
					"start": {
						"line": 10,
						"column": 2,
						"offset": 245
					},
					"end": {
						"line": 10,
						"column": 8,
						"offset": 251
					}
				}
			},
			"description": [],
			"type": {
				"value": "$args",
				"position": {
					"start": {
						"line": 10,
						"column": 19,
						"offset": 262
					},
					"end": {
						"line": 10,
						"column": 24,
						"offset": 267
					}
				}
			},
			"variable": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"position": {
				"start": {
					"line": 10,
					"column": 2,
					"offset": 245
				},
				"end": {
					"line": 10,
					"column": 24,
					"offset": 267
				}
			}
		},
		{
			"name": {
				"value": "@param",
				"position": {
					"start": {
						"line": 11,
						"column": 2,
						"offset": 304
					},
					"end": {
						"line": 11,
						"column": 8,
						"offset": 310
					}
				}
			},
			"description": [
				{
					"value": "Description of the parameter",
					"position": {
						"start": {
							"line": 11,
							"column": 22,
							"offset": 324
						},
						"end": {
							"line": 11,
							"column": 50,
							"offset": 352
						}
					}
				}
			],
			"type": {
				"value": "",
				"position": {
					"start": {
						"line": 11,
						"column": 15,
						"offset": 317
					},
					"end": {
						"line": 11,
						"column": 15,
						"offset": 317
					}
				}
			},
			"variable": {
				"value": "$var",
				"position": {
					"start": {
						"line": 11,
						"column": 21,
						"offset": 323
					},
					"end": {
						"line": 11,
						"column": 25,
						"offset": 327
					}
				}
			},
			"position": {
				"start": {
					"line": 11,
					"column": 2,
					"offset": 304
				},
				"end": {
					"line": 11,
					"column": 50,
					"offset": 352
				}
			}
		},
		{
			"name": {
				"value": "@param",
				"position": {
					"start": {
						"line": 12,
						"column": 2,
						"offset": 355
					},
					"end": {
						"line": 12,
						"column": 8,
						"offset": 361
					}
				}
			},
			"description": [
				{
					"value": "Description.",
					"position": {
						"start": {
							"line": 12,
							"column": 23,
							"offset": 376
						},
						"end": {
							"line": 12,
							"column": 35,
							"offset": 388
						}
					}
				}
			],
			"type": {
				"value": "{number}",
				"position": {
					"start": {
						"line": 12,
						"column": 17,
						"offset": 370
					},
					"end": {
						"line": 12,
						"column": 25,
						"offset": 378
					}
				}
			},
			"variable": {
				"value": "$var",
				"position": {
					"start": {
						"line": 12,
						"column": 22,
						"offset": 375
					},
					"end": {
						"line": 12,
						"column": 26,
						"offset": 379
					}
				}
			},
			"position": {
				"start": {
					"line": 12,
					"column": 2,
					"offset": 355
				},
				"end": {
					"line": 12,
					"column": 35,
					"offset": 388
				}
			}
		},
		{
			"name": {
				"value": "@return",
				"position": {
					"start": {
						"line": 13,
						"column": 2,
						"offset": 391
					},
					"end": {
						"line": 13,
						"column": 9,
						"offset": 398
					}
				}
			},
			"description": [
				{
					"value": "return description here. It can be multiline.",
					"position": {
						"start": {
							"line": 13,
							"column": 23,
							"offset": 412
						},
						"end": {
							"line": 13,
							"column": 69,
							"offset": 458
						}
					}
				},
				{
					"value": "This is the second line of the description.",
					"position": {
						"start": {
							"line": 14,
							"column": 2,
							"offset": 460
						},
						"end": {
							"line": 14,
							"column": 45,
							"offset": 503
						}
					}
				}
			],
			"type": {
				"value": "Add",
				"position": {
					"start": {
						"line": 13,
						"column": 21,
						"offset": 410
					},
					"end": {
						"line": 13,
						"column": 24,
						"offset": 413
					}
				}
			},
			"variable": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"position": {
				"start": {
					"line": 13,
					"column": 2,
					"offset": 391
				},
				"end": {
					"line": 14,
					"column": 45,
					"offset": 503
				}
			}
		},
		{
			"name": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"description": [],
			"type": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"variable": {
				"value": "",
				"position": {
					"start": {
						"line": 0,
						"column": 0,
						"offset": 0
					},
					"end": {
						"line": 0,
						"column": 0,
						"offset": 0
					}
				}
			},
			"position": {
				"start": {
					"line": 0,
					"column": 0,
					"offset": 0
				},
				"end": {
					"line": 0,
					"column": 0,
					"offset": 0
				}
			}
		}
	]
}

1- Install dependencies with:

pnpm install

or

npm install

2- Run build command:

pnpm build

or

pnpm build:watch

3- Testing

pnpm test