mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-21 17:08:11 +01:00
Normalize message attachments
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
export type NullToUndefined<T> =
|
||||
Extract<T, null> extends never ? T : Exclude<T, null> | undefined;
|
||||
|
||||
export type UndefinedToNull<T> =
|
||||
Extract<T, undefined> extends never ? T : Exclude<T, undefined> | null;
|
||||
|
||||
export function dropNull<T>(
|
||||
value: NonNullable<T> | null | undefined
|
||||
): T | undefined {
|
||||
@@ -35,3 +38,23 @@ export function shallowDropNull<O extends { [key: string]: any }>(
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function convertUndefinedToNull<T>(value: T | undefined): T | null {
|
||||
if (value === undefined) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function shallowConvertUndefinedToNull<T extends { [key: string]: any }>(
|
||||
obj: T
|
||||
): { [P in keyof T]: UndefinedToNull<T[P]> } {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const result: any = {};
|
||||
|
||||
for (const [key, propertyValue] of Object.entries(obj)) {
|
||||
result[key] = convertUndefinedToNull(propertyValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user