Path: blob/1.0-develop/resources/scripts/lib/objects.ts
7458 views
/**1* Determines if the value provided to the function is an object type that2* is not null.3*/4function isObject(val: unknown): val is Record<string, unknown> {5return typeof val === 'object' && val !== null && !Array.isArray(val);6}78/**9* Determines if an object is truly empty by looking at the keys present10* and the prototype value.11*/12// eslint-disable-next-line @typescript-eslint/ban-types13function isEmptyObject(val: {}): boolean {14return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;15}1617/**18* A helper function for use in TypeScript that returns all of the keys19* for an object, but in a typed manner to make working with them a little20* easier.21*/22// eslint-disable-next-line @typescript-eslint/ban-types23function getObjectKeys<T extends {}>(o: T): (keyof T)[] {24return Object.keys(o) as (keyof typeof o)[];25}2627export { isObject, isEmptyObject, getObjectKeys };282930