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

    Class RecordCore

    The core Object functions

    v1.0.0

    Index

    Methods

    • Asserts that the given value is an Record.

      Type Parameters

      • T = undefined

      Parameters

      • value: T

        The value to check.

      Returns asserts value is IsGuard<T, AnyRecord>

      If the value is not an object.

      v1.0.0

    • Builds value error.

      Parameters

      • value: unknown

        The invalid value.

      • typeName: "Record"

        The type name.

      • OptionalisNot: boolean = false

        Whether the error should be for !${typeName}.

      Returns TypeError

      The created error.

      v1.1.2

    • Type-safe Object.entries() with overload for NonEmptyArray

      Type Parameters

      • R extends object

        The object shape

      Parameters

      • value: R

        The object shape to get the values from

      Returns ObjectMappedArrayTuples<R>

      Array of tuples with key and value

      const result1: NonEmptyReadonlyArray<['key', 'value']> = RecordCore.entries({key: 'value'} as const);
      const result2: Array<['key', string]> = RecordCore.entries({key: 'value'});
      const result3: Array<[string, string]> = RecordCore.entries<Record<string, string>>({key: 'value'});
      const result4: [] = RecordCore.entries({});

      v1.0.0

    • Type-safe Object.keys() with overload for NonEmptyArray

      Type Parameters

      • R extends object

        The object shape

      Parameters

      • value: R

        The object shape to get the values from

      Returns ObjectMappedArray<R, keyof R>

      Array of object keys

      const result1: NonEmptyReadonlyArray<'key'> = RecordCore.keys({key: 'value'} as const);
      const result2: Array<'key'> = RecordCore.keys({key: 'value'});
      const result3: Array<string> = RecordCore.keys<Record<string, string>>({key: 'value'});
      const result4: [] = RecordCore.keys({});

      v1.0.0

    • 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

      • T extends Partial<Record<K, unknown>>

        Object type

      Parameters

      • keys: Iterable<K>

        to omit

      • data: T

        to omit from (optional)

      Returns Omit<T, K>

      omitted object or map function

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

      v1.0.0

    • Type Parameters

      • K extends PropertyKey

      Parameters

      • keys: Iterable<K>

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

      Use RecordMapper.omit for omit mapping.

    • 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

      Use RecordMapper.prop instead

      const user1: User = {id: 1, name: 'Alice', role: 'admin', active: true};
      const getName = ObjCore.onKey('name');
      const output: string = getName(user1);

      v1.0.0

    • Type Parameters

      • K extends PropertyKey

      Parameters

      • key: K

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

      Use RecordMapper.prop instead

    • Creates a predicate function that checks whether a given object's property equals the specified value.

      Supports both strictly typed object structures and looser records with optional properties.

      Useful for filtering arrays of objects based on property values.

      Type Parameters

      • T extends Record<PropertyKey, any>

        The object type with known keys (strict overload).

      • K extends string | number | symbol

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: T[K]

        The value to match against.

      Returns (obj: T) => boolean

      A predicate for use with arrays of type T.

      use RecordPredicate.propEq instead.

      // Strict object structure
      const isAdmin = RecordCore.onKeyEqual<User, 'role'>('role', 'admin');
      const admins = users.filter(isAdmin);
      // Loosely typed object
      const isPublished = RecordCore.onKeyEqual('status', 'published');
      const publishedPosts = posts.filter(isPublished);

      v1.0.0

    • Type Parameters

      • V
      • K extends PropertyKey

      Parameters

      • key: K
      • value: V

      Returns (obj: Partial<Record<K, V>>) => boolean

      use RecordPredicate.propEq instead

    • Creates a predicate function that checks whether a given object's property does not equal the specified value.

      Supports both strictly typed object structures and looser records with optional properties.

      Useful for filtering arrays of objects where you want to exclude items with a certain property value.

      Type Parameters

      • T extends Record<PropertyKey, any>

        The object type with known keys (strict overload).

      • K extends string | number | symbol

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: T[K]

        The value to check against.

      Returns (obj: T) => boolean

      A predicate function returning true when obj[key] !== value.

      use RecordPredicate.propNotEq instead.

      // Strict object structure
      const isNotAdmin = RecordCore.onKeyNotEqual<User, 'role'>('role', 'admin');
      const nonAdmins = users.filter(isNotAdmin);
      // Loosely typed object
      const isNotPublished = RecordCore.onKeyNotEqual('status', 'published');
      const draftsOrArchived = posts.filter(isNotPublished);

      v1.0.0

    • Type Parameters

      • V
      • K extends PropertyKey

      Parameters

      • key: K
      • value: V

      Returns (obj: Partial<Record<K, V>>) => boolean

      use RecordPredicate.propNotEq instead

    • 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

      • T extends Partial<Record<K, unknown>>

        Object type

      Parameters

      • keys: Iterable<K>

        keys to pick

      • value: T

        to pick from (optional)

      Returns Pick<T, K>

      picked object or map function

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

      v1.0.0

    • Type Parameters

      • K extends PropertyKey

      Parameters

      • keys: Iterable<K>

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

      Use RecordMapper.pick for pick mapping.

    • Type-safe Object.values() with overload for NonEmptyArray

      Type Parameters

      • R extends object

        The object shape

      Parameters

      • value: R

        The object shape to get the values from

      Returns ObjectMappedArray<R, R[keyof R]>

      Array of object values

      const result1: NonEmptyReadonlyArray<'value'> = RecordCore.values({key: 'value'} as const);
      const result2: Array<string> = RecordCore.values({key: 'value'});
      const result3: [] = RecordCore.values({});

      v1.0.0