UNPKG

@rx-angular/cdk

Version:

@rx-angular/cdk is a Component Development Kit for ergonomic and highly performant angular applications. It helps to to build Large scale applications, UI libs, state management, rendering systems and much more. Furthermore the unique way of mixing reacti

36 lines (35 loc) 1.04 kB
/** * @description * Accepts an array of objects of type T and single key or array of keys (K extends keyof T). * The `exctract` method is pure and immutable, thus not touching the input values and returning a shallow * copy of the extracted source. * * @example * * const cats = [{id: 1, type: 'cat', name: 'Fluffy'}, {id: 2, type: 'cat', name: 'Emma'}]; * * const catsWithoutTypes = extract(cats, ['name', 'id']); * * // catsWithoutTypes will be: * // [{id: 1, name: 'Fluffy'}, {id: 2, name: 'Emma'}]; * * @example * // Usage with RxState * * export class AnimalsListComponent { * * constructor(private state: RxState<ComponentState>, private api: ApiService) { * state.connect( * 'animals' * this.api.getAnimals(), * (state, animals) => extract(animals, ['id', 'name']) * ); * } * } * * @returns T * * @docsPage slice * @docsCategory transformation-helpers */ export declare function extract<T extends object, K extends keyof T>(array: T[], keys: K | K[]): Pick<T, K>[];