-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathinterface.ts
119 lines (85 loc) · 2.52 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export interface Position {
readonly offset: number;
readonly line: number;
readonly character: number;
}
export type JsonAstNode = JsonAstNumber
| JsonAstString
| JsonAstIdentifier
| JsonAstArray
| JsonAstObject
| JsonAstConstantFalse
| JsonAstConstantNull
| JsonAstConstantTrue;
export interface JsonAstNodeBase {
readonly start: Position;
readonly end: Position;
readonly text: string;
readonly comments?: (JsonAstComment | JsonAstMultilineComment)[];
}
export interface JsonAstNumber extends JsonAstNodeBase {
readonly kind: 'number';
readonly value: number;
}
export interface JsonAstString extends JsonAstNodeBase {
readonly kind: 'string';
readonly value: string;
}
export interface JsonAstIdentifier extends JsonAstNodeBase {
readonly kind: 'identifier';
readonly value: string;
}
export interface JsonArray extends Array<JsonValue> {}
export interface JsonAstArray extends JsonAstNodeBase {
readonly kind: 'array';
readonly elements: JsonAstNode[];
readonly value: JsonArray;
}
export interface JsonObject {
[prop: string]: JsonValue;
}
export interface JsonAstKeyValue extends JsonAstNodeBase {
readonly kind: 'keyvalue';
readonly key: JsonAstString | JsonAstIdentifier;
readonly value: JsonAstNode;
}
export interface JsonAstObject extends JsonAstNodeBase {
readonly kind: 'object';
readonly properties: JsonAstKeyValue[];
readonly value: JsonObject;
}
export interface JsonAstConstantFalse extends JsonAstNodeBase {
readonly kind: 'false';
readonly value: false;
}
export interface JsonAstConstantNull extends JsonAstNodeBase {
readonly kind: 'null';
readonly value: null;
}
export interface JsonAstConstantTrue extends JsonAstNodeBase {
readonly kind: 'true';
readonly value: true;
}
// Loose mode AST.
export interface JsonAstMultilineComment extends JsonAstNodeBase {
readonly kind: 'multicomment';
readonly content: string;
}
export interface JsonAstComment extends JsonAstNodeBase {
readonly kind: 'comment';
readonly content: string;
}
export type JsonValue = JsonAstNode['value'];
export function isJsonObject(value: JsonValue): value is JsonObject {
return value != null && typeof value === 'object' && !Array.isArray(value);
}
export function isJsonArray(value: JsonValue): value is JsonArray {
return Array.isArray(value);
}