export type RequiredKeys = { [K in keyof T]-?: NonNullable extends Pick ? never : K; }[keyof T]; export type OptionalKeys = { [K in keyof T]-?: NonNullable extends Pick ? K : never; }[keyof T]; export type OmitOptional = Pick>; export type WithRequired = T & { [P in K]-?: T[P] }; export type ArrayElements> = T extends ReadonlyArray ? S : never; // Reference: // https://stackoverflow.com/questions/7225407/convert-camelcasetext-to-sentence-case-text export function camelToTitle(camel: string): string { let title = camel.replace(/([A-Z])/g, " $1"); title = title.charAt(0).toUpperCase() + title.slice(1); return title; } export function camelToKebab(camel: string) { // Split off first character so function works on upper camel (pascal) case return (camel[0] + camel.slice(1).replace(/[A-Z]/g, c => `-${c}`)).toLowerCase(); } export function isFunction, R>( functionOrValue: ((...args: S) => T) | R ): functionOrValue is (...args: S) => T { return typeof functionOrValue === "function"; } export enum Direction { Up = "Up", Down = "Down", Left = "Left", Right = "Right", Default = "Up" }