@ygracs/xobj-lib-js 0.2.9-b.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/xObj-lib.d.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  import type { EvalKeyNameError } from "./xObj-errors";
2
+ /**
3
+ * An error description of a value check ops on fail.
4
+ */
5
+ export type IEvalKeyNameReasonOnFail = {
6
+ /**
7
+ * - message ID
8
+ */
9
+ code: string;
10
+ /**
11
+ * - message text
12
+ */
13
+ msg: string;
14
+ };
2
15
  /**
3
16
  * A result of a value check ops.
4
17
  */
@@ -19,7 +32,7 @@ export type IEvalKeyNameOptions = {
19
32
  /**
20
33
  * - a flag to accept only a non-empty string values
21
34
  */
22
- onlyNES?: boolean | undefined;
35
+ onlyNES?: boolean;
23
36
  };
24
37
  /**
25
38
  * A result of `evalKeyName` function if succeed
@@ -45,7 +58,7 @@ export type IEvalKeyNameResultOnFail = {
45
58
  /**
46
59
  * - reason of fail
47
60
  */
48
- value: RVAL_reason;
61
+ value: IEvalKeyNameReasonOnFail;
49
62
  };
50
63
  /**
51
64
  * A result of `evalKeyName` function
@@ -64,6 +77,24 @@ export type VCOR_evalkname = {
64
77
  */
65
78
  value: string | RVAL_reason;
66
79
  };
80
+ /**
81
+ * Some conditions applied to an element as a result of an element name pattern
82
+ * evaluation ops.
83
+ */
84
+ export type XObjENameDescrConditions = {
85
+ /**
86
+ * - element name
87
+ */
88
+ name: any;
89
+ /**
90
+ * - element type
91
+ */
92
+ type: any;
93
+ /**
94
+ * - some value
95
+ */
96
+ value?: any;
97
+ };
67
98
  /**
68
99
  * A result of an element name pattern evaluation ops.
69
100
  */
@@ -79,7 +110,7 @@ export type XObjENameDescr = {
79
110
  /**
80
111
  * - some conditions applied to an element
81
112
  */
82
- conditions: object | null;
113
+ conditions: XObjENameDescrConditions | null;
83
114
  };
84
115
  /**
85
116
  * A result of an xObj modification ops
@@ -111,190 +142,198 @@ export type OPT_inselops_S = {
111
142
  };
112
143
 
113
144
  /**
114
- * Clears a given node
115
- * @throws {TypeError} if `node`-param is not an object or array
116
- */
117
- export function clearXObjNode(node: object | object[]): boolean;
118
- /**
119
- * Extracts a parameter 'AS IS' from a given object.
120
- * @throws {TypeError} if first param is not an object
121
- * @throws {EvalKeyNameError} if second param is not valid identifier
122
- */
123
- export function readXObjParamRaw(obj: object, key?: string): any;
124
- /**
125
- * Extracts a parameter from a given object and returns it as a string.
126
- * @throws {TypeError} if first param is not an object
145
+ * Adds an element addressed by its key to a given object.
146
+ * @since 0.3.0
147
+ * @throws {TypeError} if `obj` param is not an object
148
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
127
149
  */
128
- export function readXObjParam(obj: object, key?: string): string;
150
+ export function addXObjElementEx(obj: object, name: string): RVAL_emodif;
129
151
  /**
130
152
  * Extracts a parameter from a given object and returns it as a boolean.
131
- * @throws {TypeError} if first param is not an object
153
+ * @throws {TypeError} if `obj` param is not an object
132
154
  */
133
155
  export function readXObjParamAsBool(obj: object, defValue?: boolean, key?: string): boolean;
134
156
  /**
135
157
  * Extracts a parameter from a given object and returns it as a number.
136
- * @throws {TypeError} if first param is not an object
158
+ * @throws {TypeError} if `obj` param is not an object
137
159
  */
138
160
  export function readXObjParamAsNum(obj: object, defValue?: number, key?: string): number;
139
- /**
140
- * Extracts a parameter from a given object and returns it as a string.
141
- * @throws {TypeError} if first param is not an object
142
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
143
- */
144
- export function readXObjParamEx(obj: object, opt?: object, key?: string): string;
145
161
  /**
146
162
  * Extracts a parameter from a given object and returns it as 'index' value.
147
- * @throws {TypeError} if first param is not an object
163
+ * @throws {TypeError} if `obj` param is not an object
148
164
  */
149
165
  export function readXObjParamAsIndex(obj: object, key?: string): number;
150
- /**
151
- * Writes a parameter 'AS IS' into a given object.
152
- * @throws {TypeError} if first param is not an object
153
- * @throws {EvalKeyNameError} if third param is not valid identifier
154
- */
155
- export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
156
- /**
157
- * Tries to convert a given value to a string and writes it as a parameter
158
- * into a given object.
159
- * @throws {TypeError} if first param is not an object
160
- */
161
- export function writeXObjParam(obj: object, value: any, key?: string): boolean;
162
166
  /**
163
167
  * Tries to convert a given value to a boolean and writes it as a parameter
164
168
  * into a given object.
165
- * @throws {TypeError} if first param is not an object
169
+ * @throws {TypeError} if `obj` param is not an object
166
170
  */
167
171
  export function writeXObjParamAsBool(obj: object, value: any, defValue?: boolean, key?: string): boolean;
168
172
  /**
169
173
  * Tries to convert a given value to a number and writes it as a parameter
170
174
  * into a given object.
171
- * @throws {TypeError} if first param is not an object
175
+ * @throws {TypeError} if `obj` param is not an object
172
176
  */
173
177
  export function writeXObjParamAsNum(obj: object, value: any, defValue?: number, key?: string): boolean;
174
178
  /**
175
179
  * Tries to convert a given value into an 'index' value and writes it
176
180
  * as a parameter into a given object.
177
- * @throws {TypeError} if first param is not an object
181
+ * @throws {TypeError} if `obj` param is not an object
178
182
  */
179
183
  export function writeXObjParamAsIndex(obj: object, value: any, key?: string): boolean;
180
- /**
181
- * Tries to convert a given value to a string and writes it
182
- * as a parameter into a given object.
183
- * @throws {TypeError} if first param is not an object
184
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
185
- */
186
- export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: string): boolean;
187
- /**
188
- * Extracts an attribute 'AS IS' from a given object.
189
- * @throws {TypeError} if first param is not an object
190
- * @throws {EvalKeyNameError} if second param is not valid identifier
191
- */
192
- export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
193
- /**
194
- * Extracts an attribute from a given object and returns it as a string.
195
- * @throws {TypeError} if first param is not an object
196
- */
197
- export function readXObjAttr(obj: object, attr: string, key?: string): string;
198
184
  /**
199
185
  * Extracts an attribute from a given object and returns it as a boolean.
200
- * @throws {TypeError} if first param is not an object
186
+ * @throws {TypeError} if `obj` param is not an object
201
187
  */
202
188
  export function readXObjAttrAsBool(obj: object, attr: string, defValue?: boolean, key?: string): boolean;
203
189
  /**
204
190
  * Extracts an attribute from a given object and returns it as a number.
205
191
  * @returns {number}
206
- * @throws {TypeError} if first param is not an object
192
+ * @throws {TypeError} if `obj` param is not an object
207
193
  */
208
194
  export function readXObjAttrAsNum(obj: object, attr: string, defValue?: number, key?: string): number;
209
- /**
210
- * Extracts an attribute from a given object and returns it as a string.
211
- * @throws {TypeError} if first param is not an object
212
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
213
- */
214
- export function readXObjAttrEx(obj: object, attr: string, opt?: object, key?: string): string;
215
195
  /**
216
196
  * Extracts an attribute from a given object and returns it as 'index' value.
217
- * @throws {TypeError} if first param is not an object
197
+ * @throws {TypeError} if `obj` param is not an object
218
198
  */
219
199
  export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): number;
220
- /**
221
- * Writes a parameter into a given object.
222
- * @throws {TypeError} if first param is not an object
223
- * @throws {EvalKeyNameError} if second param is not valid identifier
224
- */
225
- export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
226
- /**
227
- * Tries to convert a given value to a string and writes it as an attribute
228
- * into a given object.
229
- * @throws {TypeError} if first param is not an object
230
- */
231
- export function writeXObjAttr(obj: object, attr: string, value: any, key?: string): boolean;
232
200
  /**
233
201
  * Tries to convert a given value to a boolean and writes it as an attribute
234
202
  * into a given object.
235
- * @throws {TypeError} if first param is not an object
203
+ * @throws {TypeError} if `obj` param is not an object
236
204
  */
237
205
  export function writeXObjAttrAsBool(obj: object, attr: string, value: any, defValue?: boolean, key?: string): boolean;
238
206
  /**
239
207
  * Tries to convert a given value to a number and writes it as an attribute
240
208
  * into a given object.
241
- * @throws {TypeError} if first param is not an object
209
+ * @throws {TypeError} if `obj` param is not an object
242
210
  */
243
211
  export function writeXObjAttrAsNum(obj: object, attr: string, value: any, defValue?: number, key?: string): boolean;
244
212
  /**
245
213
  * Tries to convert a given value into an 'index' value and writes it
246
214
  * as an attribute into a given object.
247
- * @throws {TypeError} if first param is not an object
215
+ * @throws {TypeError} if `obj` param is not an object
248
216
  */
249
217
  export function writeXObjAttrAsIndex(obj: object, attr: string, value: any, key?: string): boolean;
218
+ /**
219
+ * Clears a given node
220
+ * @throws {TypeError} if `node`-param is not an object or array
221
+ */
222
+ export function clearXObjNode(node: object | object[]): boolean;
223
+ /**
224
+ * Extracts a parameter 'AS IS' from a given object.
225
+ * @throws {TypeError} if `obj` param is not an object
226
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
227
+ */
228
+ export function readXObjParamRaw(obj: object, key?: string): any;
229
+ /**
230
+ * Extracts a parameter from a given object and returns it as a string.
231
+ * @throws {TypeError} if `obj` param is not an object
232
+ */
233
+ export function readXObjParam(obj: object, key?: string): string;
234
+ /**
235
+ * Extracts a parameter from a given object and returns it as a string.
236
+ * @throws {TypeError} if `obj` param is not an object
237
+ * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
238
+ */
239
+ export function readXObjParamEx(obj: object, opt?: object, key?: string): string;
240
+ /**
241
+ * Writes a parameter 'AS IS' into a given object.
242
+ * @throws {TypeError} if `obj` param is not an object
243
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
244
+ */
245
+ export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
246
+ /**
247
+ * Tries to convert a given value to a string and writes it as a parameter
248
+ * into a given object.
249
+ * @throws {TypeError} if `obj` param is not an object
250
+ */
251
+ export function writeXObjParam(obj: object, value: any, key?: string): boolean;
252
+ /**
253
+ * Tries to convert a given value to a string and writes it
254
+ * as a parameter into a given object.
255
+ * @throws {TypeError} if `obj` param is not an object
256
+ * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
257
+ */
258
+ export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: string): boolean;
259
+ /**
260
+ * Extracts an attribute 'AS IS' from a given object.
261
+ * @throws {TypeError} if `obj` param is not an object
262
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
263
+ */
264
+ export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
265
+ /**
266
+ * Extracts an attribute from a given object and returns it as a string.
267
+ * @throws {TypeError} if `obj` param is not an object
268
+ */
269
+ export function readXObjAttr(obj: object, attr: string, key?: string): string;
270
+ /**
271
+ * Extracts an attribute from a given object and returns it as a string.
272
+ * @throws {TypeError} if `obj` param is not an object
273
+ * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
274
+ */
275
+ export function readXObjAttrEx(obj: object, attr: string, opt?: object, key?: string): string;
276
+ /**
277
+ * Writes a parameter into a given object.
278
+ * @throws {TypeError} if `obj` param is not an object
279
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
280
+ */
281
+ export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
282
+ /**
283
+ * Tries to convert a given value to a string and writes it as an attribute
284
+ * into a given object.
285
+ * @throws {TypeError} if `obj` param is not an object
286
+ */
287
+ export function writeXObjAttr(obj: object, attr: string, value: any, key?: string): boolean;
250
288
  /**
251
289
  * Tries to convert a given value to a string and writes it as an attribute
252
290
  * into a given object.
253
- * @throws {TypeError} if first param is not an object
291
+ * @throws {TypeError} if `obj` param is not an object
254
292
  * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
255
293
  */
256
294
  export function writeXObjAttrEx(obj: object, attr: string, value: any, opt?: object, key?: string): boolean;
257
295
  /**
258
296
  * Extracts an attributes from a given object by its key.
259
- * @throws {TypeError} if first param is not an object
297
+ * @throws {TypeError} if `obj` param is not an object
260
298
  */
261
299
  export function getXObjAttributes(obj: object, key?: string): object | null;
262
300
  /**
263
301
  * Checks whether an attribute is exists.
264
- * @throws {TypeError} if first param is not an object
265
- * @throws {EvalKeyNameError} if second param is not valid identifier
302
+ * @throws {TypeError} if `obj` param is not an object
303
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
266
304
  */
267
305
  export function checkXObjAttribute(obj: object, attr?: string, key?: string): boolean;
268
306
  /**
269
307
  * Deletes an attribute addressed by a given name.
270
- * @throws {TypeError} if first param is not an object
271
- * @throws {EvalKeyNameError} if second param is not valid identifier
308
+ * @throws {TypeError} if `obj` param is not an object
309
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
272
310
  */
273
311
  export function deleteXObjAttribute(obj: object, attr?: string, key?: string): boolean;
274
312
  /**
275
313
  * Renames an attribute addressed by a given name.
276
314
  * @since 0.2.0
277
- * @throws {TypeError} if first param is not an object
278
- * @throws {EvalKeyNameError} if second param is not valid identifier
279
- * @throws {EvalKeyNameError} if third param is not valid identifier
280
- * @throws {EvalKeyNameError} if forth param is not valid identifier
315
+ * @throws {TypeError} if `obj` param is not an object
316
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
317
+ * @throws {EvalKeyNameError} if `value` param is not valid identifier
318
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
281
319
  */
282
320
  export function renameXObjAttribute(obj: object, attr?: string, value?: string, key?: string): boolean;
283
321
  /**
284
322
  * Extracts an element from a given object by its key.
285
- * @throws {TypeError} if first param is not an object
286
- * @throws {EvalKeyNameError} if second param is not valid identifier
323
+ * @throws {TypeError} if `obj` param is not an object
324
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
287
325
  */
288
326
  export function getXObjElement(obj: object, name: string): any | null;
289
327
  /**
290
328
  * Adds an element addressed by its key to a given object.
291
- * @throws {TypeError} if first param is not an object
292
- * @throws {EvalKeyNameError} if second param is not valid identifier
329
+ * @throws {TypeError} if `obj` param is not an object
330
+ * @see {@link addXObjElementEx} for param details
293
331
  */
294
- export function addXObjElement(obj: object, name: string): RVAL_emodif;
332
+ export function addXObjElement(...args: addXObjElementParams): object | null;
333
+ type addXObjElementParams = Parameters<typeof addXObjElementEx>;
295
334
  /**
296
335
  * Inserts an element addressed by its key into a given object.
297
- * @throws {TypeError} if first param is not an object
336
+ * @throws {TypeError} if `obj` param is not an object
298
337
  * @see {@link insertXObjElementEx} for param details
299
338
  */
300
339
  export function insertXObjElement(...args: insertXObjElementParams): object | null;
@@ -302,28 +341,28 @@ type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
302
341
  /**
303
342
  * Inserts an element addressed by its key into a given object.
304
343
  * @since 0.2.0
305
- * @throws {TypeError} if first param is not an object
306
- * @throws {EvalKeyNameError} if second param is not valid identifier
344
+ * @throws {TypeError} if `obj` param is not an object
345
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
307
346
  */
308
347
  export function insertXObjElementEx(obj: object, name: string, opt?: OPT_inselops_L): RVAL_emodif;
309
348
  /**
310
349
  * Deletes an element addressed by its key from a given object.
311
- * @throws {TypeError} if first param is not an object
350
+ * @throws {TypeError} if `obj` param is not an object
312
351
  * @see {@link deleteXObjElementEx} for param details
313
352
  */
314
353
  export function deleteXObjElement(...args: deleteXObjElementParams): boolean;
315
354
  type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
316
355
  /**
317
356
  * Deletes an element addressed by its key from a given object.
318
- * @throws {TypeError} if first param is not an object
319
- * @throws {EvalKeyNameError} if second param is not valid identifier
357
+ * @throws {TypeError} if `obj` param is not an object
358
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
320
359
  */
321
360
  export function deleteXObjElementEx(obj: object, name: string): RVAL_emodif;
322
361
  /**
323
362
  * Renames an element addressed by its key.
324
- * @throws {TypeError} if first param is not an object
325
- * @throws {EvalKeyNameError} if second param is not valid identifier
326
- * @throws {EvalKeyNameError} if third param is not valid identifier
363
+ * @throws {TypeError} if `obj` param is not an object
364
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
365
+ * @throws {EvalKeyNameError} if `value` param is not valid identifier
327
366
  */
328
367
  export function renameXObjElement(obj: object, name?: string, value?: string): boolean;
329
368
  /**
@@ -332,7 +371,7 @@ export function renameXObjElement(obj: object, name?: string, value?: string): b
332
371
  export function evalXObjEName(value: any): null | number | string;
333
372
  /**
334
373
  * Inserts a list elements into a given object.
335
- * @throws {TypeError} if first param is not an object
374
+ * @throws {TypeError} if `obj` param is not an object
336
375
  * @see insertXObjEListEx
337
376
  */
338
377
  export function insertXObjEList(...args: insertXObjEListParams): object | object[] | null;
@@ -340,8 +379,8 @@ type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
340
379
  /**
341
380
  * Inserts a list elements into a given object.
342
381
  * @since 0.2.0
343
- * @throws {TypeError} if first param is not an object
344
- * @throws {EvalKeyNameError} if second param is not valid identifier
382
+ * @throws {TypeError} if `obj` param is not an object
383
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
345
384
  */
346
385
  export function insertXObjEListEx(obj: object, name: string, opt?: OPT_inselops_S): RVAL_emodif;
347
386
  /**
@@ -355,12 +394,12 @@ export function evalKeyName(value: any, opt?: boolean | IEvalKeyNameOptions): IE
355
394
  export function genXObjENameDescr(value: any): XObjENameDescr;
356
395
  /**
357
396
  * Inserts an elements into a given object.
358
- * @throws {TypeError} if first param is not an object
397
+ * @throws {TypeError} if `obj` param is not an object
359
398
  */
360
399
  export function insertXObjElements(obj: object, ...args: any[]): number;
361
400
  /**
362
401
  * Inserts a chain of an elements into a given object.
363
- * @throws {TypeError} if first param is not an object
402
+ * @throws {TypeError} if `obj` param is not an object
364
403
  */
365
404
  export function insertXObjEChain(obj: object, ...args: any[]): any | null;
366
405
  export {}