forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.ts
More file actions
28 lines (25 loc) · 932 Bytes
/
objects.ts
File metadata and controls
28 lines (25 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Determines if the value provided to the function is an object type that
* is not null.
*/
function isObject(val: unknown): val is Record<string, unknown> {
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 };