-
Notifications
You must be signed in to change notification settings - Fork 6
/
config-ini.d.ts
205 lines (183 loc) · 7.88 KB
/
config-ini.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/// <reference types="typescript" />
export interface Section {
name: string;
options: Array<any>;
}
/*
* Create a ini file parser, the format of ini file could be found at
* https://en.wikipedia.org/wiki/INI_file
*
* Duplicated sections will cause exception, duplicated options will be
* ignored and only the first one will take effect.
*
* @constructor
* @param {string} delimiter, the line delimiter which is used to separate the lines
* @return {ConfigIniParser} a ConfigIniParser object
*/
export declare class ConfigIniParser {
constructor(delimiter?: string);
/*
* Create a new section, if the section is already contain in the structure then
* a duplicated section exception will be thrown
* @param {string} sectionName a section name defined in ini [section name]
* @return {object} the created section object
*/
addSection(sectionName: string): Section;
/*
* Get a specific option value
* @param {string|null} sectionName the name defined in ini `[section name]`
* @param {string} optionName the name defined in ini `option-name = option-value`
* @param {object} defaultValue optional default value to be used when the option does not exist. If it is not provided and the value does not exist, then an exception is thrown.
* @return {string/object} the string value of the option or defaultValue
*/
get(sectionName: string|null, optionName: string, defaultValue?: any): any;
/*
* Get a option from the default section. This is a convenient method when get the
* option from the default section.
* @param {string} optionName the name defined in ini `option-name = option-value`
* @param {object} defaultValue optional default value to be used when the option does not exist. If it is not provided and the value does not exist, then an exception is thrown.
* @return {string/object} the string value of the option or defaultValue
*/
getOptionFromDefaultSection(optionName: string, defaultValue?:any):any;
/*
* Convert the option value to boolean, if the value is a number then return true if it is
* not equal to 0; if the value is string and which value is "true"/"false" then will be converted
* to bool, return true if it is "true";
* @param {string|null} sectionName, the name of the section. If null the default section will
* be used.
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {boolean} indicate the value is true or false
*/
getBoolean(sectionName: string|null, optionName: string): boolean;
/*
* Get the option from the default section and convert the value to boolean, if the
* value is a number then return true if it is
* not equal to 0; if the value is string and which value is "true"/"false" then
* will be converted to bool, return true if it is "true";
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {boolean} indicate the value is true or false
*/
getBooleanFromDefaultSection(optionName: string): boolean;
/*
* Convert a option value to number
* @param {string|null} sectionName, the name of the section. If null the default section will
* be used.
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {number/NaN} number or NaN
*/
getNumber(sectionName: string|null, optionName: string): number;
/*
* Get the option from the default section and convert the value to number
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {number/NaN} number or NaN
*/
getNumberFromDefaultSection(optionName: string): number;
/*
* Check a specify section is exist or not
* @param {string} sectionName the name of the section
* @return {boolean} to indicate the result
*/
isHaveSection(sectionName: string): boolean;
/*
* Check an option is exist in a section or not. If sectionName is null then will check
* the default section
* @param {string|null} sectionName, the name of the section. If null the default section will
* be used.
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {boolean} boolean
*/
isHaveOption(sectionName: string|null, optionName: string): boolean;
/*
* Check an option is exist in the default section
* @param {string} optionName the name defined in ini `option-name = option-value`
* @return {boolean} boolean
*/
isHaveOptionInDefaultSection(optionName: string): boolean;
/*
* Get key/value pair of the options in the specify section. If sectionName is null
* then will return the pairs from default section
* @param {string|null} sectionName? a section name defined in ini [section name]
* @return {Array.} an array contain several sub arrays which are composed by optionName,
* optionValue. The returned array looks like [[optionName0, optionValue0], ...]
*/
items(sectionName?: string|null): Array<Array<any>>;
/*
* Get all the option names from the specify section if sectionName is null or empty
* then will return options from the default section
* @param {string|null} sectionName a section name defined in ini [section name]
* @return {Array.} an string array contain all the option names
*/
options(sectionName?: string|null): Array<string>;
/*
* Remove the specify option from the section if the option exist then remove it
* and return true else return false
*
* @param {string|null} sectionName a section name defined in ini [section name]. if null
* the default section will be used.
* @param {string} optionName, name of the option
* @return, boolean, indicate the operation is success or not
*/
removeOption(sectionName: string|null, optionName: string): boolean;
/*
* Remove the specify option from the default section if the option exist then remove it
* and return true else return false
*
* @param {string} optionName, name of the option
* @return, boolean, indicate the operation is success or not
*/
removeOptionFromDefaultSection(optionName: string): boolean;
/*
* Remove the specify section if the section exist then remove it
* and return true else return false
*
* @param {string|null} sectionName?, if null or empty the default section will be removed
* @return {boolean}
*/
removeSection(sectionName?: string|null): boolean;
/*
* Get all the section names from the ini content
* @return {Array.} an string array
*/
sections(): Array<string>;
/*
* Set a option value, if the option is not exist then it will be added to the section.
* If the section is not exist an errorNoSection will be thrown.
* @param {string|null} sectionName, string
* @param {string} optionName, string
* @param {string} value, a value should be able to converted to string
* @return {object} parser object itself
*/
set(
sectionName: string|null,
optionName: string,
value: string
): ConfigIniParser;
/*
* Set a option value to the default section. if the option is not exist then
* it will be created and added to the default section.
* @param {string} optionName, string
* @param {string} value, a value should be able to converted to string
* @return {object} parser object itself
*/
setOptionInDefaultSection(optionName: string, value:string):ConfigIniParser;
/*
* Convert the configuration content to strings the line will the separate with the
* given line delimiter. A empty line will be added between each section
*
* @return {string} the content of configuration
*/
stringify(delimiter?: string): string;
/*
* Parse a given ini content
* @param {string} iniContent, a string normally separated with \r\n or \n
* @return {ConfigIniParser} the parser instance itself
*/
parse(iniContent: string): ConfigIniParser;
static readonly Errors: {
readonly Error: Error;
readonly ErrorNoSection: Error;
readonly ErrorNoOption: Error;
readonly ErrorDuplicateSectionError: Error;
readonly ErrorCallParseMultipleTimes: Error;
};
}