| 313 | ) |
| 314 | |
| 315 | export const stringifyJson = ( |
| 316 | data: Json, |
| 317 | ctx?: Traversal |
| 318 | ): string | ArkError => { |
| 319 | try { |
| 320 | const result = JSON.stringify(data) |
| 321 | if (result !== undefined) return result |
| 322 | if (!ctx) throw new TypeError("Value is not JSON-serializable") |
| 323 | return ctx.error(jsonStringifyError) |
| 324 | } catch (e) { |
| 325 | if (!ctx || !(e instanceof TypeError)) throw e |
| 326 | return ctx.error({ ...jsonStringifyError, cause: e }) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | // inverses of parse keywords, which arktype/codecs encodes with |
| 331 | export const writeIsoDate = (date: Date): string => { |