Home / File/ filter-preloads.ts — astro Source File

filter-preloads.ts — astro Source File

Architecture documentation for filter-preloads.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 1 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  b779aa4c_fa5b_6be0_853d_7e9457320b63["filter-preloads.ts"]
  ea387312_d0a2_bb52_dafc_3872f7307f95["../../src/assets/fonts/types.js"]
  b779aa4c_fa5b_6be0_853d_7e9457320b63 --> ea387312_d0a2_bb52_dafc_3872f7307f95
  style b779aa4c_fa5b_6be0_853d_7e9457320b63 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { PreloadData, PreloadFilter } from '../types.js';

export function filterPreloads(
	data: Array<PreloadData>,
	preload: PreloadFilter,
): Array<PreloadData> | null {
	if (!preload) {
		return null;
	}
	if (preload === true) {
		// Preload everything
		return data;
	}
	// Only preload urls based on weight, style and subset
	return data.filter(({ weight, style, subset }) =>
		preload.some((p) => {
			// Always check the weight
			if (
				p.weight !== undefined &&
				weight !== undefined &&
				!checkWeight(p.weight.toString(), weight)
			) {
				return false;
			}
			// Only check the style if specified
			if (p.style !== undefined && p.style !== style) {
				return false;
			}
			// Only check the subset if specified
			if (p.subset !== undefined && p.subset !== subset) {
				return false;
			}
			return true;
		}),
	);
}

function checkWeight(input: string, target: string): boolean {
	// If the input looks like "100 900", we check it as is
	const trimmedInput = input.trim();
	if (trimmedInput.includes(' ')) {
		return trimmedInput === target;
	}
	// If the target looks like "100 900", we check if the input is between the values
	if (target.includes(' ')) {
		const [a, b] = target.split(' ');
		const parsedInput = Number.parseInt(input);
		return parsedInput >= Number.parseInt(a) && parsedInput <= Number.parseInt(b);
	}
	return input === target;
}

Domain

Subdomains

Dependencies

  • ../../src/assets/fonts/types.js

Frequently Asked Questions

What does filter-preloads.ts do?
filter-preloads.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in filter-preloads.ts?
filter-preloads.ts defines 2 function(s): checkWeight, filterPreloads.
What does filter-preloads.ts depend on?
filter-preloads.ts imports 1 module(s): ../../src/assets/fonts/types.js.
Where is filter-preloads.ts in the architecture?
filter-preloads.ts is located at packages/astro/src/assets/fonts/core/filter-preloads.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/fonts/core).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free