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

Function flattenAnObject

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

Source from the content-addressed store, hash-verified

16 * @param {String} namespace Used for property chaining
17 */
18const flattenAnObject = (obj: Record<string, unknown>, namespace = '') => {
19 const flattened: Record<string, unknown> = {};
20 Object.keys(obj).forEach(key => {
21 const value = obj[key];
22 const field = namespace ? `${namespace}.${key}` : key;
23 if (Array.isArray(value)) {
24 flattened[field] = value;
25 } else if (typeof value === 'object') {
26 Object.assign(
27 flattened,
28 flattenAnObject(value as Record<string, unknown>, field)
29 );
30 } else {
31 flattened[field] = value;
32 }
33 });
34 return flattened;
35};
36
37/**
38 * Checks if a translation object is missing keys

Callers 2

schemaValidationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected