Refactoring: Split shared types into seperate modules and document alot.

This commit is contained in:
baldo 2022-09-06 19:09:25 +02:00
parent e08ae944c4
commit 843cd37243
31 changed files with 2498 additions and 842 deletions
server/shared/utils

View file

@ -0,0 +1,19 @@
/**
* Helper functions for objects.
*/
import { hasOwnProperty } from "../types";
/**
* If the given value is an object this function returns the property specified by `key` if it exists.
*
* @param arg - Value to treat as an object to look up the property.
* @param key - Key indexing the property.
* @returns The property of the given object indexed by `key` or `undefined` if `arg` is not an object
* or has no property `key`.
*/
export function getFieldIfExists(
arg: unknown,
key: PropertyKey
): unknown | undefined {
return hasOwnProperty(arg, key) ? arg[key] : undefined;
}