Files
EpicNext-Cms/src/lib/format.ts
T
openhands 17847545dd
Deploy / release (push) Skipped
Deploy / deploy (push) Successful in 1m52s
Improvements: remove dead config, fix ESM, add URL validation, unify types, add missing logging
- Remove .prettierrc (dead config, Biome replaces Prettier)
- Rename lighthouserc.json to lighthouserc.cjs with module.exports for ESM compat
- Add logger.warn to empty catch blocks in auth, register, site-settings, prisma-cache, redis, security, rate-limit
- Unify ActionResult type: action-helper.ts uses 'ok' consistent with safe-action-shared.ts
- Add noUnusedLocals + noUnusedParameters to tsconfig + fix 25 pre-existing unused vars
- Replace barrel export src/types/index.ts with direct @/types/common imports
- Make trustHost conditional (development only) in auth.ts
- Add pre-flight URL validation to update-Nitrov3.sh to catch image.library.url misconfigurations
- Improve NITRO_IMAGE_LIBRARY_URL content validation in pre-flight & post-compute checks
2026-07-26 20:28:11 +02:00

46 lines
1.5 KiB
TypeScript

import { resolveImagerBase } from "@/lib/imager";
/** Build a Habbo avatar-imager URL for a figure string. */
export function avatarImageUrl(
base: string,
look: string,
opts: {
size?: "s" | "m" | "l";
headOnly?: boolean;
direction?: number;
headDirection?: number;
} = {},
): string {
const resolved = resolveImagerBase(base);
const params = new URLSearchParams({ figure: look, img_format: "png" });
if (opts.size) params.set("size", opts.size);
if (opts.headOnly) params.set("headonly", "1");
if (opts.direction !== undefined)
params.set("direction", String(opts.direction));
if (opts.headDirection !== undefined)
params.set("head_direction", String(opts.headDirection));
const sep = resolved.includes("?") ? "&" : "?";
return `${resolved}${sep}${params.toString()}`;
}
/** URL-safe slug from a title (lowercase, ascii, hyphenated). */
export function slugify(input: string): string {
// NFKD splits accented letters into base + combining mark; the combining
// marks (and any other non-alphanumerics) are then collapsed to hyphens.
const slug = input
.toLowerCase()
.normalize("NFKD")
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 255);
return slug || "article";
}
/** Trim text to `max` chars on a word boundary, adding an ellipsis. */
export function excerpt(text: string, max = 160): string {
if (text.length <= max) return text;
const cut = text.slice(0, max);
const lastSpace = cut.lastIndexOf(" ");
return `${(lastSpace > 0 ? cut.slice(0, lastSpace) : cut).trimEnd()}…`;
}