deno.land / std@0.180.0 / json / _common.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.import type { JsonValue } from "./common.ts";
/** JSON.parse with detailed error message. */export function parse(text: string): JsonValue { try { return JSON.parse(text); } catch (error: unknown) { if (error instanceof Error) { // Truncate the string so that it is within 30 lengths. const truncatedText = 30 < text.length ? `${text.slice(0, 30)}...` : text; throw new (error.constructor as ErrorConstructor)( `${error.message} (parsing: '${truncatedText}')`, ); } throw error; }}
std

Version Info

Tagged at
a year ago