( value: string, custom?: CustomParser | undefined, )
| 12 | export type CustomParser = Record<string, (value: any) => unknown>; |
| 13 | |
| 14 | export function parse<T = unknown>( |
| 15 | value: string, |
| 16 | custom?: CustomParser | undefined, |
| 17 | ): T { |
| 18 | const data = JSON.parse(value); |
| 19 | if (!Array.isArray(data)) return unpack([], [], data, custom) as T; |
| 20 | const hydrated = new Array(data.length); |
| 21 | unpack(data, hydrated, 0, custom); |
| 22 | return hydrated[0]; |
| 23 | } |
| 24 | |
| 25 | function unpack( |
| 26 | arr: unknown[], |
no test coverage detected