MCPcopy
hub / github.com/virattt/dexter / stripFieldsDeep

Function stripFieldsDeep

src/tools/finance/api.ts:15–41  ·  view source on GitHub ↗
(value: unknown, fields: readonly string[])

Source from the content-addressed store, hash-verified

13 * This reduces token usage while preserving the financial metrics needed for analysis.
14 */
15export function stripFieldsDeep(value: unknown, fields: readonly string[]): unknown {
16 const fieldsToStrip = new Set(fields);
17
18 function walk(node: unknown): unknown {
19 if (Array.isArray(node)) {
20 return node.map(walk);
21 }
22
23 if (!node || typeof node !== 'object') {
24 return node;
25 }
26
27 const record = node as Record<string, unknown>;
28 const cleaned: Record<string, unknown> = {};
29
30 for (const [key, child] of Object.entries(record)) {
31 if (fieldsToStrip.has(key)) {
32 continue;
33 }
34 cleaned[key] = walk(child);
35 }
36
37 return cleaned;
38 }
39
40 return walk(value);
41}
42
43function getApiKey(): string {
44 return process.env.FINANCIAL_DATASETS_API_KEY || '';

Callers 4

insider_trades.tsFile · 0.85
segments.tsFile · 0.85
key-ratios.tsFile · 0.85
fundamentals.tsFile · 0.85

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected