2022-06-26 18:34:09 +00:00
|
|
|
/**
|
|
|
|
* Determines if the value provided to the function is an object type that
|
|
|
|
* is not null.
|
|
|
|
*/
|
2022-06-27 23:56:26 +00:00
|
|
|
function isObject(val: unknown): val is Record<string, unknown> {
|
2022-06-26 18:34:09 +00:00
|
|
|
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if an object is truly empty by looking at the keys present
|
|
|
|
* and the prototype value.
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
2022-06-26 19:13:52 +00:00
|
|
|
function isEmptyObject(val: {}): boolean {
|
2022-06-26 18:34:09 +00:00
|
|
|
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function for use in TypeScript that returns all of the keys
|
|
|
|
* for an object, but in a typed manner to make working with them a little
|
|
|
|
* easier.
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
2022-06-26 19:13:52 +00:00
|
|
|
function getObjectKeys<T extends {}>(o: T): (keyof T)[] {
|
2022-06-26 18:34:09 +00:00
|
|
|
return Object.keys(o) as (keyof typeof o)[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export { isObject, isEmptyObject, getObjectKeys };
|