UNPKG

@launchmenu/core

Version:

An environment for visual keyboard controlled applets

140 lines 6.8 kB
import { TDeepMerge } from "./_types/TDeepMerge"; /** * Some object related utils */ export declare class ExtendedObject { /** * Checks whether a passed object is a plain javascript object * @param obj The object to perform the operation on * @returns Whether or not the object is a plain javascipt object */ static isPlainObject(obj: any): obj is { [key: string]: any; }; /** * Maps the values of an object to a new object * @param obj The object to perform the operation on * @param func The function to use for the mapping, where the params are value, key, and the return value is used as the new value * @returns The object created as a mapping of the values of this object */ static mapValues<O extends { [key: string]: any; }, T>(obj: O, func: (value: O[keyof O], key: string) => T): { [P in keyof O]: T; }; /** * Maps the values of an object to a new object, alias for mapValues * @param obj The object to perform the operation on * @param func The function to use for the mapping, where the params are value, key, and the return value is used as the new value * @returns The object created as a mapping of the values of this object */ static map<O, T>(obj: O, func: (value: O[keyof O], key: string) => T): { [P in keyof O]: T; }; /** * Maps the keys of an object to a new object * @param obj The object to perform the operation on * @param func The function to use for the mapping, where the params are key, value, and the return value is used as the new key * @returns The object created as a mapping of the keys of this object */ static mapKeys<S>(obj: { [name: string]: S; }, func: (key: string, value: S) => string): { [name: string]: S; }; /** * Maps the keys and values of an object to a new object * @param obj The object to perform the operation on * @param func The function to use for the mapping, where the params are key, value, and the return value is an array with the key as the first index, and value as the second * @returns The object created as a mapping of the keys and values of this object */ static mapPairs<S, T>(obj: { [name: string]: S; }, func: (key: string, value: S) => [string, T]): { [name: string]: T; }; /** * Creates an object from the given entry array * @param entries The entries to create an object from * @returns The resulting object */ static fromEntries<S>(entries: [string, S][]): { [key: string]: S; }; /** * Filters the some fields from the object * @param obj The object to perform the operation on * @param func The function to use to filter, where the params are value and key * @returns The object created which contains all fields that the func returned true for */ static filter<S extends { [key: string]: any; }>(obj: S, func: (value: S[keyof S], key: string) => boolean): Partial<S>; /** * Creates an object containing of the defined fields * @param obj The object to perform the operation on * @param fields A list of fields to include in the object * @returns The object created which contains all specified fields */ static project(obj: { [key: string]: any; }, fields: Array<string>): object; /** * Calls the provided method on all key value pairs * @param obj The object to perform the operation on * @param func The function to call for each of the pairs, receives key and value as parameters * @param recurse Whether or notto recurse on a child object, a function can be provided that will receive the key and value as parameters, and returns whether or not to recurse * @param includeRecurseObj Whether the object that is recursed on should also be called on the function * @param path The path to include to the callback of where we are at in the object */ static forEach<S>(obj: { [name: string]: S; }, func: (key: string, value: S, path: string, parentPath: string) => void, recurse?: ((key: string, value: S, path: string, parentPath: string) => boolean) | boolean, includeRecurseObj?: boolean, path?: string): void; /** * Calls the provided method on all key value pairs that are available in each object * @param objects The array of objects to perform the operation on * @param func The function to call for each of the pairs, receives key and value as parameters * @param recurse Whether or notto recurse on a child object, a function can be provided that will receive the key and value as parameters, and returns whether or not to recurse * @param firstObjectLeading Whether the first object dictates the structure, I.e. if a subsequent object doesn't contain a substructure, it appears as if it does have the structured but is filled with undefined. * @param path The path to include to the callback of where we are at in the object */ static forEachPaired(objects: { [key: string]: any; }[], func: (key: string, values: any[], path: string, parentPath: string) => void, recurse?: ((key: string, values: any[], path: string, parentPath: string) => boolean) | boolean, firstObjectLeading?: boolean, path?: string): void; /** * Merges two objects together * @param obj1 The first object * @param obj2 The second object (which takes precedence) * @returns The merged objects */ static deepMerge<A extends { [key: string]: any; }, B extends { [key: string]: any; }>(obj1: A, obj2: B): TDeepMerge<A, B>; /** * Checks if the contents of object 1 and 2 are equal * @param obj1 The first object * @param obj2 The second object * @param includeObjects Whether object difference should be taken into account * @returns Whether or not the contents of the two objects are equivalent */ static equals(obj1: { [key: string]: any; }, obj2: { [key: string]: any; }, includeObjects?: boolean): boolean; /** * Checks if the contents of object 1 and 2 are equal, including subobjects * @param obj1 The first object * @param obj2 The second object * @param maxDepth The maximum depth to check * @returns Whether or not the contents of the two objects are equivalent */ static deepEquals(obj1: { [key: string]: any; }, obj2: { [key: string]: any; }, maxDepth?: number): boolean; } //# sourceMappingURL=ExtendedObject.d.ts.map