cavalion-js 1.0.77 → 1.0.79

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 CHANGED
@@ -1,6 +1,16 @@
1
+ ### 2024/07/07 - 1.0.79
2
+
3
+ * Removes `Array.prototype.last` and -`first`
4
+ * Improves beautifying XML sources and error detection during (uhm)
5
+
6
+ ### 2024/05/16 - 1.0.78
7
+
8
+ * Adds Array.fn.nonNil
9
+ * Introduces js.eval
10
+
1
11
  ### 2024/03/24 - 1.0.77
2
12
 
3
- *
13
+ * Introduces util/Text
4
14
 
5
15
  ### 2023/09/30 - 1.0.76
6
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.77",
3
+ "version": "1.0.79",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/js/_js.js CHANGED
@@ -17,6 +17,8 @@ define(function(require) {
17
17
  const groupBy = (arr, key) => arr.reduce((a, o) =>
18
18
  ((a[js.get(key, o)] || (a[js.get(key, o)] = []))
19
19
  .push(o), a), {});
20
+
21
+ const tlc = (s) => s.toLowerCase();
20
22
 
21
23
  /*var js;*/
22
24
  return (js = {
@@ -38,6 +40,7 @@ define(function(require) {
38
40
  sj: JSON.stringify,//serialize.serialize,
39
41
  pj: JSON.parse,
40
42
  sf: String.format,
43
+ eval: global[tlc("EVAL")],
41
44
  nameOf: nameOf,
42
45
  defineClass: defineClass,
43
46
  mixIn: mixIn,
@@ -74,16 +74,16 @@ define(function(require) {
74
74
  Array.prototype.remove = remove;
75
75
  }
76
76
  }
77
- if(Array.prototype.last === undefined) {
78
- Array.prototype.last = function() {
79
- return this[this.length - 1];
80
- };
81
- }
82
- if(Array.prototype.first === undefined) {
83
- Array.prototype.first = function() {
84
- return this[0];
85
- };
86
- }
77
+ // if(Array.prototype.last === undefined) {
78
+ // Array.prototype.last = function() {
79
+ // return this[this.length - 1];
80
+ // };
81
+ // }
82
+ // if(Array.prototype.first === undefined) {
83
+ // Array.prototype.first = function() {
84
+ // return this[0];
85
+ // };
86
+ // }
87
87
 
88
88
  Array.as = function(arrObjOrNull) {
89
89
  if(arrObjOrNull instanceof Array) {
@@ -108,6 +108,8 @@ define(function(require) {
108
108
  return before.concat([item]).concat(arr);
109
109
  };
110
110
  Array.fn = {
111
+ nonNil(item) { return item !== null && item !== undefined; },
112
+ nonNull(item) { return item !== null },
111
113
  truthy(item) { return !!item; },
112
114
  falsy(item) { return !item; },
113
115
  unique(item, index, array) { return array.indexOf(item) === index; },
package/src/util/Xml.js CHANGED
@@ -20,12 +20,17 @@ define(function() {
20
20
  xsltProcessor.importStylesheet(xsltDoc);
21
21
  var resultDoc = xsltProcessor.transformToDocument(xmlDoc);
22
22
  var resultXml = new XMLSerializer().serializeToString(resultDoc);
23
- return resultXml;
23
+
24
+ if(resultXml.indexOf('<parsererror ') !== -1) {
25
+ return sourceXml;
26
+ }
27
+
28
+ return resultXml.replace(/^( {2})+/gm, match => '\t'.repeat(match.length / 2));
24
29
  };
25
30
 
26
31
  var Xml = {
27
- beautify: prettifyXml,
28
- beautify_(xml) {
32
+ beautify_2: prettifyXml,
33
+ beautify_1(xml) {
29
34
  var formatted = "";
30
35
  var reg = /(>)(<)(\/*)/g;
31
36
  xml = xml.replace(reg, "$1\n$2$3");
@@ -54,6 +59,9 @@ define(function() {
54
59
  });
55
60
 
56
61
  return formatted;
62
+ },
63
+ beautify(xml) {
64
+ return Xml.beautify_2(Xml.beautify_1(xml));
57
65
  },
58
66
  jsonfy(node, opts, r) {
59
67
  if(node.getAttributeNames) {