MCPcopy Create free account
hub / github.com/Devographics/Monorepo / parseLiteral

Function parseLiteral

api/src/graphql/string_or_array.ts:29–46  ·  view source on GitHub ↗
(ast: ValueNode)

Source from the content-addressed store, hash-verified

27 throw new TypeError('Value must be a string, a float, or an array of strings and/or floats')
28 },
29 parseLiteral(ast: ValueNode): string | number | (string | number)[] {
30 if (ast.kind === Kind.STRING) {
31 return ast.value
32 } else if (ast.kind === Kind.FLOAT) {
33 return parseFloat(ast.value)
34 } else if (ast.kind === Kind.LIST) {
35 const values = ast.values.map(valueNode => {
36 if (valueNode.kind === Kind.STRING) {
37 return valueNode.value
38 } else if (valueNode.kind === Kind.FLOAT) {
39 return parseFloat(valueNode.value)
40 }
41 throw new TypeError('All elements in the array must be strings or floats')
42 })
43 return values
44 }
45 throw new TypeError('Value must be a string, a float, or an array of strings and/or floats')
46 }
47})
48
49export default StringOrFloatOrArray

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected