()
| 285 | }; |
| 286 | |
| 287 | export const stringCodec = < |
| 288 | T extends string | object = string, |
| 289 | >(): Codec<T> => ({ |
| 290 | encode: v => (typeof v === 'string' ? v : JSON.stringify(v)), |
| 291 | decode: v => { |
| 292 | try { |
| 293 | return JSON.parse(v) as T; |
| 294 | } catch { |
| 295 | return v as T; |
| 296 | } |
| 297 | }, |
| 298 | }); |
| 299 | |
| 300 | /** |
| 301 | * Parses a partial WalFormat configuration and returns a complete WalFormat object. |
no outgoing calls