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