(obj: Record<string, unknown>, namespace = '')
| 16 | * @param {String} namespace Used for property chaining |
| 17 | */ |
| 18 | const 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 |
no outgoing calls
no test coverage detected