(v: any)
| 1 | import { getSafeJson } from '@openpanel/json'; |
| 2 | |
| 3 | const 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 | |
| 22 | export const parseQueryString = (obj: Record<string, any>): any => { |
| 23 | return Object.fromEntries( |
no test coverage detected