@ygracs/xobj-lib-js 0.0.14-rc4 → 0.1.1
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 +14 -0
- package/doc/xObj.md +19 -15
- package/index.js +1 -1
- package/lib/xObj-lib.js +17 -15
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
#### *v0.1.1*
|
|
2
|
+
|
|
3
|
+
Release version.
|
|
4
|
+
|
|
5
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.0.
|
|
6
|
+
|
|
7
|
+
#### *v0.1.0*
|
|
8
|
+
|
|
9
|
+
Release version.
|
|
10
|
+
|
|
11
|
+
> - `xObj-lib.md` updated;
|
|
12
|
+
> - change behavior for function: `insertXObjElement`, `insertXObjElements`, `insertXObjEChain`, `insertXObjEList` (***remove deprecated options parameters**. check the package docs*)
|
|
13
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.4.
|
|
14
|
+
|
|
1
15
|
#### *v0.0.14rc4*
|
|
2
16
|
|
|
3
17
|
Pre-release version.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.23|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2023-
|
|
3
|
+
>|date:|2023-07-30|
|
|
4
4
|
|
|
5
5
|
## Intoduction
|
|
6
6
|
|
|
@@ -266,15 +266,17 @@ This function inserts an empty element named by a `name` parameter into a given
|
|
|
266
266
|
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
267
267
|
> - `name` parameter is not a non-empty string.
|
|
268
268
|
|
|
269
|
+
An `options` parameter contains the following parameters:
|
|
270
|
+
|
|
271
|
+
|option name|value type|default value|description|
|
|
272
|
+
|:---|---|---:|:---|
|
|
273
|
+
|`force`|`boolean`|`false`|modifies the functions behavior|
|
|
274
|
+
|`ripOldies`|`boolean`|`false`|it prevents a replacement of an element which exists and has a type of an `object`. Applied only if `force` option is set to `true`|
|
|
275
|
+
|
|
269
276
|
An `options.force` parameter modifies the functions behavior as follows:
|
|
270
|
-
- if not given it is set to `false`(default value);
|
|
271
277
|
- when set to `true`, the addressed element will be replaced with an empty element.
|
|
272
278
|
- when set to `false`, if the target element exists and is not a type of an `object`, the function will failed.
|
|
273
279
|
|
|
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.
|
|
277
|
-
|
|
278
280
|
#### **deleteXObjElement(object, name)**
|
|
279
281
|
|
|
280
282
|
This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
|
|
@@ -307,7 +309,7 @@ A value of the `name` parameter must have some of the following formats:
|
|
|
307
309
|
4. `<name>[@<attribute>]`;
|
|
308
310
|
5. `<name>[@<attribute>=<value>]`;
|
|
309
311
|
|
|
310
|
-
> Note: the `<value>` must be
|
|
312
|
+
> Note: the `<value>` must be quoted if it contains characters like a spaces or square brackets.
|
|
311
313
|
|
|
312
314
|
The returned object has following attributes:
|
|
313
315
|
|
|
@@ -331,7 +333,7 @@ This function inserts an elements given by the `names_list` and return quantity
|
|
|
331
333
|
|
|
332
334
|
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
333
335
|
>
|
|
334
|
-
> The `options` parameter if given must be an object. For details see `insertXObjElement
|
|
336
|
+
> The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertxobjelementobject-name-options).
|
|
335
337
|
|
|
336
338
|
#### **insertXObjEList(object, name\[, options])**
|
|
337
339
|
|
|
@@ -341,23 +343,25 @@ This function inserts an elements list named by a `name` parameter into a given
|
|
|
341
343
|
> - `object` parameter is not a plain object;
|
|
342
344
|
> - `name` parameter is not a non-empty string.
|
|
343
345
|
|
|
346
|
+
An `options` parameter contains the following parameters:
|
|
347
|
+
|
|
348
|
+
|option name|value type|default value|description|
|
|
349
|
+
|:---|---|---:|:---|
|
|
350
|
+
|`force`|`boolean`|`false`|modifies the functions behavior|
|
|
351
|
+
|`ripOldies`|`boolean`|`false`|it prevents a replacement of an element which exists and has a type of an `array`. Applied only if `force` option is set to `true`|
|
|
352
|
+
|
|
344
353
|
An `options.force` parameter modifies the functions behavior as follows:
|
|
345
|
-
- if not given it is set to `false` (*default value*);
|
|
346
354
|
- when set to `true`, the addressed element will be replaced with an empty elements list.
|
|
347
355
|
- when set to `false`, if the target element type is an `object`, the function will wraps it in the list.
|
|
348
356
|
- when set to `false`, if the target element exists and is not a type of an `array` or an `object`, the function will failed.
|
|
349
357
|
|
|
350
|
-
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`.
|
|
351
|
-
|
|
352
|
-
> NOTE: An `options.rip_oldies` will deprecate. Use `options.ripOldies` instead.
|
|
353
|
-
|
|
354
358
|
#### **insertXObjEChain(object, names_list\[, options])**
|
|
355
359
|
|
|
356
360
|
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.
|
|
357
361
|
|
|
358
362
|
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
359
363
|
>
|
|
360
|
-
> The `options` parameter if given must be an object. For details see `insertXObjElement
|
|
364
|
+
> The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertxobjelementobject-name-options).
|
|
361
365
|
|
|
362
366
|
#### **deleteXObjElementEx(object, name)**
|
|
363
367
|
|
package/index.js
CHANGED
package/lib/xObj-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.059-20230918]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -212,7 +212,7 @@ function addXObjElement(obj, name){
|
|
|
212
212
|
};
|
|
213
213
|
};
|
|
214
214
|
|
|
215
|
-
function insertXObjElement(obj, name, opt
|
|
215
|
+
function insertXObjElement(obj, name, opt){
|
|
216
216
|
let err = null;
|
|
217
217
|
if (!isPlainObject(obj)) {
|
|
218
218
|
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
@@ -231,9 +231,8 @@ function insertXObjElement(obj, name, opt = {}){
|
|
|
231
231
|
throw err;
|
|
232
232
|
};
|
|
233
233
|
const _options = isPlainObject(opt) ? opt : {};
|
|
234
|
-
let { force,
|
|
234
|
+
let { force, ripOldies } = _options;
|
|
235
235
|
if (typeof force !== 'boolean') force = false;
|
|
236
|
-
if (ripOldies === undefined) ripOldies = rip_oldies;
|
|
237
236
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
238
237
|
let prop = obj[key];
|
|
239
238
|
let isACCEPTED = (
|
|
@@ -536,10 +535,11 @@ function readXObjParamAsStr(obj, defValue, key){
|
|
|
536
535
|
}
|
|
537
536
|
};
|
|
538
537
|
};
|
|
539
|
-
return readAsString(result,
|
|
538
|
+
return readAsString(result, {
|
|
540
539
|
useTrim: false,
|
|
541
540
|
numberToString: true,
|
|
542
541
|
boolToString: true,
|
|
542
|
+
defValue,
|
|
543
543
|
});
|
|
544
544
|
};
|
|
545
545
|
|
|
@@ -657,10 +657,11 @@ function writeXObjParamEx(obj, value, defValue, key){
|
|
|
657
657
|
numberToString: true,
|
|
658
658
|
boolToString: true,
|
|
659
659
|
});
|
|
660
|
-
const _value = readAsString(value,
|
|
660
|
+
const _value = readAsString(value, {
|
|
661
661
|
useTrim: false,
|
|
662
662
|
numberToString: true,
|
|
663
663
|
boolToString: true,
|
|
664
|
+
defValue: _defValue,
|
|
664
665
|
});
|
|
665
666
|
try {
|
|
666
667
|
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
@@ -752,10 +753,11 @@ function readXObjAttrAsStr(obj, attr, defValue, key){
|
|
|
752
753
|
}
|
|
753
754
|
};
|
|
754
755
|
};
|
|
755
|
-
return readAsString(result,
|
|
756
|
+
return readAsString(result, {
|
|
756
757
|
useTrim: true,
|
|
757
758
|
numberToString: true,
|
|
758
759
|
boolToString: true,
|
|
760
|
+
defValue,
|
|
759
761
|
});
|
|
760
762
|
};
|
|
761
763
|
|
|
@@ -873,10 +875,11 @@ function writeXObjAttrEx(obj, attr, value, defValue, key){
|
|
|
873
875
|
numberToString: true,
|
|
874
876
|
boolToString: true,
|
|
875
877
|
});
|
|
876
|
-
const _value = readAsString(value,
|
|
878
|
+
const _value = readAsString(value, {
|
|
877
879
|
useTrim: true,
|
|
878
880
|
numberToString: true,
|
|
879
881
|
boolToString: true,
|
|
882
|
+
defValue: _defValue,
|
|
880
883
|
});
|
|
881
884
|
try {
|
|
882
885
|
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
@@ -905,8 +908,8 @@ function insertXObjElements(obj, ...args){
|
|
|
905
908
|
const hasOpt = len > 0 && isPlainObject(args[len - 1]);
|
|
906
909
|
const opt = hasOpt ? args.pop() : {};
|
|
907
910
|
const names = readAsListS({
|
|
908
|
-
|
|
909
|
-
|
|
911
|
+
useTrim: true,
|
|
912
|
+
keepEmpty: false,
|
|
910
913
|
}, ...args);
|
|
911
914
|
let count = 0;
|
|
912
915
|
for (let key of names) {
|
|
@@ -915,7 +918,7 @@ function insertXObjElements(obj, ...args){
|
|
|
915
918
|
return count;
|
|
916
919
|
};
|
|
917
920
|
|
|
918
|
-
function insertXObjEList(obj, name, opt
|
|
921
|
+
function insertXObjEList(obj, name, opt){
|
|
919
922
|
let err = null;
|
|
920
923
|
if (!isPlainObject(obj)) {
|
|
921
924
|
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
@@ -934,9 +937,8 @@ function insertXObjEList(obj, name, opt = {}){
|
|
|
934
937
|
throw err;
|
|
935
938
|
};
|
|
936
939
|
const _options = isPlainObject(opt) ? opt : {};
|
|
937
|
-
let { force,
|
|
940
|
+
let { force, ripOldies } = _options;
|
|
938
941
|
if (typeof force !== 'boolean') force = false;
|
|
939
|
-
if (ripOldies === undefined) ripOldies = rip_oldies;
|
|
940
942
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
941
943
|
let item = obj[key];
|
|
942
944
|
let isACCEPTED = (
|
|
@@ -965,8 +967,8 @@ function insertXObjEChain(obj, ...args){
|
|
|
965
967
|
const hasOpt = len > 0 && isPlainObject(args[len - 1]);
|
|
966
968
|
const opt = hasOpt ? args.pop() : {};
|
|
967
969
|
const names = readAsListS({
|
|
968
|
-
|
|
969
|
-
|
|
970
|
+
useTrim: true,
|
|
971
|
+
keepEmpty: false,
|
|
970
972
|
}, ...args);
|
|
971
973
|
let curObj = obj;
|
|
972
974
|
let isSUCCEED = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ygracs/xobj-lib-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A helper library to work with xml-js module",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"#lib/*": "./lib/*"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ygracs/bsfoc-lib-js": "^0.
|
|
30
|
+
"@ygracs/bsfoc-lib-js": "^0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"jest": "^29.
|
|
33
|
+
"jest": "^29.7.0",
|
|
34
34
|
"minimist": "^1.2.8"
|
|
35
35
|
}
|
|
36
36
|
}
|