UNPKG

typerinth

Version:

A TypeScript library for interacting with the Modrinth API.

32 lines (31 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetRandomProjects = void 0; const Route_1 = require("../Route"); const errors_1 = require("../../errors"); class GetRandomProjects extends Route_1.Route { count; constructor(baseUrl, ua, cacheManager, count) { if (count < 0 || count > 100) { throw new Error('Count must be between 0 and 100.'); } super(baseUrl, ua, cacheManager); this.count = count; } getCacheKey() { return null; } getUrl() { const url = Route_1.Route.addPathSegment(this.baseUrl, `/projects_random`); url.searchParams.append('count', this.count.toString()); return url; } parseData(data) { if (!data) throw new errors_1.UnexpectedApiError('Unexpected empty response'); if (data.error) throw new errors_1.ApiError(data.error, data.description); return data; } } exports.GetRandomProjects = GetRandomProjects;