@xylabs/object
Advanced tools
Comparing version 4.4.10 to 4.4.11
@@ -1,3 +0,4 @@ | ||
export type OmitByPredicate<T extends object> = (value: T[keyof T], key: keyof T) => boolean; | ||
export declare const omitBy: <T extends object>(obj: T, predicate: OmitByPredicate<T>) => Partial<T>; | ||
import type { EmptyObject } from './EmptyObject.ts'; | ||
export type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean; | ||
export declare const omitBy: <T extends EmptyObject>(obj: T, predicate: OmitByPredicate, maxDepth?: number) => Partial<T>; | ||
//# sourceMappingURL=omitBy.d.ts.map |
{ | ||
"name": "@xylabs/object", | ||
"version": "4.4.10", | ||
"version": "4.4.11", | ||
"description": "Primary SDK for using XYO Protocol 2.0", | ||
@@ -32,6 +32,6 @@ "homepage": "https://xyo.network", | ||
"dependencies": { | ||
"@xylabs/assert": "^4.4.10", | ||
"@xylabs/logger": "^4.4.10", | ||
"@xylabs/promise": "^4.4.10", | ||
"@xylabs/typeof": "^4.4.10" | ||
"@xylabs/assert": "^4.4.11", | ||
"@xylabs/logger": "^4.4.11", | ||
"@xylabs/promise": "^4.4.11", | ||
"@xylabs/typeof": "^4.4.11" | ||
}, | ||
@@ -38,0 +38,0 @@ "devDependencies": { |
@@ -1,9 +0,17 @@ | ||
export type OmitByPredicate<T extends object> = (value: T[keyof T], key: keyof T) => boolean | ||
import type { EmptyObject } from './EmptyObject.ts' | ||
import type { JsonObject } from './JsonObject.ts' | ||
export const omitBy = <T extends object>( | ||
export type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean | ||
export const omitBy = <T extends EmptyObject>( | ||
obj: T, | ||
predicate: OmitByPredicate<T>, | ||
predicate: OmitByPredicate, | ||
maxDepth = 1, | ||
): Partial<T> => { | ||
const result: Partial<T> = {} | ||
if (maxDepth <= 0) { | ||
return obj | ||
} | ||
const result: JsonObject = {} | ||
for (const key in obj) { | ||
@@ -13,3 +21,3 @@ if (Object.hasOwn(obj, key)) { | ||
if (!predicate(value, key)) { | ||
result[key] = value | ||
result[key] = ((value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth - 1) : value) as JsonObject | ||
} | ||
@@ -19,3 +27,3 @@ } | ||
return result | ||
return result as T | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115835
991
Updated@xylabs/assert@^4.4.11
Updated@xylabs/logger@^4.4.11
Updated@xylabs/promise@^4.4.11
Updated@xylabs/typeof@^4.4.11