/** * OBJECT FUNCTIONS ============================================================ * ============================================================================= */ /** * Get The List of Class Instance Method Names * @param {Class} Class - to get methods names from * @returns {String[]} list - of all instance methods, including async (but excludes properties, and static methods) */ export function classInstanceMethodNames(Class: any): string[]; /** * Clone Object/Collection/Class */ export function cloneFast(obj: any): any; /** * Extract Object keys starting with `#` (or `prefix` character) into a new object * @example: * const props = {'#tag': 'Row', _id: 'Id'} * const privateObj = extractPrivateProps(props) * >>> privateObj == {'tag': 'Row'} * >>> props == {_id: 'Id'} * * @param {object|array} obj - object with mixed of private and standard properties * @param {object} [o] - options * @param {string} [o.prefix] - private property prefix * @param {boolean} [o.mutate] - whether to remove extracted props from given object * @returns {object} privateProps - with `#` (or `prefix` character) removed from keys */ export function extractPrivateProps(obj: object | array, { prefix, mutate }?: { prefix?: string | undefined; mutate?: boolean | undefined; } | undefined): object; /** * Extract Object keys with all UPPER_CASE letters into a new object by mutation * @example: * const props = {VIEW: 'Row', _id: 'Id'} * const upperObj = extractUppercaseProps(props) * >>> upperObj == {VIEW: 'Row'} * >>> props == {_id: 'Id'} * * @param {object|array} obj - object with mixed of uppercase and standard properties * @param {string} [upperChars] - additional characters to be considered as UPPER case * @returns {object} uppercaseProps - new object, and mutated props without uppercase keys */ export function extractUppercaseProps(obj: object | array, upperChars?: string | undefined): object; /** * Delete Nested Property of an Object by given Key Path * @param {Object} obj - to delete property from * @param {String|*} path - key path to nested property for deletion * @returns {Boolean} return value of the `delete` keyword */ export function deleteProp(obj: Object, path: string | any): boolean; /** * Check if value provided is an Object with at least one attribute * * @param {*} obj - value to check * @returns {boolean} - true if value is an Object with value */ export function hasObjectValue(obj: any): boolean; /** * Checks if value is a plain object, that is, * an object created by the Object constructor or one with a [[Prototype]] of null. * * @uses lodash * @see https://lodash.com/docs/4.17.21#isPlainObject * * @param {*} value - any value to check * @return {boolean} */ export function isObject(value: any): boolean; /** * List the keys and values of an object for iteration. * @Note: use for convenience only because it takes 0.5 microseconds per loop, which is: * - x2-3 times longer than looping with `for (const key in obj) {...}` (0.2 microseconds), * - x4-5 times longer than `forEach` or `for i++` loop using array (0.1 microseconds). * => For performance, best to store list as array. * * @uses generator * @uses lodash * @see https://lodash.com/docs/#isObjectLike * * @example: for (const [key, value] of listProps(obj)) { console.log(key, value); } * * @param {Object} obj - the object to list * @return {Object} generator's yielded value */ export function listProps(obj: Object): Object; /** * Creates a new object that merges properties from all given objects. Properties from the right take precedence * over properties on the left * @Note: use update() for faster performance of x5 times (without cloneDeep) and x3 times (with cloneDeep) * * @param {Array|Object} objects - Objects to merge * @return {Object} - A new object */ export function merge(...objects: any[] | Object): Object; /** * Compare Original Object vs. Changed Object and keep only changed values * @note: deleted props will output as `null` value * * @param {Object|Undefined|Null} original - to compare against * @param {Object|Undefined|Null} changed - object to keep changes * @param {Object} [options] - ignoreDeleted?: boolean - whether to disable `null` for deleted props * @returns {Object|Undefined|Null} changedOnly - new object with only changed values kept, or undefined if no changes */ export function objChanges(original: Object | undefined | null, changed: Object | undefined | null, { ignoreDeleted }?: Object | undefined): Object | undefined | null; /** * Set Object to be given Payload recursively, by Mutation * * @example: reset({user: {name: 'Chris'}}, {user: {sign: 'scorpion'}}) >>> {user: {sign: 'scorpion'}} * * @param {Object|Array} collection - collection to be reset * @param {Object} payload - the nested Object to update with * @return {Object|Array} - mutated collection that has properties of payload */ export function reset(collection: Object | any[], payload: Object): Object | any[]; /** * Update Collection with nested props (Array/Object), keeping other attributes in the Collection. * * @example: * update({user: {name: 'Chris'}}, {user: {sign: 'scorpion'}}) * >>> {user: {name: 'Chris', sign: 'scorpion'}} * * @param {Object|Array} state - collection to be updated * @param {Object|Array} payload - the nested props to update with, can be empty (ie. no updates) * @param {{clone?: boolean, removeNull?: boolean, arrayHoles?: boolean}} [options] * [clone] - whether to return new Object instead of mutating it * [removeNull] - whether to remove `null` props instead of updating them as `null` * [arrayHoles] - whether to allow holes in array after update * @return {Object|Array} - mutated/cloned Object with nested update */ export function update(state: Object | any[], payload: Object | any[], { clone, removeNull, arrayHoles }?: { clone?: boolean | undefined; removeNull?: boolean | undefined; arrayHoles?: boolean | undefined; } | undefined): Object | any[]; /** * Check Recursively for Matching Object within Nested Object or Collection. * * @example: * hasObjMatch([[[1, -1], [2, -2]]], [1, -1]); * >>> true * * @param {*} obj - the collection to search for matching object * @param {*} searchObj - the matching object to find * @returns {boolean} - true if a match found. */ export function hasObjMatch(obj: any, searchObj: any): boolean; /** * Check if an Object has Provided Key Paths and Values. * * @example: * const obj = { * properties: { * id: 7 * }, * type: 'DRAFT', * coords: [[[1, -1], [2, -2]]] * } * hasObjKeys(obj, { 'properties.id': 7, 'coords': [1, -1] }, 'include'); * >>> true * * @param {*} obj - the object to check * @param {object} keys - key paths and values to match, e.g. { 'properties.id': 7, type: 'DRAFT' } * @param {String} match - one of comparison types ['deep', 'shallow', 'include'], default is `shallow` * @returns {boolean} - true if a match found. */ export function hasObjKeys(obj: any, keys?: object, match?: string): boolean; /** * Check if given object has `key` property defined as any value * @param {any} obj * @param {string} key * @returns {boolean} true - if the `key` property is defined */ export function hasProp(obj: any, key: string): boolean; /** * Get Reference to Object with Provided Key Paths and Values within Nested Object or Collection. * * @example: * const obj = { * id: 7, * items: [ * { * type: 'polygon', * geoJSON: { * properties: { * id: 7 * }, * type: 'DRAFT', * coords: [[[1, -1], [2, -2]]] * } * } * ] * } * findObjByKeys(obj, { 'properties.id': 7, 'coords': [1, -1] }, 'include'); * >>> Object: { * properties: { * id: 7 * }, * type: 'DRAFT', * coords: [[[1, -1], [2, -2]]] * } * * @param {any} collection - the Object/Array to search for matching object * @param {object} keys - object with key paths and values to match, e.g. { 'properties.id': 7, type: 'DRAFT' } * @param {string} match - one of comparison types ['deep', 'shallow', 'include'] * @returns {object|undefined} - the matching object if found */ export function findObjByKeys(collection: any, keys?: object, match?: string): object | undefined; /** * Find all the objects which matches the keys in the object. * @see findObjByKeys on usage details. * @param {any} collection * @param {object} keys * @param {string} match * @returns {object[]} - the matching objects if found, else empty array */ export function findAllObjsByKeys(collection: any, keys?: object, match?: string): object[]; /** * Get the first direct parent object/array containing given `value` * @param {object|array|any} collection - to search from * @param {any} value - to find parent for * @returns {object|array|void} parent - containing given `value` */ export function findParent(collection: object | array | any, value: any): object | array | void; /** * Extract the value safely from an object via the keyPath and returns the value. * Removes that value's key from the passed object. * * @uses lodash * @see https://lodash.com/docs/4.17.1#get * @param {Object} obj - the object to get from and mutate * @param {string|Array} keyPath - the path to the desired value * @param {*} [fallback] - optional fallback value to return * @return {*} */ export function pop(obj: Object, keyPath: string | any[], fallback?: any): any; /** * Delete Object property without mutating it, returning new Object without the deleted property * * @param {Object} obj - the Object to remove property from * @param {string} key - Object property to delete * @return {Object} - without the deleted key property */ export function removeKey(obj: Object, key: string): Object; /** * Recursively remove given list of keys from object or collection * @param {Object|Array} obj - or collection to remove keys from * @param {String[]} keys - list of keys to remove * @param {Boolean} [clone] - whether to return new object, defaults to mutating existing * @param {Boolean} [recursive] - whether to parse given obj recursively */ export function removeKeys(obj: Object | any[], keys: string[], { clone, recursive }?: boolean | undefined): any; /** * Remove Empty String value keys from given Collection by mutation * (For Array, Falsey values will be removed) * * @param {Object|Array} collection - to remove empty values * @param {Boolean} [recursive] - whether to remove empty values recursively * @return {Object|Array} - without empty strings */ export function removeEmptyValues(collection: Object | any[], { recursive }?: boolean | undefined): Object | any[]; /** * Remove Null/Undefined value keys from given Collection by mutation * (For Array, Falsey values will be removed) * * @param {Object|Array} collection - to remove nil values * @param {Boolean} [recursive] - whether to remove nil values recursively * @return {Object|Array} - without null or undefined keys */ export function removeNilValues(collection: Object | any[], { recursive }?: boolean | undefined): Object | any[]; /** * Remove items with truthy 'delete' properties from given Collection by mutation * (For Array, Falsey values will be removed) * * @param {Object|Array} collection - to remove deleted items from * @return {Object|Array} - without items with .delete keys */ export function removeDeletedItems(collection: Object | any[]): Object | any[]; /** * Remove GraphQL Tags and Null values from given Collection * - Nullable values will be removed from Array * - Commonly uneditable attributes listed in `tags` are deleted, see `GQL_HIDDEN_FIELDS` for example * * @param {Object|Array} collection - to remove graphql tags from * @param {Array} [tags] - list of tags to remove * @param {Boolean} [clone] - whether to clone the object before mutating * @return {Object|Array} - without graphql tags */ export function sanitizeResponse(collection: Object | any[], { tags, clone }?: any[] | undefined): Object | any[]; /** * Sort Object Keys by given order, returning new Object with Keys sorted * * @param {Object} obj - to sort key attributes for * @param {String} order - enum, one of ['asc', 'desc'] * @return {Object} - sorted by key attributes */ export function sortObjKeys(obj: Object, order?: string): Object; export namespace sortObjKeys { function descending(a: any, b: any): 0 | 1 | -1; } /** * Swap Object's Keys with its Values * * @example: * swapKeyWithValue({id: 1, name: Tom}) * >>> {1: 'id', 'Tom': name} * * @param {Object} obj - to swap keys with values * @returns {Object} - with key and values swapped */ export function swapKeyWithValue(obj: Object): Object; /** * Compute the Total Number from Object Values * @example: * toObjValuesTotal({'a': 1, 'b': 2}) * >>> 3 * * @param {Object} obj - with nested values to calculate total for * @returns {number} total - value of object values */ export function toObjValuesTotal(obj: Object): number; /** * Compute the Total Number from Object Values given Key Property * @example: * toObjValuesKeyTotal({'a': {'count': 1}, 'b': {'count': 2}}, 'count') * >>> 3 * * @param {Object} obj - with nested values to calculate total for * @param {String} [key] - nested obj value key to extract amount for calculation * @returns {number} total - value of object values for given key property */ export function toObjValuesKeyTotal(obj: Object, key?: string | undefined): number; /** * Converts object properties to a query string * * @example toParams({ids: [1, 2]}); >>> 'ids=1&ids=2' * * @param {Object} obj - the object to turn into a query string * @return {string} */ export function queryString(obj: Object): string; /** * Flatten/Unflatten Nested Object Keys into Single Object with Dot Separated Keys */ export const toFlatObj: any; export const fromFlatObj: any; export { clone, cloneDeep, get, isEqual, isEmpty, isMap, isObjectLike, isNil, omitBy, property, set, unset };