UNPKG

@daysnap/utils

Version:
43 lines (40 loc) 835 B
import { isEmpty } from "./chunk-YGV2UKBN.js"; import { isEmptyArray } from "./chunk-ELR2DZ56.js"; import { isEmptyObject } from "./chunk-GVYBTJDA.js"; import { isFunction } from "./chunk-WCZPEH7E.js"; import { isObject } from "./chunk-XCSSSEK2.js"; // src/filterEmptyValue.ts function filterEmptyValue(obj, expand = false) { return Object.entries(obj).reduce( (res, [key, value]) => { if (isFunction(expand) && expand(key, value)) { res[key] = value; } else { if (!isEmpty(value)) { if (expand) { if (!isEmptyArray(value) && !(isObject(value) && isEmptyObject(value))) { res[key] = value; } } else { res[key] = value; } } } return res; }, {} ); } export { filterEmptyValue };