MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / removeUndefinedFields

Function removeUndefinedFields

test/util.ts:564–589  ·  view source on GitHub ↗
(obj: any)

Source from the content-addressed store, hash-verified

562 }
563
564 function removeUndefinedFields(obj: any): any {
565 if (obj === null) {
566 return undefined;
567 }
568
569 if (Array.isArray(obj)) {
570 return obj.map(removeUndefinedFields);
571 }
572
573 if (typeof obj === "object") {
574 const copy: any = {};
575 for (const [key, value] of Object.entries(obj)) {
576 if (obj[key] !== undefined) {
577 copy[key] = removeUndefinedFields(value);
578 }
579 }
580
581 if (Object.keys(copy).length === 0) {
582 return [];
583 }
584
585 return copy;
586 }
587
588 return obj;
589 }
590
591 return removeUndefinedFields(result);
592 }

Callers 1

executeJsFunction · 0.85

Calls 2

entriesMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected