21 lines
984 B
TypeScript
21 lines
984 B
TypeScript
export const VIDEO_DURATION_OPTIONS = [6, 9, 10, 15] as const;
|
|
export const VIDEO_RESOLUTION_OPTIONS = [480, 720, 1080] as const;
|
|
export const VIDEO_DURATION_MIN = 1;
|
|
|
|
export function normalizeVideoDuration(value: string | number | undefined) {
|
|
const seconds = Math.floor(Number(value) || VIDEO_DURATION_OPTIONS[0]);
|
|
return String(Math.max(VIDEO_DURATION_MIN, seconds));
|
|
}
|
|
|
|
export function normalizeVideoResolution(value: string | number | undefined) {
|
|
const token = String(value || "").trim().toLowerCase();
|
|
if (token === "low") return "480";
|
|
if (token === "auto" || token === "medium" || token === "high") return "720";
|
|
const resolution = Number(token.replace(/p$/i, "")) || 720;
|
|
return String(nearestOption(resolution, VIDEO_RESOLUTION_OPTIONS));
|
|
}
|
|
|
|
function nearestOption(value: number, options: readonly number[]) {
|
|
return options.reduce((nearest, option) => Math.abs(option - value) < Math.abs(nearest - value) ? option : nearest, options[0]);
|
|
}
|