mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-05 23:43:57 +00:00
2498e59156
refactor: extract functions to api domain refactor: strict custom field parsing refactor: remove rundown cache utilities refactor: directory restructure
20 lines
577 B
TypeScript
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;
|
|
}
|