UNPKG

@tempots/std

Version:

Std library for TypeScript. Natural complement to the Tempo libraries.

80 lines (79 loc) 2.85 kB
import { IndexKey, Merge, TupleToUnion } from './domain'; /** * Returns an array of keys from the given object. * * @param obj - The object from which to extract keys. * @returns An array of keys from the object. * @public */ export declare const objectKeys: <T extends object>(obj: T) => Array<keyof T>; /** * Returns an array of values from the given object. * * @param obj - The object from which to extract values. * @returns An array of values from the object. * @public */ export declare const objectValues: <T extends object>(obj: T) => Array<T[keyof T]>; /** * Returns an array of entries (key-value pairs) from the given object. * * @param obj - The object from which to extract entries. * @returns An array of tuples, where each tuple contains a key and its corresponding value from the object. * @public */ export declare const objectEntries: <T extends object>(obj: T) => [keyof T, T[keyof T]][]; /** * Creates an object from an array of entries. * * @param entries - The array of entries to create an object from. * @returns The created object. * @public */ export declare const objectFromEntries: <T extends object>(entries: [keyof T, T[keyof T]][]) => T; /** * Checks if two objects have the same keys. * * @param a - The first object. * @param b - The second object. * @returns `true` if both objects have the same keys, `false` otherwise. * @public */ export declare const sameObjectKeys: <T extends object>(a: T, b: T) => boolean; /** * Checks if the given value is an object. * * @param obj - The value to check. * @returns `true` if the value is an object, `false` otherwise. * @public */ export declare const isObject: (obj: unknown) => obj is Record<IndexKey, unknown>; /** * Removes specified fields from an object and returns a new object without those fields. * * @param ob - The object from which fields will be removed. * @param fields - The fields to be removed from the object. * @returns A new object without the specified fields. * @public */ export declare const removeObjectFields: <T extends object, F extends Array<keyof T>>(ob: T, ...fields: F) => Omit<T, TupleToUnion<F>>; /** * Merges two objects together. * * @typeParam A - The type of the first object. * @typeParam B - The type of the second object. * @param a - The first object to merge. * @param b - The second object to merge. * @returns The merged object. * @public */ export declare const mergeObjects: <A extends Record<IndexKey, unknown>, B extends Record<IndexKey, unknown>>(a: A, b: B) => Merge<A, B>; /** * Checks if an object is empty. * An object is considered empty if it has no own enumerable properties. * * @param obj - The object to check. * @returns `true` if the object is empty, `false` otherwise. * @public */ export declare const isEmptyObject: (obj: object) => boolean;