From 4fc34c5b79826baf59fd4f805aa22081d22adcb6 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:31:34 +0300 Subject: [PATCH] Editor: Remove unused setNestedValue (#63620) Co-authored-by: tyxla Co-authored-by: Mamaduka --- packages/editor/src/utils/set-nested-value.js | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 packages/editor/src/utils/set-nested-value.js diff --git a/packages/editor/src/utils/set-nested-value.js b/packages/editor/src/utils/set-nested-value.js deleted file mode 100644 index ec684e751cd041..00000000000000 --- a/packages/editor/src/utils/set-nested-value.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Sets the value at path of object. - * If a portion of path doesn’t exist, it’s created. - * Arrays are created for missing index properties while objects are created - * for all other missing properties. - * - * This function intentionally mutates the input object. - * - * Inspired by _.set(). - * - * @see https://lodash.com/docs/4.17.15#set - * - * @todo Needs to be deduplicated with its copy in `@wordpress/core-data`. - * - * @param {Object} object Object to modify - * @param {Array} path Path of the property to set. - * @param {*} value Value to set. - */ -export default function setNestedValue( object, path, value ) { - if ( ! object || typeof object !== 'object' ) { - return object; - } - - path.reduce( ( acc, key, idx ) => { - if ( acc[ key ] === undefined ) { - if ( Number.isInteger( path[ idx + 1 ] ) ) { - acc[ key ] = []; - } else { - acc[ key ] = {}; - } - } - if ( idx === path.length - 1 ) { - acc[ key ] = value; - } - return acc[ key ]; - }, object ); - - return object; -}