This library is a wrapper around the Modrinth API, a platform for Minecraft mods, modpacks, and other content. It is not an official package by Modrinth and not affiliated with Modrinth in any way.
Simply execute the following command in your commandline:
npm install typerinth
Import the package like this:
import { Modrinth } from 'typerinth';
const modrinth = new Modrinth();
You can change the options to tune typerinth to your liking:
import { Modrinth } from 'typerinth';
const modrinth = new Modrinth({
baseUrl: "https://api.modrinth.com",
apiVersion: "v2",
userAgent: "AppName/Version",
cache: {
ttl: 600,
checkperiod: 120,
useCache: true
}
});
Once you have done this, you can use all the following functions as you like.
import { SearchIndex } from 'typerinth';
const result = await modrinth.search("life", {
limit: 3,
index: SearchIndex.Downloads,
})
You can use Facets to filter search results more precisely.
- Facet: Represents a single filter condition. It consists of:
- FacetType: The category of the filter (e.g., versions, categories, etc.).
- FacetOperation: The comparison method (like EQUALS).
- Value: The actual value to filter by.
- FacetGroup: Combines multiple Facets with a logical OR. If any of the Facets in the group match, the result is included. A FacetGroup can also just have one Facet.
- SearchFacets: Combines multiple FacetGroups with a logical AND.
Here’s an example where we search for projects related to "life", filtering them to show only results that:
- Belong to the "forge" category AND
- Are compatible with Minecraft version "1.16.5" OR "1.20.1".
import { SearchIndex, SearchFacets, FacetGroup, Facet } from 'typerinth';
const result = await modrinth.search("life", {
limit: 3,
index: SearchIndex.Downloads,
facets: new SearchFacets(
new FacetGroup(
new Facet(FacetType.Categories, FacetOperation.EQUALS, "forge")
),
new FacetGroup(
new Facet(FacetType.Versions, FacetOperation.EQUALS, "1.16.5"),
new Facet(FacetType.Versions, FacetOperation.EQUALS, "1.17.1")
),
)
})
const project = await modrinth.getProject("project-id");
const projects = await modrinth.getProjects(["project-id-1", "project-id-2"]);
const projects = await modrinth.getRandomProjects(5);
const isValid = await modrinth.checkProjectValidity("project-id");
const versions = await modrinth.getProjectVersions("project-id", {
loaders: ["forge"],
gameVersions: ["1.16.5"]
});
const version = await modrinth.getVersion("version-id");
const versions = await modrinth.getVersions(["version-id-1", "version-id-2"]);
const version = await modrinth.getVersionFromFileHash("file-hash");
const user = await modrinth.getUser("user-id");
const users = await modrinth.getUsers(["user-id-1", "user-id-2"]);
const projects = await modrinth.getUserProjects("user-id");
Gets tags as described in the Modrinth API documentation.
import {TagType} from "typerinth";
const tags = await modrinth.getTag(TagType.Loader);
const license = await modrinth.getLicense("license-id");
const stats = await modrinth.getStatistics();
This project is licensed under the MIT License - see the LICENSE file for details.