UNPKG

@villedemontreal/general-utils

Version:
88 lines 3.56 kB
export declare const getCartesianProduct: (...vectors: any[]) => any[]; /** * Tells whether the provided value is or can be considered empty. * * Following types are always considered *NOT* empty: boolean, number, function, RegExp. * * @example * • isEmpty('') → true * • isEmpty('…') → false * • isEmpty({}) → true * • isEmpty([]) → true * • isEmpty(null) → true * • isEmpty(undefined) → true * • isEmpty(true) → false * • isEmpty(/^$/) → false * * @param collection Collection to remove the empty values from. * @param #removeEmptyValues */ export declare function isEmpty(value: any): boolean; /** Tells whether the provided value is or can be considered as a collection. */ export declare function isCollection(value: any): boolean; /** * Removes empty values from the given collection. * * @example * • removeEmptyValues({A: 'a', B: '', C: null, D: 'd', E: undefined, F: true}) → {A: 'a', D: 'd', F: true} * * @param collection Collection from which to remove the empty values. * * @see #isEmpty */ export declare function removeEmptyValues<C extends any | any[]>(collection: C): C; /** * Removes missing values from the given collection. * * @example * • removeMissingValues({A: 'a', B: '', C: null, D: 'd', E: undefined, F: true}) → {A: 'a', B: '', D: 'd', F: true} * * @param collection Collection from which to remove the missing values. */ export declare function removeMissingValues<C extends any | any[]>(collection: C): C; /** * Filters the given collection using the provided predicate. * * @param collection Collection from which to filter the values. */ export declare function filter<C extends any | any[]>(collection: C, predicate: (value: any) => boolean): C; /** * Converts the provided collection into a dictionary. * * @param collection Collection to convert into a dictionary. * @param mapper Function used to make the keys of the resulting dictionary. */ export declare function toDictionary<T, C extends T[]>(collection: C, mapper?: (value: T, index: number) => string): { [key: string]: T; }; /** * Tells whether the provided model is matching with the expected model. * * @example * • isMatching({'A': 1, 'B': 2, 'C': 3}, {'A': 1, 'B': true}) // → false * • isMatching({'A': 1, 'B': true, 'C': 3}, {'A': 1, 'B': true}) // → true * * @param model Model to check. * @param expectedModel Structure composed of fixed values, describing what the model should be matching with. * @param keyFilter Keys of the fields to consider for the operation. */ export declare function isMatching(model: any, expectedModel: any, keyFilter?: string[]): boolean; export type CompatibilityRuleSet = { [key: string]: (value: any) => boolean; }; /** * Tells whether the provided model is compatible with the expected model. * * This method is very similar to `#isMatching` but also offers the ability to * specify rules (predicates) instead of fixed values only. * * @example * • isCompatible({'A': 1, 'B': 2, 'C': 3}, {'A': 1, 'B': _.isBoolean}) // → false * • isCompatible({'A': 1, 'B': true, 'C': 3}, {'A': 1, 'B': _.isBoolean}) // → true * * @param model Model to check. * @param expectedModel Structure composed of both fixed values and rules, describing what the model should be matching with. * @param keyFilter Keys of the fields to consider for the operation. */ export declare function isCompatible(model: any, expectedModel: any, keyFilter?: string[]): boolean; //# sourceMappingURL=collectionUtils.d.ts.map