core/selectors/payload.selector.ts

core/selectors/payload.selector.ts is a file in Bane's Lab Content. 19 lines of code and 8 definitions.

import { PAYLOAD_CONTENT_KEY, PAYLOAD_TABS_KEY } from "#configuration/constants/leak.constants";

export const isRecord = function isRecord(value: unknown): value is Record<string, unknown> {
    return typeof value === "object" && value !== null;
};

export const textAt = function textAt(record: Record<string, unknown>, key: string): string | null {
    const value = record[key];
    return typeof value === "string" ? value : null;
};

export const listAt = function listAt(value: unknown, key: string): Record<string, unknown>[] {
    const held = isRecord(value) ? value[key] : undefined;
    return Array.isArray(held) ? held.filter(isRecord) : [];
};

export const contentOf = function contentOf(payload: unknown): Record<string, unknown> | null {
    const content = isRecord(payload) ? payload[PAYLOAD_CONTENT_KEY] : undefined;
    return isRecord(content) ? content : null;
};

export const tabsIn = function tabsIn(content: unknown): Record<string, unknown>[] {
    return listAt(content, PAYLOAD_TABS_KEY);
};