UNPKG

@rashedmakkouk/dev-utils

Version:
24 lines (23 loc) 969 B
import { NormalizedSchema } from 'normalizr'; /** Typings */ import { NormalizeSchemaOptions } from '../types'; /** * Normalizes payload by defined object attribute. * * Options: * options['idAttribute'] = 'id' // Object property to normalize based on. * * @param key - Entity type to move records under (e.g. posts). * @param payload - Data object or object array to manipulate. * @param options - Set custom column to use (e.g. idAttribute). * * @returns Result object: * - Object.entities: Normalized records by 'key'. * - Object.result: Array or single value of data 'idAttributes'. */ declare function normalize<KeyT extends string = string, EntityT = unknown, PayloadT extends unknown | unknown[] = unknown[]>(key: KeyT, payload: PayloadT, options?: NormalizeSchemaOptions): NormalizedSchema<{ [key: string]: { [attribute: string]: EntityT; } | undefined; }, PayloadT extends unknown[] ? string[] : string>; export default normalize;