UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

62 lines (61 loc) 4.79 kB
import type { DeepPartial, DeepReadonly, DeepRequired } from 'ts-essentials'; import type { ILogObj, Logger } from 'tslog'; /** * checks if `item` is an object (it may be an array, ...) */ export declare function isObjectOrArray(item: unknown): boolean; /** * checks if `item` is a record with keys, i.e. an object that is neither `null` nor an array * @see {@link isObjectOrArray} to allow arrays as well */ export declare function isPlainObject(item: unknown): item is Record<string, unknown>; export type MergeableRecord = Record<string, unknown>; export type MergeableArray = unknown[]; export type Mergeable = MergeableRecord | MergeableArray; type OrReadonly<T> = T | Readonly<T> | DeepReadonly<T>; /** * Given two objects deeply merges them, if an object is an array it will merge the array values! * Guarantees some type safety by requiring objects to merge to be from the same type (allows undefined) * @see {@link deepMergeObjectInPlace} to merge into an existing object */ export declare function deepMergeObject<T extends Mergeable>(base: Required<OrReadonly<T>>, addon?: T | DeepPartial<T> | Partial<T>): Required<T>; export declare function deepMergeObject<T extends Mergeable>(base: DeepRequired<OrReadonly<T>>, addon?: T | DeepPartial<T> | Partial<T>): DeepRequired<T>; export declare function deepMergeObject<T extends Mergeable>(base: OrReadonly<T>, addon?: DeepPartial<T> | Partial<T>): T; export declare function deepMergeObject(base: Mergeable, addon: Mergeable): Mergeable; export declare function deepMergeObject(base?: Mergeable, addon?: Mergeable): Mergeable | undefined; /** * Given two objects deeply merges them, if an object is an array it will merge the array values! * Modifies the `base` object in place and also returns it. * Guarantees some type safety by requiring objects to merge to be from the same type (allows undefined) * @see {@link deepMergeObject} to create a new merged object */ export declare function deepMergeObjectInPlace<T extends Mergeable>(base: T, addon?: DeepPartial<T> | Partial<T>): T; export declare function deepMergeObjectInPlace<T extends Mergeable>(base: T | undefined, addon?: DeepPartial<T> | Partial<T>): T | undefined; type Defined<T> = Exclude<T, undefined>; type DefinedRecord<T> = { [K in keyof T as T[K] extends undefined ? never : K]: Defined<T[K]>; }; export declare function compactRecord<T extends Record<string, unknown>>(record: T): DefinedRecord<T>; export declare function compactRecord(record: undefined): undefined; export declare function compactRecord<T extends Record<string, unknown>>(record: T | undefined): DefinedRecord<T> | undefined; type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | Function; /** * Given an object type `T`, produces a union of string literal types representing all possible paths to primitive values within that object. * Sadly, right now, the ts-essential paths property breaks when it comes to deeper nested objects */ export type AutocompletablePaths<T, Prefix extends string = ''> = T extends Primitive | readonly unknown[] ? never : { [K in keyof T & string]: `${Prefix}${K}` | (T[K] extends Primitive | readonly unknown[] ? never : AutocompletablePaths<T[K], `${Prefix}${K}.`>); }[keyof T & string]; /** * This is a version of a deep clone that preserves unclonable values (like functions, symbols, ...) by keeping the same reference to them. */ export declare function deepClonePreserveUnclonable<T>(obj: T): T; /** * Compares the two passed objects deeply using the loose comparison system designed for the {@link FlowrFilter.MatchesEnrichment}. For this system in use, see {@link FlowrFilter.MatchesEnrichment} in use. * @param obj - The real object which we want to test against. * @param expected - The object to test the real value {@link obj} against, which should be an object in the shape of {@link obj} with each value to test for replaced by a {@link RegExp} or value to match against. The test will pass if the partial structure matches and the value at each {@link RegExp}, string or primitive location matches the corresponding regular expression. For array entries, {@link arrayMatch} determines whether every element in the array has to match the given expected value, or only some. * @param arrayMatch - For array entries, the expected value in {@link test} is compared against each array entry in the real value. This property determines whether every element in the array has to match, or only some. If unset, this defaults to `some`. * @param logger - The logger to use for trace debugging. */ export declare function looselyCompareObjects(obj: Record<string, unknown>, expected: Record<string, unknown>, arrayMatch?: 'some' | 'every', logger?: Logger<ILogObj>): boolean; export {};