@luolapeikko/ts-common
    Preparing search index...

    Class RecordMapper

    The RecordMapper class provides utility functions for mapping and transforming record types.

    v1.1.0

    Index

    Methods

    Methods

    • Omit function to omit keys from an object or use as map function to omit keys from an array

      Type Parameters

      • K extends PropertyKey

        Omit keys

      Parameters

      • keys: Iterable<K>

        to omit

      Returns <T extends Partial<Record<K, unknown>>>(value: T) => Omit<T, K>

      omitted object or map function

      type Data = {demo: string, value: number|null};
      const dataArray: Data[] = [{demo: 'hello', value: null}];
      const output: Omit<Data, 'demo'>[] = dataArray.map(RecordMapper.omit(['demo']));

      v1.1.0

    • Pick function to pick keys from an object or use as map function to pick keys from an array

      Type Parameters

      • K extends PropertyKey

        Pick keys

      Parameters

      • keys: Iterable<K>

        keys to pick

      Returns <T extends Partial<Record<K, unknown>>>(value: T) => Pick<T, K>

      picked object or map function

      type Data = {demo: string, value: number | null};
      const dataArray: Data[] = [{demo: 'hello', value: null}];
      const output: Pick<Data, 'demo'>[] = dataArray.map(RecordMapper.pick(['demo']));

      v1.1.0

    • Creates a function that selects a specific property value from an object.

      Useful for use with arrays map function when extracting a single property from each object.

      Type Parameters

      • T extends any[] | Record<PropertyKey, any>

        Object target from which the property will be selected

      • K extends string | number | symbol

        Property name in target that will be selected

      Parameters

      • key: K

        The property name to select

      Returns (target: T) => T[K]

      select value by key from the target

      // property access
      const ids = users.map(RecordMapper.prop('id'));
      // index access
      const getFirst = RecordMapper.prop(0);
      const test = getFirst(['a', 'b', 'c']); // 'a'

      v1.1.0

    • Creates a function that selects a specific property value from an object.

      Useful for use with arrays map function when extracting a single property from each object.

      Type Parameters

      • K extends PropertyKey

        Property name in target that will be selected

      Parameters

      • key: K

        The property name to select

      Returns <T extends Record<K, any>>(target: T) => T[K]

      select value by key from the target

      // property access
      const ids = users.map(RecordMapper.prop('id'));
      // index access
      const getFirst = RecordMapper.prop(0);
      const test = getFirst(['a', 'b', 'c']); // 'a'

      v1.1.0