Some code cleanup, add jest coverage and begin using it for utility functions

This commit is contained in:
DaneEveritt 2022-06-26 14:34:09 -04:00
parent ca39830333
commit 1eb3ea2ee4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
29 changed files with 2044 additions and 134 deletions

View file

@ -0,0 +1,29 @@
/**
* Determines if the value provided to the function is an object type that
* is not null.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
function isObject (val: unknown): val is {} {
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
function isEmptyObject (val: {}): boolean {
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
function getObjectKeys<T extends {}> (o: T): (keyof T)[] {
return Object.keys(o) as (keyof typeof o)[];
}
export { isObject, isEmptyObject, getObjectKeys };