MCPcopy
hub / github.com/puckeditor/puck / encodeEmptyObjects

Function encodeEmptyObjects

packages/core/lib/data/flatten-node.ts:14–32  ·  view source on GitHub ↗
(props: Record<string, any> = {})

Source from the content-addressed store, hash-verified

12const emptyObjectStr = "__puck_{}";
13
14function encodeEmptyObjects(props: Record<string, any> = {}) {
15 const result: Record<string, any> = {};
16
17 for (const key in props) {
18 if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
19
20 const val = props[key];
21
22 if (Array.isArray(val) && val.length === 0) {
23 result[key] = emptyArrayStr;
24 } else if (isPureObject(val) && Object.keys(val).length === 0) {
25 result[key] = emptyObjectStr;
26 } else {
27 result[key] = val;
28 }
29 }
30
31 return result;
32}
33
34function decodeEmptyObjects(props: Record<string, any> = {}) {
35 const result: Record<string, any> = {};

Callers 1

flattenNodeFunction · 0.85

Calls 1

isPureObjectFunction · 0.85

Tested by

no test coverage detected