MCPcopy Create free account
hub / github.com/TanStack/db / convert

Function convert

packages/trailbase-db-collection/src/trailbase.ts:53–68  ·  view source on GitHub ↗
(
  conversions: Conversions<InputType, OutputType>,
  input: InputType,
)

Source from the content-addressed store, hash-verified

51 RequiredConversions<InputType, OutputType>
52
53function convert<
54 InputType extends ShapeOf<OutputType> & Record<string, unknown>,
55 OutputType extends ShapeOf<InputType>,
56>(
57 conversions: Conversions<InputType, OutputType>,
58 input: InputType,
59): OutputType {
60 const c = conversions as Record<string, Conversion<InputType, OutputType>>
61
62 return Object.fromEntries(
63 Object.keys(input).map((k: string) => {
64 const value = input[k]
65 return [k, c[k]?.(value as any) ?? value]
66 }),
67 ) as OutputType
68}
69
70function convertPartial<
71 InputType extends ShapeOf<OutputType> & Record<string, unknown>,

Callers 2

parseFunction · 0.85
serialInsFunction · 0.85

Calls 2

mapMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected