Home / File/ metadata.ts — astro Source File

metadata.ts — astro Source File

Architecture documentation for metadata.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 3 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f7e2fa0f_185a_721c_2dec_cc06429c3ee5["metadata.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  f7e2fa0f_185a_721c_2dec_cc06429c3ee5 --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  416eda3d_47e6_c298_102b_b7a37d86a44e["../../assets/types.js"]
  f7e2fa0f_185a_721c_2dec_cc06429c3ee5 --> 416eda3d_47e6_c298_102b_b7a37d86a44e
  06b0c610_26ca_c591_7c57_db060f004f97["../utils/vendor/image-size/lookup.js"]
  f7e2fa0f_185a_721c_2dec_cc06429c3ee5 --> 06b0c610_26ca_c591_7c57_db060f004f97
  style f7e2fa0f_185a_721c_2dec_cc06429c3ee5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import type { ImageInputFormat, ImageMetadata } from '../types.js';
import { lookup as probe } from '../utils/vendor/image-size/lookup.js';

/**
 * Extracts image metadata such as dimensions, format, and orientation from the provided image data.
 *
 * @param {Uint8Array} data - The binary data of the image.
 * @param {string} [src] - The source path or URL of the image, used for error messages. Optional.
 * @return {Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>} A promise that resolves with the extracted metadata, excluding `src` and `fsPath`.
 * @throws {AstroError} Throws an error if the image metadata cannot be extracted.
 */
export async function imageMetadata(
	data: Uint8Array,
	src?: string,
): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>> {
	let result;
	try {
		result = probe(data);
	} catch {
		throw new AstroError({
			...AstroErrorData.NoImageMetadata,
			message: AstroErrorData.NoImageMetadata.message(src),
		});
	}
	if (!result.height || !result.width || !result.type) {
		throw new AstroError({
			...AstroErrorData.NoImageMetadata,
			message: AstroErrorData.NoImageMetadata.message(src),
		});
	}

	const { width, height, type, orientation } = result;
	const isPortrait = (orientation || 0) >= 5;

	return {
		width: isPortrait ? height : width,
		height: isPortrait ? width : height,
		format: type as ImageInputFormat,
		orientation,
	};
}

Domain

Subdomains

Functions

Dependencies

  • ../../assets/types.js
  • ../core/errors/index.js
  • ../utils/vendor/image-size/lookup.js

Frequently Asked Questions

What does metadata.ts do?
metadata.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 metadata.ts?
metadata.ts defines 1 function(s): imageMetadata.
What does metadata.ts depend on?
metadata.ts imports 3 module(s): ../../assets/types.js, ../core/errors/index.js, ../utils/vendor/image-size/lookup.js.
Where is metadata.ts in the architecture?
metadata.ts is located at packages/astro/src/assets/utils/metadata.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/utils).

Analyze Your Own Codebase

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

Try Supermodel Free