PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / utils / compact-object / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at gutenberg/utils/compact-object/index.js

27 lines 693 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Compact object - remove empty nested objects and undefined values.
3 *
4 * @link https://gist.github.com/Mazuh/8209a608a655f91b9de319872d7a660a
5 *
6 * @param {Object} obj - object to work with.
7 *
8 * @return {Object}
9 */
10 export default function compactObject(obj) {
11 if (typeof obj !== 'object') {
12 return obj;
13 }
14
15 return Object.keys(obj).reduce((accumulator, key) => {
16 const isObject = typeof obj[key] === 'object';
17 const value = isObject ? compactObject(obj[key]) : obj[key];
18 const isEmptyObject = isObject && !Object.keys(value).length;
19
20 if (value === undefined || isEmptyObject) {
21 return accumulator;
22 }
23
24 return Object.assign(accumulator, { [key]: value });
25 }, {});
26 }
27