MCPcopy Index your code
hub / github.com/cameri/nostream / parseValue

Function parseValue

src/cli/utils/config.ts:76–111  ·  view source on GitHub ↗
(raw: string)

Source from the content-addressed store, hash-verified

74}
75
76export const parseValue = (raw: string): unknown => {
77 const trimmed = raw.trim()
78
79 if (trimmed === 'true') {
80 return true
81 }
82
83 if (trimmed === 'false') {
84 return false
85 }
86
87 if (trimmed === 'null') {
88 return null
89 }
90
91 if (/^-?\d+$/.test(trimmed)) {
92 const asNumber = Number(trimmed)
93 if (Number.isSafeInteger(asNumber)) {
94 return asNumber
95 }
96 }
97
98 if (/^-?\d+n$/.test(trimmed)) {
99 return BigInt(trimmed.slice(0, -1))
100 }
101
102 if ((trimmed.startsWith('{') && trimmed.endsWith('}')) || (trimmed.startsWith('[') && trimmed.endsWith(']'))) {
103 try {
104 return JSON.parse(trimmed)
105 } catch {
106 return raw
107 }
108 }
109
110 return raw
111}
112
113export const parseTypedValue = (raw: string, type: 'inferred' | 'json' = 'inferred'): unknown => {
114 if (type === 'json') {

Callers 2

config.spec.tsFile · 0.90
parseTypedValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected