@cumulus/common
Version:
Common utilities used across tasks
72 lines • 2.71 kB
TypeScript
/**
* Simple utility functions
*
* @module util
*/
import type { PartialObject, ValueKeyIteratee, NumericDictionary, Dictionary } from 'lodash';
/**
* Mark a piece of code as deprecated.
*
* Each deprecation notice for a given name and version combination will
* only be printed once.
*
* @param {string} name - the name of the function / method / class to deprecate
* @param {string} version - the version after which the code will be marked
* as deprecated
* @param {string} [alternative] - the function / method / class to use instead
* of this deprecated code
*
* @alias module:util
*/
export declare const deprecate: (name: string, version: string, alternative?: string) => void;
/**
* Remove properties whose values are `null` or `undefined`
*
* @param {Object} obj - object to update
* @returns {Object} a shallow clone of the object with `null` and `undefined`
* properties removed
*
* @alias module:util
*/
export declare const removeNilProperties: <T extends object>(obj: T) => { [P in keyof T]: Exclude<T[P], null>; };
/**
* Test if a value is included in a list of items
*
* This is a curried function - https://lodash.com/docs/4.17.11#curry
*
* @param {Array} collection - the list of items to check against
* @param {Object} val - the item to check for in the collection
* @returns {boolean}
*
* @alias module:util
* @kind function
*/
export declare const isOneOf: import("lodash").CurriedFunction2<unknown[], unknown, boolean>;
export declare const returnNullOrUndefinedOrDate: (dateVal: string | number | null | undefined) => Date | null | undefined;
/**
* This is from https://github.com/siberiacancode/lodash-omitdeep/blob/main/src/omitDeepBy/omitDeepBy.ts
* That repo uses outdated lodash packages.
*/
/**
* The opposite of `_.pickBy`; this method creates an object composed of the
* own and inherited enumerable properties of `object` that `predicate`
* doesn't return truthy for.
*
* @param {object} object - The source object.
* @param [predicate=_.identity] - The function invoked per property.
* @returns Returns the new object.
* @example
*
* const object = { 'a': 1, 'b': null, 'c': { 'a': 1, 'b': null } };
*
* omitByDeep(object, _.isNil);
* // => { 'a': 1, 'c': { 'a': 1 } }
*/
interface OmitDeepBy {
<T>(object: Dictionary<T> | null | undefined, predicate?: ValueKeyIteratee<T>): Dictionary<T>;
<T>(object: NumericDictionary<T> | null | undefined, predicate?: ValueKeyIteratee<T>): NumericDictionary<T>;
<T extends object>(object: T | null | undefined, predicate: ValueKeyIteratee<T[keyof T]>): PartialObject<T>;
}
export declare const omitDeepBy: OmitDeepBy;
export {};
//# sourceMappingURL=util.d.ts.map