UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

27 lines (23 loc) 816 B
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; // Utility to return a deep clone of a nested object or array. const deepCloneObject = objectToClone => { // Return the value if objectToClone is not an object if (typeof objectToClone !== 'object' || objectToClone === null) { return objectToClone; } // Create a new array/object to hold the values const clonedObject = Array.isArray(objectToClone) ? [] : {}; for (const key in objectToClone) { const value = objectToClone[key]; // Recursively check for nested objects/arrays clonedObject[key] = deepCloneObject(value); } return clonedObject; }; exports.deepCloneObject = deepCloneObject;