Refactoring: Split shared types into seperate modules and document alot.
This commit is contained in:
parent
e08ae944c4
commit
843cd37243
31 changed files with 2498 additions and 842 deletions
server/shared/utils
19
server/shared/utils/objects.ts
Normal file
19
server/shared/utils/objects.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue