constants.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { resolve } from "node:path";
  2. import type { IRateLimiterOptions } from "rate-limiter-flexible";
  3. import type { ResponseFormat } from "./types.js";
  4. import packageJson from "../package.json" with { type: "json" };
  5. import type { axios } from "./axios.js";
  6. // for @linkcode in tsdoc comments
  7. void [{} as typeof axios];
  8. //#region rate limiting
  9. /** Options for the rate limiter */
  10. export const rateLimitOptions: IRateLimiterOptions = {
  11. points: 20,
  12. duration: 30,
  13. };
  14. /** Any requests to paths starting with one of these will not be subject to rate limiting */
  15. export const rlIgnorePaths = [
  16. "/docs",
  17. ];
  18. //#region docs
  19. /** Path to the VuePress build output folder - this is what gets served as the docs by the API if the `HOST_WEBSITE` env var is set to `true` */
  20. export const docsPath = resolve("./www/.vuepress/dist");
  21. /** Max age of the docs in milliseconds */
  22. export const docsMaxAge = 1000 * 60 * 60 * 24 * 2; // 2 days
  23. //#region misc
  24. /** Max amount of results that geniURL can serve */
  25. export const maxResultsAmt = 10;
  26. /** Timeout for all requests sent using the common {@linkcode axios} instance in milliseconds */
  27. export const axiosTimeout = 1000 * 15;
  28. //#region other
  29. /** The version from package.json, split into a tuple of major, minor, and patch number */
  30. export const splitVersion = packageJson.version.split(".").map(v => Number(v)) as [major: number, minor: number, patch: number];
  31. /** Major, minor, and patch version numbers */
  32. export const [verMajor, verMinor, verPatch] = splitVersion;
  33. /** Map of response formats and their corresponding MIME types */
  34. export const mimeTypeMap = {
  35. json: "application/json",
  36. xml: "application/xml",
  37. } as const satisfies Record<ResponseFormat, string>;
  38. /** Map of unicode variant characters and replacements used in normalizing strings served by the genius API */
  39. export const charReplacements = new Map<string, string>([
  40. ["`´’︐︑ʻ", "'"],
  41. ["“”", "\""],
  42. [",", ","],
  43. ["—─ ", "-"],
  44. ["     ", " "],
  45. ]);