Add centralized unit definitions

This commit is contained in:
Codex
2026-03-07 06:35:29 +00:00
parent e20fcbb3df
commit 143608db37
3 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { calculators } from './calculators';
const domainDescriptions: Record<string, string> = {
length: 'linear or spatial distance measurement',
weight: 'mass or force quantity',
temperature: 'thermal energy level',
volume: 'three-dimensional capacity',
area: 'two-dimensional surface measurement',
speed: 'rate of change of position',
pressure: 'force exerted per unit area',
energy: 'capacity to do work',
power: 'rate of energy transfer',
data: 'digital information volume',
time: 'temporal duration',
angle: 'angular measurement',
'number-systems': 'numeric representation systems',
radiation: 'ionizing emission metrics',
electrical: 'electricity-related magnitude',
force: 'force or torque measurement',
light: 'luminous intensity',
other: 'specialized measurement',
};
const definitions: Record<string, string> = {};
const formatLabel = (label: string): string => {
if (!label) return '';
return label
.replace(/\b([A-Z])/g, ' $1')
.replace(/\s+/g, ' ')
.trim();
};
const buildDefinition = (label: string, categoryKey: string): string => {
if (!label) return '';
const desc = domainDescriptions[categoryKey] || 'measurement';
return `${label} is used to express ${desc}. Understanding ${label} keeps calculations aligned across the ${categoryKey} domain.`;
};
calculators.forEach(calc => {
const { category, labels } = calc;
Object.values(labels).forEach(label => {
if (!label) return;
if (!definitions[label]) {
definitions[label] = buildDefinition(label, category);
}
});
});
export function getDefinition(label: string): string | undefined {
return definitions[label];
}
export const unitDefinitions = definitions;