Skip to main content

Welcome

DiscordJS Docs Parser Logo

GitHub codecov npm

About

discordjs-docs-parser is a parser for DiscordJS documentation. It parses the JSON and outputs all the data in a readable Class format for consumptions. A use case for this library is providing a doc search command in your Discord bot project. It is also a good way to get a quick overview of the documentation. The prime motivators for this library are the Discord Utils Bot and Sapphire Application Commands projects.

Installation

Install with your package manager of choice:

npm install discordjs-docs-parser

Usage

Migrating from [TeeSeal's library][teeseals-library]

discordjs-docs-parser is written to be a drop-in replacement for TeeSeal's library. This means that you can simply replace the require/import and most of your code should continue to work exactly as it is written right now. That said, there are a few things that should be noted that are gone:

  1. The doc.resolveEmbed(query) method is gone. This is a design choice because I am of the opinion that this library should not be doing any opinionated markdown formatting or embed structuring. Instead, it should be left up to the consumer to do this.

  2. All the formatted* methods are gone, except for formattedName and formattedDescription. Similar to the point above, this is because this library should not make any assumptions about how the documentation should be formatted. Instead, the consumer should be responsible for formatting the documentation.

Fetching the documentation

The first step is to fetch the documentation. This is done by calling the fetch method. After fetching the documentation, this library stores the result in an in-memory cache (using a Map) for later use.

Please refer to Doc#fetch examples and more information.

Getting a specific doc element by its name

After fetching the documentation from GitHub, and having it stored in the internal cache, you can get a specific element either by its exact ID or a nested property path.

Please refer to Doc#get examples and more information.

Using a Fuzzy search to find a document element

If instead of getting the absolute path of a specific element you instead want to perform a fuzzy search for elements you can use doc.search. This will return the top 10 results for the provided query using the Jaro Winkler Distance algorithm.

Please refer to Doc#search examples and more information.