Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/lib/objects.ts
7458 views
1
/**
2
* Determines if the value provided to the function is an object type that
3
* is not null.
4
*/
5
function isObject(val: unknown): val is Record<string, unknown> {
6
return typeof val === 'object' && val !== null && !Array.isArray(val);
7
}
8
9
/**
10
* Determines if an object is truly empty by looking at the keys present
11
* and the prototype value.
12
*/
13
// eslint-disable-next-line @typescript-eslint/ban-types
14
function isEmptyObject(val: {}): boolean {
15
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
16
}
17
18
/**
19
* A helper function for use in TypeScript that returns all of the keys
20
* for an object, but in a typed manner to make working with them a little
21
* easier.
22
*/
23
// eslint-disable-next-line @typescript-eslint/ban-types
24
function getObjectKeys<T extends {}>(o: T): (keyof T)[] {
25
return Object.keys(o) as (keyof typeof o)[];
26
}
27
28
export { isObject, isEmptyObject, getObjectKeys };
29
30