export function parseReportField()

in packages/app/src/logEntryProcessing.ts [36:55]


export function parseReportField(rawField: string): [string, unknown] {
	const [rawFieldName, rawFieldValue] = rawField
		.split(':')
		.map((s) => s.trim());

	const fieldNameNoSpaces = rawFieldName.replace(/ /g, '');
	const fieldName =
		fieldNameNoSpaces.charAt(0).toLowerCase() + fieldNameNoSpaces.slice(1);

	const [value, unit] = rawFieldValue.split(' ');

	if (unit === 'ms' || unit === 'MB') {
		// value should be numeric
		const numericValue = parseFloat(value);
		return [fieldName + unit, numericValue] as [string, unknown];
	} else {
		// we didn't recognise the unit, perhaps there isn't one
		return [fieldName, rawFieldValue] as [string, unknown];
	}
}