UNPKG

3.88 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { BaseException } from '../exception';
9import { JsonAstNode, JsonValue, Position } from './interface';
10export declare class JsonException extends BaseException {
11}
12/**
13 * A character was invalid in this context.
14 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
15 */
16export declare class InvalidJsonCharacterException extends JsonException {
17 invalidChar: string;
18 line: number;
19 character: number;
20 offset: number;
21 constructor(context: JsonParserContext);
22}
23/**
24 * More input was expected, but we reached the end of the stream.
25 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
26 */
27export declare class UnexpectedEndOfInputException extends JsonException {
28 constructor(_context: JsonParserContext);
29}
30/**
31 * An error happened within a file.
32 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
33 */
34export declare class PathSpecificJsonException extends JsonException {
35 path: string;
36 exception: JsonException;
37 constructor(path: string, exception: JsonException);
38}
39/**
40 * Context passed around the parser with information about where we currently are in the parse.
41 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
42 */
43export interface JsonParserContext {
44 position: Position;
45 previous: Position;
46 readonly original: string;
47 readonly mode: JsonParseMode;
48}
49/**
50 * The Parse mode used for parsing the JSON string.
51 */
52export declare enum JsonParseMode {
53 Strict = 0,
54 CommentsAllowed = 1,
55 SingleQuotesAllowed = 2,
56 IdentifierKeyNamesAllowed = 4,
57 TrailingCommasAllowed = 8,
58 HexadecimalNumberAllowed = 16,
59 MultiLineStringAllowed = 32,
60 LaxNumberParsingAllowed = 64,
61 NumberConstantsAllowed = 128,
62 Default = 0,
63 Loose = 255,
64 Json = 0,
65 Json5 = 255
66}
67/**
68 * Parse the JSON string and return its AST. The AST may be losing data (end comments are
69 * discarded for example, and space characters are not represented in the AST), but all values
70 * will have a single node in the AST (a 1-to-1 mapping).
71 *
72 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
73 * @param input The string to use.
74 * @param mode The mode to parse the input with. {@see JsonParseMode}.
75 * @returns {JsonAstNode} The root node of the value of the AST.
76 */
77export declare function parseJsonAst(input: string, mode?: JsonParseMode): JsonAstNode;
78/**
79 * Options for the parseJson() function.
80 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
81 */
82export interface ParseJsonOptions {
83 /**
84 * If omitted, will only emit errors related to the content of the JSON. If specified, any
85 * JSON errors will also include the path of the file that caused the error.
86 */
87 path?: string;
88}
89/**
90 * Parse a JSON string into its value. This discards the AST and only returns the value itself.
91 *
92 * If a path option is pass, it also absorbs JSON parsing errors and return a new error with the
93 * path in it. Useful for showing errors when parsing from a file.
94 *
95 * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
96 * @param input The string to parse.
97 * @param mode The mode to parse the input with. {@see JsonParseMode}.
98 * @param options Additional optinos for parsing.
99 * @returns {JsonValue} The value represented by the JSON string.
100 */
101export declare function parseJson(input: string, mode?: JsonParseMode, options?: ParseJsonOptions): JsonValue;