MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / parseScalar

Function parseScalar

apps/api/src/utils/parse-zod-query-string.ts:3–20  ·  view source on GitHub ↗
(v: any)

Source from the content-addressed store, hash-verified

1import { getSafeJson } from '@openpanel/json';
2
3const parseScalar = (v: any): any => {
4 if (Array.isArray(v)) return v.map(parseScalar);
5 if (typeof v === 'object' && v !== null) return parseQueryString(v);
6 if (
7 typeof v === 'string' &&
8 /^-?[0-9]+(\.[0-9]+)?$/i.test(v) &&
9 !Number.isNaN(Number.parseFloat(v))
10 )
11 return Number.parseFloat(v);
12 if (v === 'true') return true;
13 if (v === 'false') return false;
14 if (typeof v === 'string') {
15 const json = getSafeJson(v);
16 if (json !== null) return json;
17 return v;
18 }
19 return null;
20};
21
22export const parseQueryString = (obj: Record<string, any>): any => {
23 return Object.fromEntries(

Callers 1

parseQueryStringFunction · 0.85

Calls 3

getSafeJsonFunction · 0.90
parseQueryStringFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected