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

Function coerceValue

apps/sim/executor/utils/start-block.ts:230–264  ·  view source on GitHub ↗
(type: string | null | undefined, value: unknown)

Source from the content-addressed store, hash-verified

228}
229
230export function coerceValue(type: string | null | undefined, value: unknown): unknown {
231 if (value === undefined || value === null) {
232 return value
233 }
234
235 switch (type) {
236 case 'string':
237 return typeof value === 'string' ? value : String(value)
238 case 'number': {
239 if (typeof value === 'number') return value
240 const parsed = Number(value)
241 return Number.isNaN(parsed) ? value : parsed
242 }
243 case 'boolean': {
244 if (typeof value === 'boolean') return value
245 if (value === 'true' || value === '1' || value === 1) return true
246 if (value === 'false' || value === '0' || value === 0) return false
247 return value
248 }
249 case 'object':
250 case 'array': {
251 if (typeof value === 'string') {
252 try {
253 const parsed = JSON.parse(value)
254 return parsed
255 } catch {
256 return value
257 }
258 }
259 return value
260 }
261 default:
262 return value
263 }
264}
265
266interface DerivedInputResult {
267 structuredInput: Record<string, unknown>

Callers 3

buildFieldsSampleFunction · 0.90
buildInputFormatInputFunction · 0.90
deriveInputFromFormatFunction · 0.70

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected