Repository: withastro/astro
File: packages/astro/src/assets/fonts/utils.ts (TypeScript)

Code before:
import { createRequire } from 'node:module';
import { extname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type * as unifont from 'unifont';
import type { Storage } from 'unstorage';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { DEFAULT_FALLBACKS, FONT_TYPES, LOCAL_PROVIDER_NAME, SYSTEM_METRICS } from './constants.js';
import type { FontFaceMetrics, generateFallbackFontFace } from './metrics.js';
import { type ResolveProviderOptions, resolveProvider } from './providers/utils.js';
import type {
	FontFamily,
	FontType,
	LocalFontFamily,
	ResolvedFontFamily,
	ResolvedLocalFontFamily,
} from './types.js';

export function toCSS(properties: Record<string, string | undefined>, indent = 2) {
	return Object.entries(properties)
		.filter(([, value]) => Boolean(value))
		.map(([key, value]) => `${' '.repeat(indent)}${key}: ${value};`)
		.join('\n');
}

export function renderFontFace(properties: Record<string, string | undefined>) {
	return `@font-face {\n${toCSS(properties)}\n}\n`;
}

export function generateFontFace(family: string, font: unifont.FontFaceData) {
	return renderFontFace({
		'font-family': family,
		src: renderFontSrc(font.src),
		'font-display': font.display ?? 'swap',
		'unicode-range': font.unicodeRange?.join(','),
		'font-weight': Array.isArray(font.weight) ? font.weight.join(' ') : font.weight?.toString(),
		'font-style': font.style,
		'font-stretch': font.stretch,
		'font-feature-settings': font.featureSettings,
		'font-variation-settings': font.variationSettings,
	});
}

// Source: https://github.com/nuxt/fonts/blob/main/src/css/render.ts#L68-L81
export function renderFontSrc(sources: Exclude<unifont.FontFaceData['src'][number], string>[]) {
	return sources
		.map((src) => {
			if ('url' in src) {
				let rendered = `url("${src.url}")`;
				for (const key of ['format', 'tech'] as const) {
					const value = src[key];
					if (value) {

Review comment (suggestion):
```suggestion
	return `@font-face {\n\t${toCSS(properties)}\n}\n`;
```
Some indentation :) 

Code after:
import { createRequire } from 'node:module';
import { extname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type * as unifont from 'unifont';
import type { Storage } from 'unstorage';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { DEFAULT_FALLBACKS, FONT_TYPES, LOCAL_PROVIDER_NAME, SYSTEM_METRICS } from './constants.js';
import type { FontFaceMetrics, generateFallbackFontFace } from './metrics.js';
import { type ResolveProviderOptions, resolveProvider } from './providers/utils.js';
import type {
	FontFamily,
	FontType,
	LocalFontFamily,
	ResolvedFontFamily,
	ResolvedLocalFontFamily,
} from './types.js';

export function toCSS(properties: Record<string, string | undefined>, indent = 2) {
	return Object.entries(properties)
		.filter(([, value]) => Boolean(value))
		.map(([key, value]) => `${' '.repeat(indent)}${key}: ${value};`)
		.join('\n');
}

export function renderFontFace(properties: Record<string, string | undefined>) {
	return `@font-face {\n\t${toCSS(properties)}\n}\n`;
}

export function generateFontFace(family: string, font: unifont.FontFaceData) {
	return renderFontFace({
		'font-family': family,
		src: renderFontSrc(font.src),
		'font-display': font.display ?? 'swap',
		'unicode-range': font.unicodeRange?.join(','),
		'font-weight': Array.isArray(font.weight) ? font.weight.join(' ') : font.weight?.toString(),
		'font-style': font.style,
		'font-stretch': font.stretch,
		'font-feature-settings': font.featureSettings,
		'font-variation-settings': font.variationSettings,
	});
}

// Source: https://github.com/nuxt/fonts/blob/main/src/css/render.ts#L68-L81
export function renderFontSrc(sources: Exclude<unifont.FontFaceData['src'][number], string>[]) {
	return sources
		.map((src) => {
			if ('url' in src) {
				let rendered = `url("${src.url}")`;
				for (const key of ['format', 'tech'] as const) {
					const value = src[key];
					if (value) {