@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.

      Parameters

      • value: unknown

        The value to check.

      Returns asserts value is Record<PropertyKey, unknown>

      If the value is not an object.

      v1.0.0

    • Builds an type error Invalid object: ${JSON.stringify(value)}.

      Parameters

      • value: unknown

        The invalid value.

      Returns TypeError

      The created error.

      v1.0.0

    • 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

    • Checks if the given value is an Record.

      Parameters

      • value: unknown

        The value to check.

      Returns value is Record<PropertyKey, unknown>

      True if the value is an object; otherwise, false.

      v1.0.0

    • Checks if the given value is not an Record.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      Returns value is Exclude<T, Record<PropertyKey, unknown>>

      True if the value is not an object; otherwise, false.

      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

    • 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 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

    • 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

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

      v1.0.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

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

      v1.0.0

    • 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.

      // 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

    • 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

      • V

        The value type of the property (loose overload).

      • K extends PropertyKey

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: V

        The value to match against.

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

      A predicate for use with arrays of type T.

      // 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

    • 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.

      // 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

    • 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

      • V

        The value type of the property (loose overload).

      • K extends PropertyKey

        The key of the property to compare.

      Parameters

      • key: K

        The property name to compare.

      • value: V

        The value to check against.

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

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

      // 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

    • 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

    • 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 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-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