@ygracs/xobj-lib-js 0.3.1 → 0.3.3

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,8 +1,77 @@
1
- import type { EvalKeyNameError } from "./xObj-errors";
2
1
  /**
3
- * An error description of a value check ops on fail.
2
+ * A result of `evalKeyName` function
4
3
  */
5
- export type IEvalKeyNameReasonOnFail = {
4
+ export type IEvalKeyNameResult = IEvalKeyNameResultOnSuccess | IEvalKeyNameResultOnFail;
5
+ export const IEvalKeyNameResult: IEvalKeyNameResult;
6
+ export type INode = {
7
+ [x: string]: any;
8
+ };
9
+ export const INode: INode;
10
+ /**
11
+ * A result of an xObj modification ops
12
+ */
13
+ export type INodeModifResult = INodeModifResultOnFail | INodeModifResultOnSuccess;
14
+ export const INodeModifResult: INodeModifResult;
15
+ /**
16
+ * Some conditions applied to an element as a result of an element name pattern
17
+ * evaluation ops.
18
+ */
19
+ export type XObjENameDescrConditions = {
20
+ /**
21
+ * - element name
22
+ */
23
+ name: any;
24
+ /**
25
+ * - element type
26
+ */
27
+ type: any;
28
+ /**
29
+ * - some value
30
+ */
31
+ value?: any;
32
+ };
33
+ /**
34
+ * A result of an element name pattern evaluation ops.
35
+ */
36
+ export type XObjENameDescr = {
37
+ /**
38
+ * - ops flag
39
+ */
40
+ isERR: boolean;
41
+ /**
42
+ * - element name
43
+ */
44
+ name: null | number | string;
45
+ /**
46
+ * - some conditions applied to an element
47
+ */
48
+ conditions: XObjENameDescrConditions | null;
49
+ };
50
+ /**
51
+ * A list of a `INode`-elements
52
+ */
53
+ export type INodeList = INode[];
54
+ /**
55
+ * An options for an element insertion ops
56
+ */
57
+ export type OPT_inselops_L = {
58
+ force?: boolean;
59
+ ripOldies?: boolean;
60
+ acceptIfList?: boolean;
61
+ };
62
+ /**
63
+ * An options for an element insertion ops
64
+ */
65
+ export type OPT_inselops_S = {
66
+ force?: boolean;
67
+ ripOldies?: boolean;
68
+ };
69
+ /**
70
+ * A result of a value check ops.
71
+ * @deprecated
72
+ * @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameReasonOnFail` instead.
73
+ */
74
+ export type RVAL_reason = {
6
75
  /**
7
76
  * - message ID
8
77
  */
@@ -13,9 +82,9 @@ export type IEvalKeyNameReasonOnFail = {
13
82
  msg: string;
14
83
  };
15
84
  /**
16
- * A result of a value check ops.
85
+ * An error description of a value check ops on fail.
17
86
  */
18
- export type RVAL_reason = {
87
+ export type IEvalKeyNameReasonOnFail = {
19
88
  /**
20
89
  * - message ID
21
90
  */
@@ -25,6 +94,21 @@ export type RVAL_reason = {
25
94
  */
26
95
  msg: string;
27
96
  };
97
+ /**
98
+ * A result of a value check ops.
99
+ * @deprecated
100
+ * @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameResult` instead.
101
+ */
102
+ export type VCOR_evalkname = {
103
+ /**
104
+ * - ops flag
105
+ */
106
+ isSucceed: boolean;
107
+ /**
108
+ * - result value or reson if failed
109
+ */
110
+ value: string | IEvalKeyNameReasonOnFail;
111
+ };
28
112
  /**
29
113
  * An options setting for `evalKeyName` function
30
114
  */
@@ -61,269 +145,58 @@ export type IEvalKeyNameResultOnFail = {
61
145
  value: IEvalKeyNameReasonOnFail;
62
146
  };
63
147
  /**
64
- * A result of `evalKeyName` function
65
- */
66
- export type IEvalKeyNameResult = IEvalKeyNameResultOnSuccess | IEvalKeyNameResultOnFail;
67
- /**
68
- * A result of a value check ops.
148
+ * A result of an xObj modification ops
149
+ * @deprecated
150
+ * @todo \[from v0.3.2] make obsolete. Use `INodeModifResult` instead.
69
151
  */
70
- export type VCOR_evalkname = {
152
+ export type RVAL_emodif = {
71
153
  /**
72
- * - ops flag
154
+ * - flag that indicates whether an ops is succeed or not
73
155
  */
74
156
  isSucceed: boolean;
75
157
  /**
76
- * - result value or reson if failed
77
- */
78
- value: string | RVAL_reason;
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
158
+ * - some element as a result
95
159
  */
96
- value?: any;
160
+ item: object | object[] | null;
97
161
  };
98
162
  /**
99
- * A result of an element name pattern evaluation ops.
163
+ * A result of an xObj modification ops if failed
100
164
  */
101
- export type XObjENameDescr = {
102
- /**
103
- * - ops flag
104
- */
105
- isERR: boolean;
165
+ export type INodeModifResultOnFail = {
106
166
  /**
107
- * - element name
167
+ * - flag that indicates whether an ops is succeed or not
108
168
  */
109
- name: null | number | string;
169
+ isSucceed: false;
110
170
  /**
111
- * - some conditions applied to an element
171
+ * - some element as a result
112
172
  */
113
- conditions: XObjENameDescrConditions | null;
173
+ item: null;
114
174
  };
115
175
  /**
116
- * A result of an xObj modification ops
176
+ * A result of an xObj modification ops if succeed
117
177
  */
118
- export type RVAL_emodif = {
178
+ export type INodeModifResultOnSuccess = {
119
179
  /**
120
180
  * - flag that indicates whether an ops is succeed or not
121
181
  */
122
- isSucceed: boolean;
182
+ isSucceed: true;
123
183
  /**
124
184
  * - some element as a result
125
185
  */
126
- item: object | object[] | null;
127
- };
128
- /**
129
- * An options for an element insertion ops
130
- */
131
- export type OPT_inselops_L = {
132
- force?: boolean;
133
- ripOldies?: boolean;
134
- acceptIfList?: boolean;
135
- };
136
- /**
137
- * An options for an element insertion ops
138
- */
139
- export type OPT_inselops_S = {
140
- force?: boolean;
141
- ripOldies?: boolean;
186
+ item: object | object[];
142
187
  };
143
188
 
144
189
  /**
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
149
- */
150
- export function addXObjElementEx(obj: object, name: string): RVAL_emodif;
151
- /**
152
- * Extracts a parameter from a given object and returns it as a boolean.
153
- * @throws {TypeError} if `obj` param is not an object
154
- */
155
- export function readXObjParamAsBool(obj: object, defValue?: boolean, key?: string): boolean;
156
- /**
157
- * Extracts a parameter from a given object and returns it as a number.
158
- * @throws {TypeError} if `obj` param is not an object
159
- */
160
- export function readXObjParamAsNum(obj: object, defValue?: number, key?: string): number;
161
- /**
162
- * Extracts a parameter from a given object and returns it as 'index' value.
163
- * @throws {TypeError} if `obj` param is not an object
164
- */
165
- export function readXObjParamAsIndex(obj: object, key?: string): number;
166
- /**
167
- * Tries to convert a given value to a boolean and writes it as a parameter
168
- * into a given object.
169
- * @throws {TypeError} if `obj` param is not an object
170
- */
171
- export function writeXObjParamAsBool(obj: object, value: any, defValue?: boolean, key?: string): boolean;
172
- /**
173
- * Tries to convert a given value to a number and writes it as a parameter
174
- * into a given object.
175
- * @throws {TypeError} if `obj` param is not an object
176
- */
177
- export function writeXObjParamAsNum(obj: object, value: any, defValue?: number, key?: string): boolean;
178
- /**
179
- * Tries to convert a given value into an 'index' value and writes it
180
- * as a parameter into a given object.
181
- * @throws {TypeError} if `obj` param is not an object
182
- */
183
- export function writeXObjParamAsIndex(obj: object, value: any, key?: string): boolean;
184
- /**
185
- * Extracts an attribute from a given object and returns it as a boolean.
186
- * @throws {TypeError} if `obj` param is not an object
187
- */
188
- export function readXObjAttrAsBool(obj: object, attr: string, defValue?: boolean, key?: string): boolean;
189
- /**
190
- * Extracts an attribute from a given object and returns it as a number.
191
- * @returns {number}
192
- * @throws {TypeError} if `obj` param is not an object
193
- */
194
- export function readXObjAttrAsNum(obj: object, attr: string, defValue?: number, key?: string): number;
195
- /**
196
- * Extracts an attribute from a given object and returns it as 'index' value.
197
- * @throws {TypeError} if `obj` param is not an object
198
- */
199
- export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): number;
200
- /**
201
- * Tries to convert a given value to a boolean and writes it as an attribute
202
- * into a given object.
203
- * @throws {TypeError} if `obj` param is not an object
204
- */
205
- export function writeXObjAttrAsBool(obj: object, attr: string, value: any, defValue?: boolean, key?: string): boolean;
206
- /**
207
- * Tries to convert a given value to a number and writes it as an attribute
208
- * into a given object.
209
- * @throws {TypeError} if `obj` param is not an object
210
- */
211
- export function writeXObjAttrAsNum(obj: object, attr: string, value: any, defValue?: number, key?: string): boolean;
212
- /**
213
- * Tries to convert a given value into an 'index' value and writes it
214
- * as an attribute into a given object.
215
- * @throws {TypeError} if `obj` param is not an object
216
- */
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;
288
- /**
289
- * Tries to convert a given value to a string and writes it as an attribute
290
- * into a given object.
291
- * @throws {TypeError} if `obj` param is not an object
292
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
293
- */
294
- export function writeXObjAttrEx(obj: object, attr: string, value: any, opt?: object, key?: string): boolean;
295
- /**
296
- * Extracts an attributes from a given object by its key.
297
- * @throws {TypeError} if `obj` param is not an object
298
- */
299
- export function getXObjAttributes(obj: object, key?: string): object | null;
300
- /**
301
- * Checks whether an attribute is exists.
302
- * @throws {TypeError} if `obj` param is not an object
303
- * @throws {EvalKeyNameError} if `attr` param is not valid identifier
304
- */
305
- export function checkXObjAttribute(obj: object, attr?: string, key?: string): boolean;
306
- /**
307
- * Deletes an attribute addressed by a given name.
308
- * @throws {TypeError} if `obj` param is not an object
309
- * @throws {EvalKeyNameError} if `attr` param is not valid identifier
310
- */
311
- export function deleteXObjAttribute(obj: object, attr?: string, key?: string): boolean;
312
- /**
313
- * Renames an attribute addressed by a given name.
314
- * @since 0.2.0
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
190
+ * Tries to convert a value into an ID.
191
+ * @inner
319
192
  */
320
- export function renameXObjAttribute(obj: object, attr?: string, value?: string, key?: string): boolean;
193
+ export function evalKeyName(value: any, opt?: boolean | IEvalKeyNameOptions): IEvalKeyNameResult;
321
194
  /**
322
195
  * Extracts an element from a given object by its key.
323
196
  * @throws {TypeError} if `obj` param is not an object
324
197
  * @throws {EvalKeyNameError} if `name` param is not valid identifier
325
198
  */
326
- export function getXObjElement(obj: object, name: string): any | null;
199
+ export function getXObjElement(obj: INode, name: string): any | null;
327
200
  /**
328
201
  * Adds an element addressed by its key to a given object.
329
202
  * @throws {TypeError} if `obj` param is not an object
@@ -331,6 +204,13 @@ export function getXObjElement(obj: object, name: string): any | null;
331
204
  */
332
205
  export function addXObjElement(...args: addXObjElementParams): object | null;
333
206
  type addXObjElementParams = Parameters<typeof addXObjElementEx>;
207
+ /**
208
+ * Adds an element addressed by its key to a given object.
209
+ * @since 0.3.0
210
+ * @throws {TypeError} if `obj` param is not an object
211
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
212
+ */
213
+ export function addXObjElementEx(obj: INode, name: string): INodeModifResult;
334
214
  /**
335
215
  * Inserts an element addressed by its key into a given object.
336
216
  * @throws {TypeError} if `obj` param is not an object
@@ -344,7 +224,7 @@ type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
344
224
  * @throws {TypeError} if `obj` param is not an object
345
225
  * @throws {EvalKeyNameError} if `name` param is not valid identifier
346
226
  */
347
- export function insertXObjElementEx(obj: object, name: string, opt?: OPT_inselops_L): RVAL_emodif;
227
+ export function insertXObjElementEx(obj: INode, name: string, opt?: OPT_inselops_L): INodeModifResult;
348
228
  /**
349
229
  * Deletes an element addressed by its key from a given object.
350
230
  * @throws {TypeError} if `obj` param is not an object
@@ -357,14 +237,19 @@ type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
357
237
  * @throws {TypeError} if `obj` param is not an object
358
238
  * @throws {EvalKeyNameError} if `name` param is not valid identifier
359
239
  */
360
- export function deleteXObjElementEx(obj: object, name: string): RVAL_emodif;
240
+ export function deleteXObjElementEx(obj: INode, name: string): INodeModifResult;
361
241
  /**
362
242
  * Renames an element addressed by its key.
363
243
  * @throws {TypeError} if `obj` param is not an object
364
244
  * @throws {EvalKeyNameError} if `name` param is not valid identifier
365
245
  * @throws {EvalKeyNameError} if `value` param is not valid identifier
366
246
  */
367
- export function renameXObjElement(obj: object, name?: string, value?: string): boolean;
247
+ export function renameXObjElement(obj: INode, name?: string, value?: string): boolean;
248
+ /**
249
+ * Clears a given node
250
+ * @throws {TypeError} if `node`-param is not an object or array
251
+ */
252
+ export function clearXObjNode(node: INode | INode[]): boolean;
368
253
  /**
369
254
  * Tries to convert a value into an ID.
370
255
  */
@@ -382,12 +267,7 @@ type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
382
267
  * @throws {TypeError} if `obj` param is not an object
383
268
  * @throws {EvalKeyNameError} if `name` param is not valid identifier
384
269
  */
385
- export function insertXObjEListEx(obj: object, name: string, opt?: OPT_inselops_S): RVAL_emodif;
386
- /**
387
- * Tries to convert a value into an ID.
388
- * @inner
389
- */
390
- export function evalKeyName(value: any, opt?: boolean | IEvalKeyNameOptions): IEvalKeyNameResult;
270
+ export function insertXObjEListEx(obj: INode, name: string, opt?: OPT_inselops_S): INodeModifResult;
391
271
  /**
392
272
  * Tries to convert a value into an element name description.
393
273
  */
@@ -402,4 +282,3 @@ export function insertXObjElements(obj: object, ...args: any[]): number;
402
282
  * @throws {TypeError} if `obj` param is not an object
403
283
  */
404
284
  export function insertXObjEChain(obj: object, ...args: any[]): any | null;
405
- export {}