@ygracs/xobj-lib-js 0.0.13 → 0.0.14-rc2
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/CHANGELOG.md +24 -0
- package/LICENSE +9 -9
- package/doc/xObj.md +84 -49
- package/index.js +1 -4
- package/lib/xObj-lib.js +763 -227
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
#### *v0.0.14rc2*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - some fixes in 'xObj-lib.js' module;
|
|
6
|
+
> - added some error codes (*see details in docs*);
|
|
7
|
+
> - added `evalXObjEName` function;
|
|
8
|
+
> - added `deleteXObjAttribute` function.
|
|
9
|
+
|
|
10
|
+
#### *v0.0.14rc1*
|
|
11
|
+
|
|
12
|
+
Pre-release version.
|
|
13
|
+
|
|
14
|
+
> - `xObj-lib.md` updated;
|
|
15
|
+
> - some fixes in 'xObj-lib.js' module;
|
|
16
|
+
> - changed behavior for `getXObjAttributes` (*see details in docs*);
|
|
17
|
+
> - changed behavior for `readXObjParamRaw` and its siblings (*see details in docs*);
|
|
18
|
+
> - changed behavior for `writeXObjParamRaw` and its siblings (*see details in docs*);
|
|
19
|
+
> - changed behavior for `readXObjAttrRaw` and its siblings (*see details in docs*);
|
|
20
|
+
> - changed behavior for `writeXObjAttrRaw` and its siblings (*see details in docs*);
|
|
21
|
+
> - changed `options` parameter for `insertXObjElement` (*see details in docs*);
|
|
22
|
+
> - changed `options` parameter for `insertXObjEList` (*see details in docs*);
|
|
23
|
+
> - added `checkXObjAttribute` function.
|
|
24
|
+
|
|
1
25
|
#### *v0.0.13*
|
|
2
26
|
|
|
3
27
|
Pre-release version.
|
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019-
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2023 Yuri Grachev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.20|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|
|
|
3
|
+
>|date:|2023-02-27|
|
|
4
4
|
|
|
5
5
|
## Intoduction
|
|
6
6
|
|
|
@@ -50,9 +50,9 @@ The settings listed in the table below:
|
|
|
50
50
|
### Base functions for read and write an object parameter
|
|
51
51
|
|
|
52
52
|
> Note:
|
|
53
|
-
> If a `key` parameter given to the function is
|
|
53
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
|
|
54
54
|
>
|
|
55
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
55
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
56
56
|
|
|
57
57
|
#### **readXObjParam(object\[, key])**
|
|
58
58
|
|
|
@@ -109,11 +109,11 @@ This function sets object parameter to a given value and if succeed returns `tru
|
|
|
109
109
|
### Base functions for read or write object attributes
|
|
110
110
|
|
|
111
111
|
> Note:
|
|
112
|
-
> If a `key` parameter given to the function is
|
|
112
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
113
113
|
>
|
|
114
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
114
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
115
115
|
>
|
|
116
|
-
> If an `attr` parameter given to the function is not a 'string' type, the function will
|
|
116
|
+
> If an `attr` parameter given to the function is not a 'string' type, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
117
117
|
|
|
118
118
|
#### **readXObjAttr(object, attr\[, key])**
|
|
119
119
|
|
|
@@ -173,9 +173,9 @@ This function sets object attribute to a given value and if succeed returns `tru
|
|
|
173
173
|
### Special functions for read and write an object parameter
|
|
174
174
|
|
|
175
175
|
> Note:
|
|
176
|
-
> If a `key` parameter given to the function is
|
|
176
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
|
|
177
177
|
>
|
|
178
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
178
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
179
179
|
|
|
180
180
|
#### **readXObjParamRaw(object\[, key])**
|
|
181
181
|
|
|
@@ -188,9 +188,9 @@ This is a special function that writes a given value of an object parameter as "
|
|
|
188
188
|
### Special functions for read or write object attributes
|
|
189
189
|
|
|
190
190
|
> Note:
|
|
191
|
-
> If a `key` parameter given to the function is
|
|
191
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
192
192
|
>
|
|
193
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
193
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
194
194
|
|
|
195
195
|
#### **readXObjAttrRaw(object, attr\[, key])**
|
|
196
196
|
|
|
@@ -200,62 +200,95 @@ This is a special function that returns a value of an object attribute as "IT IS
|
|
|
200
200
|
|
|
201
201
|
This is a special function that writes a given value of an object attribute as "IT IS".
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
### Other functions for deal with an object attributes
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
> Note:
|
|
206
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
207
|
+
>
|
|
208
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
209
|
+
|
|
210
|
+
#### **getXObjAttributes(object\[, key])**
|
|
211
|
+
|
|
212
|
+
This function returns an object which represents a set of the element attributes for a given object or `null` if failed.
|
|
213
|
+
|
|
214
|
+
#### **checkXObjAttribute(object, attr\[, key])**
|
|
215
|
+
|
|
216
|
+
This function tries to check whether or not an attribute with a name given by `attr` parameter exists for the element given by `object` parameter. If attribute exists `true` is returned.
|
|
217
|
+
|
|
218
|
+
> Note: If an `attr` parameter is not a type of `string`, the function will throw a `TypeError` exception.
|
|
219
|
+
|
|
220
|
+
#### **deleteXObjAttribute(object, attr\[, key])**
|
|
221
|
+
|
|
222
|
+
This function tries to delete an attribute with a name given by `attr` parameter. If succeed `true` is returned.
|
|
223
|
+
|
|
224
|
+
> Note: If an `attr` parameter is not a type of `string`, the function will throw a `TypeError` exception.
|
|
206
225
|
|
|
207
226
|
### Other functions
|
|
208
227
|
|
|
228
|
+
#### **evalXObjEName(name)**
|
|
229
|
+
|
|
230
|
+
This function evaluated a value given by a `name` parameter and return a result. The dependencies of a resulted value returned by the function given in the following table:
|
|
231
|
+
|
|
232
|
+
|given value|value of result|
|
|
233
|
+
|:---|---|
|
|
234
|
+
|value not given (*or `undefined`*)|value of `undefined`|
|
|
235
|
+
|any empty string|an empty string|
|
|
236
|
+
|value is a positive number or a string that can be converted to a such number|value of a `number`|
|
|
237
|
+
|any other string that can\'t be converted to a number|value of a string|
|
|
238
|
+
|any other cases|value of `null`|
|
|
239
|
+
|
|
209
240
|
#### **getXObjElement(object, name)**
|
|
210
241
|
|
|
211
242
|
This function returns an element from a given object by its name or `null` if that element not found.
|
|
212
243
|
|
|
213
|
-
> the function will
|
|
214
|
-
> - `object` parameter is not a plain object;
|
|
244
|
+
> the function will throw a `TypeError` if:
|
|
245
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
215
246
|
> - `name` parameter is not a non-empty string.
|
|
216
247
|
|
|
217
|
-
#### **
|
|
248
|
+
#### **addXObjElement(object, name)**
|
|
218
249
|
|
|
219
|
-
This function
|
|
250
|
+
This function adds an element given by `name` parameter to a members of the given object and returns an `object` that represents a status of the operation.
|
|
220
251
|
|
|
221
|
-
> the function will
|
|
222
|
-
> - `object` parameter is not a plain object;
|
|
252
|
+
> the function will throw a `TypeError` if:
|
|
253
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
223
254
|
> - `name` parameter is not a non-empty string.
|
|
224
255
|
|
|
225
|
-
|
|
226
|
-
- if not given it is set to `false`(default value);
|
|
227
|
-
- when set to `true`, the addressed element will be replaced with an empty element.
|
|
228
|
-
- when set to `false`, if the target element exists and is not a type of an `object`, the function will failed.
|
|
256
|
+
The status of an operation contains 2 fields:
|
|
229
257
|
|
|
230
|
-
|
|
258
|
+
- `isSucceed` - `boolean` value;
|
|
259
|
+
- `item` - an item which was added or a `null`.
|
|
231
260
|
|
|
232
|
-
#### **
|
|
261
|
+
#### **insertXObjElement(object, name\[, options])**
|
|
233
262
|
|
|
234
|
-
This function
|
|
263
|
+
This function inserts an empty element named by a `name` parameter into a given object. If succeed the element will be returned or `null` in opposite.
|
|
235
264
|
|
|
236
|
-
> the function will
|
|
237
|
-
> - `object` parameter is not a plain object;
|
|
265
|
+
> the function will throw a `TypeError` if:
|
|
266
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
238
267
|
> - `name` parameter is not a non-empty string.
|
|
239
268
|
|
|
240
|
-
|
|
269
|
+
An `options.force` parameter modifies the functions behavior as follows:
|
|
270
|
+
- if not given it is set to `false`(default value);
|
|
271
|
+
- when set to `true`, the addressed element will be replaced with an empty element.
|
|
272
|
+
- when set to `false`, if the target element exists and is not a type of an `object`, the function will failed.
|
|
241
273
|
|
|
242
|
-
|
|
243
|
-
|
|
274
|
+
An `options.ripOldies` parameter applied only if `options.force` is `true`. And if set to `false` (*default value*), it prevents a replacement of an element which exists and has a type of an `object`.
|
|
275
|
+
|
|
276
|
+
> NOTE: An `options.rip_oldies` will deprecate. Use `options.ripOldies` instead.
|
|
244
277
|
|
|
245
278
|
#### **deleteXObjElement(object, name)**
|
|
246
279
|
|
|
247
280
|
This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
|
|
248
281
|
|
|
249
|
-
> the function will
|
|
250
|
-
> - `object` parameter is not a plain object;
|
|
282
|
+
> the function will throw a `TypeError` if:
|
|
283
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
251
284
|
> - `name` parameter is not a non-empty string.
|
|
252
285
|
|
|
253
286
|
#### **renameXObjElement(object, oldName, newName)**
|
|
254
287
|
|
|
255
288
|
This function renames an element with a name `oldName` to a name `newName` for the given object. If succeed `true` is returned.
|
|
256
289
|
|
|
257
|
-
> the function will
|
|
258
|
-
> - `object` parameter is not a plain object;
|
|
290
|
+
> the function will throw a `TypeError` if:
|
|
291
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
259
292
|
> - `oldName` or `newName` parameter is not a non-empty string.
|
|
260
293
|
|
|
261
294
|
### Experimental functions
|
|
@@ -266,46 +299,48 @@ This function renames an element with a name `oldName` to a name `newName` for t
|
|
|
266
299
|
|
|
267
300
|
This function inserts an elements given by the `names_list` and return quantity of the inserted elements.
|
|
268
301
|
|
|
269
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
302
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
270
303
|
>
|
|
271
|
-
>
|
|
304
|
+
> The `options` parameter if given must be an object. For details see `insertXObjElement`.
|
|
272
305
|
|
|
273
306
|
#### **insertXObjEList(object, name\[, options])**
|
|
274
307
|
|
|
275
308
|
This function inserts an elements list named by a `name` parameter into a given object. If succeed the list will be returned or `null` in opposite.
|
|
276
309
|
|
|
277
|
-
> the function will
|
|
310
|
+
> the function will throw a `TypeError` if:
|
|
278
311
|
> - `object` parameter is not a plain object;
|
|
279
312
|
> - `name` parameter is not a non-empty string.
|
|
280
313
|
|
|
281
|
-
An `options.force` parameter modifies the functions
|
|
282
|
-
- if not given it is set to `false`(default value);
|
|
283
|
-
- when set to `true`, the
|
|
284
|
-
- when set to `false`, if the target element type is an `object`, the function will
|
|
314
|
+
An `options.force` parameter modifies the functions behavior as follows:
|
|
315
|
+
- if not given it is set to `false` (*default value*);
|
|
316
|
+
- when set to `true`, the addressed element will be replaced with an empty elements list.
|
|
317
|
+
- when set to `false`, if the target element type is an `object`, the function will wraps it in the list.
|
|
285
318
|
- when set to `false`, if the target element exists and is not a type of an `array` or an `object`, the function will failed.
|
|
286
319
|
|
|
287
|
-
An `options.
|
|
320
|
+
An `options.ripOldies` parameter applied only if `options.force` is `true`. And if set to `false` (*default value*), it prevents a replacement of an element which exists and has a type of an `array`.
|
|
321
|
+
|
|
322
|
+
> NOTE: An `options.rip_oldies` will deprecate. Use `options.ripOldies` instead.
|
|
288
323
|
|
|
289
324
|
#### **insertXObjEChain(object, names_list\[, options])**
|
|
290
325
|
|
|
291
326
|
This function inserts a chain of the elements listed by `names_list`. If succeed the last inserted element will be returned or `null` if failed.
|
|
292
327
|
|
|
293
|
-
> If an `object` parameter given to the function is not a plain object, the function will
|
|
328
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
294
329
|
>
|
|
295
|
-
>
|
|
330
|
+
> The `options` parameter if given must be an object. For details see `insertXObjElement`.
|
|
296
331
|
|
|
297
332
|
#### **deleteXObjElementEx(object, name)**
|
|
298
333
|
|
|
299
|
-
This function deletes an element
|
|
334
|
+
This function deletes an element addressed by `name` parameter from a given object and returns an `object` that represents a status of the operation.
|
|
300
335
|
|
|
301
|
-
> the function will
|
|
302
|
-
> - `object` parameter is not a plain object;
|
|
336
|
+
> the function will throw a `TypeError` if:
|
|
337
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
303
338
|
> - `name` parameter is not a non-empty string.
|
|
304
339
|
|
|
305
340
|
The status of an operation contains 2 fields:
|
|
306
341
|
|
|
307
342
|
- `isSucceed` - `boolean` value;
|
|
308
|
-
- `item` - an item which was deleted (only for objects) or a `null`.
|
|
343
|
+
- `item` - an item which was deleted (*only for objects*) or a `null`.
|
|
309
344
|
|
|
310
345
|
### Base class
|
|
311
346
|
|
package/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.008-20230227]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
|
-
//const xObj = require('./lib/xObj-lib.js');
|
|
6
|
-
|
|
7
5
|
// === module extra block (helper functions) ===
|
|
8
6
|
|
|
9
7
|
// === module main block ===
|
|
10
8
|
|
|
11
9
|
// === module exports block ===
|
|
12
10
|
|
|
13
|
-
//module.exports.xObj = xObj;
|
|
14
11
|
module.exports = require('./lib/xObj-lib.js');
|