index.ts (743B)
1 export const obj_en = <KeyType extends string, ValType>( 2 object: Record<string, ValType>, 3 parse_function: (key: string) => KeyType = (i) => i as KeyType 4 ): [KeyType, ValType][] => { 5 return Object.entries(object).map<[KeyType, ValType]>(([k, v]) => [parse_function(k), v]) 6 }; 7 8 export const obj_truthy_fields = (obj: Record<string, string>): boolean => { 9 return Object.values(obj).every(Boolean); 10 }; 11 12 export const obj_result = (obj: any): string | undefined => { 13 if (`result` in obj && typeof obj.result === `string`) return obj.result; 14 return undefined; 15 }; 16 17 export const obj_results_str = (obj: any): string[] | undefined => { 18 if (Array.isArray(obj.results)) return obj.results.map(String); 19 return undefined; 20 };