cavalion-js 1.0.76 → 1.0.78

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/.md CHANGED
@@ -31,6 +31,7 @@
31
31
  - [Keyboard.js](src/util/:)
32
32
  - [Rest.js](src/util/:)
33
33
  - [Stylesheet.js](src/util/:)
34
+ - [Text.js](src/util/:)
34
35
  - [Xml.js](src/util/:)
35
36
 
36
37
  #
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 2024/05/16 - 1.0.78
2
+
3
+ * Adds Array.fn.nonNil
4
+ * Introduces js.eval
5
+
6
+ ### 2024/03/24 - 1.0.77
7
+
8
+ * Introduces util/Text
9
+
1
10
  ### 2023/09/30 - 1.0.76
2
11
 
3
12
  * Fixes a solid bug, in _JsObject.prototype.setProperties()_, sure why not?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.76",
3
+ "version": "1.0.78",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -41,7 +41,6 @@ define(function(require) {
41
41
  .replace(/ /g, " ")
42
42
  .replace(/\n/g, "<br>");
43
43
  parentNode.appendChild(div);
44
-
45
44
  }
46
45
  }
47
46
  }));
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,
@@ -17,9 +17,7 @@ define(function(require) {
17
17
  }());
18
18
 
19
19
  Error.chain = function(e, cause) {
20
- return mixIn(e, {
21
- cause: cause
22
- });
20
+ return mixIn(e, { cause: cause });
23
21
  };
24
22
 
25
23
  if(Array.prototype.indexOf === undefined) {
@@ -76,6 +74,16 @@ define(function(require) {
76
74
  Array.prototype.remove = remove;
77
75
  }
78
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
+ }
79
87
 
80
88
  Array.as = function(arrObjOrNull) {
81
89
  if(arrObjOrNull instanceof Array) {
@@ -99,15 +107,23 @@ define(function(require) {
99
107
  before = arr.splice(0, newIndex);
100
108
  return before.concat([item]).concat(arr);
101
109
  };
110
+ Array.fn = {
111
+ nonNil(item) { return item !== null && item !== undefined; },
112
+ nonNull(item) { return item !== null },
113
+ truthy(item) { return !!item; },
114
+ falsy(item) { return !item; },
115
+ unique(item, index, array) { return array.indexOf(item) === index; },
116
+ // sort()
117
+ };
102
118
 
103
- // if(Array.prototype.each === undefined) {
104
- // // DUH!!! (2020-01-01)
105
- // Array.prototype.each = Array.prototype.forEach;
106
- // }
107
-
119
+ if (typeof String.prototype.startsWith !== 'function') {
120
+ String.prototype.startsWith = function(s) {
121
+ return this.indexOf(s) === 0;
122
+ };
123
+ }
108
124
  if (typeof String.prototype.endsWith !== 'function') {
109
- String.prototype.endsWith = function(suffix) {
110
- return this.indexOf(suffix, this.length - suffix.length) !== -1;
125
+ String.prototype.endsWith = function(s) {
126
+ return this.indexOf(s, this.length - s.length) !== -1;
111
127
  };
112
128
  }
113
129
 
@@ -368,14 +384,22 @@ define(function(require) {
368
384
  var f = _cf(l, r);
369
385
  return (l * f) / (r * f);
370
386
  };
371
- Math.f = (n) => {
372
- var r = js.sf("%f", n), i, dot = r.indexOf(".");
387
+ Math.f = (n, d) => {
388
+ var r = String(n), i, dot = r.indexOf(".");
389
+
390
+ n = parseFloat(n);
391
+
373
392
  if((i = r.indexOf("0000")) > dot) {
374
393
  return n.toFixed(i - dot - 1);
375
394
  }
376
395
  if((i = r.indexOf("9999")) > dot) {
377
396
  return n.toFixed(i - dot - 1);
378
397
  }
398
+
399
+ if(d) {
400
+ return n.toFixed(d).replace(/0*$/, "").replace(/\.$/, "");
401
+ }
402
+
379
403
  return n;
380
404
  };
381
405
  Math.f_= (value, regexps) => {
@@ -392,11 +416,11 @@ define(function(require) {
392
416
 
393
417
  /*--- */
394
418
 
395
- Date.prototype.getWeekNumber = function(){
396
- var d = new Date(+this);
397
- d.setHours(0, 0, 0);
398
- d.setDate(d.getDate() + 4 - (d.getDay() || 7));
399
- return Math.ceil((((d - new Date(d.getFullYear(), 0, 1))
419
+ Date.getWeekNumber = function(dt){
420
+ dt = new Date(+dt);
421
+ dt.setHours(0, 0, 0);
422
+ dt.setDate(dt.getDate() + 4 - (dt.getDay() || 7));
423
+ return Math.ceil((((dt - new Date(dt.getFullYear(), 0, 1))
400
424
  / 8.64e7) + 1) / 7);
401
425
  };
402
426