import { $t } from '../locales'; /** * Transform record to option * * @example * ```ts * const record = { * key1: 'label1', * key2: 'label2' * }; * const options = transformRecordToOption(record); * // [ * // { value: 'key1', label: 'label1' }, * // { value: 'key2', label: 'label2' } * // ] * ```; * * @param record */ export function transformRecordToOption>(record: T) { return Object.entries(record).map(([value, label]) => ({ value: Number.parseInt(value, 10), label })) as CommonType.Option[]; } /** * Translate options * * @param options */ export function translateOptions(options: CommonType.Option[]) { return options.map(option => ({ ...option, label: $t(option.label as FlowI18n.I18nKey) })); } export function isNotNull(value: any) { return value !== undefined && value !== null && value !== '' && value !== 'undefined'; }