Skip to content

KartoffelChipss/Typerinth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typerinth

npm npm discord

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.

Table of Contents

Installation

Simply execute the following command in your commandline:

npm install typerinth

Usage

Import the package like this:

import { Modrinth } from 'typerinth';
const modrinth = new Modrinth();

Options

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.


Projects

Search

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.

  1. 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.
  2. 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.
  3. 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")
            ),
    )
})

Get a project by its ID or slug

const project = await modrinth.getProject("project-id");

Get multiple projects by their IDs or slugs

const projects = await modrinth.getProjects(["project-id-1", "project-id-2"]);

Get a random selection of projects

const projects = await modrinth.getRandomProjects(5);

Check if a project ID or slug is valid

const isValid = await modrinth.checkProjectValidity("project-id");

Versions

Get the versions of a project

const versions = await modrinth.getProjectVersions("project-id", {
    loaders: ["forge"],
    gameVersions: ["1.16.5"]
});

Get a version by its ID

const version = await modrinth.getVersion("version-id");

Get multiple versions by their IDs

const versions = await modrinth.getVersions(["version-id-1", "version-id-2"]);

Get the version from a file hash

const version = await modrinth.getVersionFromFileHash("file-hash");

Users

Get a user by their ID or username

const user = await modrinth.getUser("user-id");

Get multiple users by their IDs or usernames

const users = await modrinth.getUsers(["user-id-1", "user-id-2"]);

Get a user's projects

const projects = await modrinth.getUserProjects("user-id");

Miscellanous

Get tags

Gets tags as described in the Modrinth API documentation.

import {TagType} from "typerinth";
const tags = await modrinth.getTag(TagType.Loader);

Get a License by its ID

const license = await modrinth.getLicense("license-id");

Get statistics

const stats = await modrinth.getStatistics();

License

This project is licensed under the MIT License - see the LICENSE file for details.