MCPcopy Index your code
hub / github.com/simstudioai/sim / parseCsvOrJson

Function parseCsvOrJson

apps/sim/tools/zoominfo/utils.ts:50–71  ·  view source on GitHub ↗
(value: unknown, fieldName: string)

Source from the content-addressed store, hash-verified

48}
49
50export function parseCsvOrJson(value: unknown, fieldName: string): string[] | undefined {
51 if (value === undefined || value === null) return undefined
52 if (Array.isArray(value)) return value.map(String)
53 if (typeof value !== 'string') return undefined
54 const trimmed = value.trim()
55 if (!trimmed) return undefined
56 if (trimmed.startsWith('[')) {
57 try {
58 const parsed = JSON.parse(trimmed)
59 if (!Array.isArray(parsed)) {
60 throw new Error(`${fieldName} JSON must be an array of strings`)
61 }
62 return parsed.map(String)
63 } catch (error) {
64 throw new Error(`${fieldName} must be valid JSON: ${getErrorMessage(error)}`)
65 }
66 }
67 return trimmed
68 .split(',')
69 .map((s) => s.trim())
70 .filter(Boolean)
71}
72
73export function toNumberOrUndefined(value: unknown): number | undefined {
74 if (value === undefined || value === null || value === '') return undefined

Callers 6

search_news.tsFile · 0.90
enrich_contacts.tsFile · 0.90
search_intent.tsFile · 0.90
toCsvStringOrUndefinedFunction · 0.85

Calls 2

getErrorMessageFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected