MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / noEmptyObjectValues

Function noEmptyObjectValues

client/i18n/schema-validation.ts:87–108  ·  view source on GitHub ↗
(
  obj: Record<string, unknown>,
  namespace = ''
)

Source from the content-addressed store, hash-verified

85 * @param {String} namespace String for tracking nested properties
86 */
87const noEmptyObjectValues = (
88 obj: Record<string, unknown>,
89 namespace = ''
90): string[] => {
91 const emptyKeys = [];
92 for (const key of Object.keys(obj)) {
93 const value = obj[key];
94 const field = namespace ? `${namespace}.${key}` : key;
95 if (Array.isArray(value)) {
96 if (!value.length) {
97 emptyKeys.push(field);
98 }
99 } else if (typeof value === 'object') {
100 emptyKeys.push(
101 noEmptyObjectValues(value as Record<string, unknown>, field)
102 );
103 } else if (!value) {
104 emptyKeys.push(field);
105 }
106 }
107 return emptyKeys.flat();
108};
109
110/**
111 * Grab the schema keys once, to avoid overhead of

Callers 1

schemaValidationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected