MCPcopy
hub / github.com/lingodotdev/lingo.dev / flattenHints

Function flattenHints

packages/cli/src/cli/loaders/flat.ts:187–226  ·  view source on GitHub ↗
(
  obj: Record<string, any>,
  parentHints: string[] = [],
  parentPath: string = "",
)

Source from the content-addressed store, hash-verified

185}
186
187function flattenHints(
188 obj: Record<string, any>,
189 parentHints: string[] = [],
190 parentPath: string = "",
191): Record<string, string[]> {
192 const result: Record<string, string[]> = {};
193
194 for (const [key, _value] of Object.entries(obj)) {
195 if (_.isObject(_value) && !_.isArray(_value)) {
196 const value = _value as Record<string, any>;
197 const currentHints = [...parentHints];
198 const currentPath = parentPath ? `${parentPath}/${key}` : key;
199
200 // Add this level's hint if it exists
201 if (value.hint && typeof value.hint === "string") {
202 currentHints.push(value.hint);
203 }
204
205 // Process nested objects (excluding the hint property)
206 const nestedObj = _.omit(value, "hint");
207
208 // If this is a leaf node (no nested objects), add to result
209 if (Object.keys(nestedObj).length === 0) {
210 if (currentHints.length > 0) {
211 result[currentPath] = currentHints;
212 }
213 } else {
214 // Recursively process nested objects
215 const nestedComments = flattenHints(
216 nestedObj,
217 currentHints,
218 currentPath,
219 );
220 Object.assign(result, nestedComments);
221 }
222 }
223 }
224
225 return result;
226}

Callers 1

createFlatLoaderFunction · 0.85

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected