UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

26 lines (25 loc) 644 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.countObjectFields = exports.cloneObject = void 0; /** * * Deep clone an object. * * @param obj Object to clone. * @returns Deep cloned object. */ const cloneObject = (obj) => { return JSON.parse(JSON.stringify(obj)); }; exports.cloneObject = cloneObject; /** * * Count the number of fields in an object. * * @param obj Object to check. * @returns Number of fields in the object. */ const countObjectFields = (obj) => { if (obj != null) return Object.keys(obj)?.length; return 0; }; exports.countObjectFields = countObjectFields;