Files
ontime/packages/utils/src/customField-utils/customFieldUtils.ts
T
Carlos Valente 2498e59156 refactor: migrate custom fields to transactions
refactor: extract functions to api domain

refactor: strict custom field parsing

refactor: remove rundown cache utilities

refactor: directory restructure
2025-06-09 14:12:59 +02:00

20 lines
577 B
TypeScript

import type { CustomFields } from 'ontime-types';
/**
* Transforms an alphanumeric label with spaces into a valid key
*/
export function customFieldLabelToKey(label: string): string {
return label.trim().replaceAll(' ', '_');
}
/**
* Finds an object key in the CustomFields object that matches the given label
*/
export function customKeyFromLabel(label: string, fields: CustomFields): string | null {
const maybeMatchingKey = Object.keys(fields).find((key) => fields[key].label === label);
if (maybeMatchingKey) {
return maybeMatchingKey;
}
return null;
}