import { PayloadImage } from "../sdk"; export const isDefined = (value: T | null | undefined): value is T => value !== null && value !== undefined; export const isUndefined = (value: T | null | undefined): value is null | undefined => !isDefined(value); export const isNotEmpty = (value: string | null | undefined): value is string => isDefined(value) && value.trim().length > 0; export const isEmpty = (value: string | null | undefined): value is string => isUndefined(value) || value.trim().length === 0; export const hasDuplicates = (list: T[]): boolean => list.length !== new Set(list).size; export const isValidPayloadImage = ( image: | { filename?: string | null; mimeType?: string | null; width?: number | null; height?: number | null; url?: string | null; } | undefined | null | string ): image is PayloadImage => { if (isUndefined(image)) return false; if (typeof image === "string") return false; if (isEmpty(image.filename)) return false; if (isEmpty(image.url)) return false; if (isEmpty(image.mimeType)) return false; if (isUndefined(image.width)) return false; if (isUndefined(image.height)) return false; return true; }; export const isPayloadType = (value: string | T): value is T => typeof value === "object"; export const isPayloadArrayType = ( value: (string | T)[] | null | undefined ): value is T[] => isDefined(value) && value.every(isPayloadType); export const isPublished = ( object: T ): boolean => object._status === "published";