This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
129 lines (124 loc) · 3.7 KB
/
index.d.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
120
121
122
123
124
125
126
127
128
129
/// <reference types="node" />
import { Writable } from 'stream';
declare enum NodeType {
None = 0,
Scalar = 1,
List = 2,
Dict = 3
}
declare type Dict$1 = {
[key: string]: Node<List$1 | Dict$1 | Scalar>;
};
declare type Scalar = string;
declare type List$1 = Array<Node<List$1 | Dict$1 | Scalar>>;
declare class Node<NodeValueType> {
type: NodeType;
value: NodeValueType;
constructor(type: NodeType, val: NodeValueType);
}
declare class Emitter {
stream: string;
protected containsSpecials(value: string): boolean;
emitNode(node: Node<Dict$1 | List$1 | Scalar>, os: Writable, indent?: number, isLast?: boolean): void;
emitConfigValue(value: ConfigValue, indent?: number, isLast?: boolean, commas?: boolean, apostrophes?: boolean): void;
}
declare enum TokenType {
ArrayStart = 0,
ArrayEnd = 1,
DictStart = 2,
DictEnd = 3,
Key = 4,
Scalar = 5
}
declare enum ErrorType {
KeyExpected = 0,
InvalidToken = 1,
UnexpectedEOF = 2
}
declare class Token {
type: TokenType;
value: string;
pos: number;
line: number;
col: number;
constructor(_type: TokenType, _value?: string, _pos?: number, _line?: number, _col?: number);
}
declare class Parser {
tokens: Token[];
buffer: string;
readPos: number;
line: number;
column: number;
tokIdx: number;
filePath: string;
constructor(content: string, filePath?: string);
parse(): Node<Dict$1>;
protected unread(): number;
protected peek(offset?: number): string;
protected get(): string;
protected skip(n?: number): void;
protected skipNextToken(): void;
protected tokenize(): void;
protected createParseError(type: ErrorType, token: Token | number, col?: number): string;
protected parseToken(): Node<Dict$1 | List$1 | Scalar>;
}
declare type Dict = {
[key: string]: ConfigValue;
};
declare type List = Array<ConfigValue>;
declare type ConfigValue = string | boolean | number | Dict | List;
declare class Config {
protected parser: Parser;
protected emitter: Emitter;
protected content: string;
config: Dict;
fileName: string;
/**
*
* @param {string} fileName
* @param {Object} predefinedValues [optional]
*/
constructor(fileName: string, preDefines?: Object);
protected existsFile(path: string): boolean;
protected createFile(path: string): void;
protected loadFile(path: string): void;
protected isNumber(value: string): boolean;
protected isFloat(value: string): boolean;
protected parseNode(node: Node<Dict$1 | List$1 | Scalar>): ConfigValue;
protected parse(): void;
/**
* Get a config value with unknown type, slower than GetOfType
* @param {string} key
* @returns {ConfigValue}
*/
get(key: string): ConfigValue;
/**
* Set a config value
* @param {string} key
* @param {ConfigValue} value
*/
set(key: string, value: ConfigValue): void;
/**
* Save the current changes to the opened file
* @param {boolean} useCommas [default: true]
* @param {boolean} useApostrophe [default: true]
*
* @returns {Promise<void>}
*/
save(useCommas?: boolean, useApostrophe?: boolean): Promise<void>;
/**
* Get a config value with known type, faster than normal Get
* @param {string} key
* @param {ValueType} type
* @returns {ReturnValueType}
*/
getOfType<ReturnValueType>(key: string): ReturnValueType;
/**
* Serialize config
* @param {boolean} useCommas [default: true]
* @param {boolean} useApostrophe [default: true]
* @returns {string}
*/
serialize(useCommas?: boolean, useApostrophe?: boolean): string;
}
export { Config, ConfigValue, Dict, List };