cavalion-js 1.0.73 → 1.0.75

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
@@ -1,15 +1,20 @@
1
1
  * [CHANGELOG.md]() - [README.md]() - [package.json]()
2
+ * [PROMPT.md]()
2
3
  * [.workspace](`(devtools/Workspace<${ws.getSpecializer()}>)`) - [.js]()
3
4
 
4
5
 
5
6
  # cavalion-js
6
7
 
8
+ * [openai.com](https://chat.:)
9
+ * [String Word & Line Counter](https://chat.openai.com/c/01217e42-e74a-4d6a-b327-883ebfb3fa58)
10
+ * [Setting Up SPA Environment](https://chat.openai.com/c/2ff4e435-dd2d-46e3-a08d-58ccae92ee93)
7
11
  * [src](:/)
8
12
  * **[console](src/:/)**
9
13
  * **[data](src/:/)** - [design](src/:/)
10
14
  * **[entities](src/:/)** - [entities.js](src/) - [features](src/:/)
11
15
  * [js](src/:/) / [\_js.js](src/js/:) - [extensions.js](src/js/:) - _[global.js](src/js/:)_? - _[define.js](src/js/:)?_
12
16
  - [defineClass.js](src/js/:) - [referenceClass.js](src/js/:)
17
+ - [JsObject.js](src/js/:) - [Class.js](src/js/:)
13
18
  - [json.js](src/:) - [locale.js](src/:) - [text.js](src/:)
14
19
  - [script.js](src/:) - [relscript.js](src/:)
15
20
  - [stylesheet.js](src/:)
@@ -47,6 +52,26 @@
47
52
  - [Scaffold.js](src/js/:)
48
53
  - [Type.js](src/js/:)
49
54
 
55
+ # `2023/05/23` countWords
56
+
57
+ String.prototype.countLinesAndWords = function() {
58
+ const lines = this.split('\n').length;
59
+ const words = this.split(/\s+/).length;
60
+ return { lines, words };
61
+ };
62
+
63
+ // Usage example:
64
+ const text = 'Hello\nWorld!\nThis is a sample text.';
65
+ const { lines, words } = text.countLinesAndWords();
66
+ console.log('Number of lines:', lines);
67
+ console.log('Number of words:', words);
68
+
69
+ # `2023/05/11` Constructing...
70
+
71
+ The name of the constructor for vcl/ui/Node.closeable is not correct.
72
+
73
+ ![20230511-091729-jjXuKW](https://raw.githubusercontent.com/relluf/screenshots/master/20230511-091729-jjXuKW.png)
74
+
50
75
  # `2022/11/02`
51
76
 
52
77
  What about a shared _polyfill_-like file, loaded at startup in order to fill in the gaps of packages that are not updated/compiled just yet.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
- ### 2023/03/01 - 1.0.73
1
+ ### 2023/06/30 - 1.0.75
2
+
3
+ * Introduces locales.mixIn, prefixed.has()
4
+ * Ensures that Printer.prottype.print returns the printed value
5
+ * Refactores String.escape to use JSON.stringify
6
+
7
+ ### 2023/06/30 - 1.0.74
8
+
9
+ * Introduces `locale.has()`
10
+
11
+ ### 2023/03/01 - 1.0.73
2
12
 
3
13
  * Introduces `js.mi` alias for `js.mixIn`
4
14
  * Fixes a bug in `js.sf` (ie. String.format) where specifiers where not handled correctly for %X.Yf like formats
package/PROMPT.md ADDED
@@ -0,0 +1,19 @@
1
+ > _I want to document my homemade/written cavalion-js library. It deals with a JavaScript class system and some utility classes for manipulating the DOM, printing to a "in-page console". It must be using code examples a lot._
2
+
3
+ "From now on, I want you to act as a technical writer and JavaScript expert focusing on library documentation.
4
+
5
+ We are documenting the 'cavalion-js' library, which is a homemade JavaScript library that provides a class system and utility classes for DOM manipulation and printing to an in-page console.
6
+
7
+ Start with an overview of the library, explaining its purpose, benefits, and main features. Provide a high-level view of the class system and utility classes it includes. Explain what problems this library solves and why someone might choose to use it over other solutions.
8
+
9
+ Next, delve into the specifics of the JavaScript class system that 'cavalion-js' implements. Explain how to define classes, inherit from other classes, override methods, and use other features of the class system. Use code examples to illustrate these concepts.
10
+
11
+ Then, document the utility classes for manipulating the DOM. Provide a comprehensive guide to each class, describing what it does and how to use it. Include code examples for each utility, showing how to perform common tasks like selecting elements, manipulating element attributes, and modifying the DOM structure.
12
+
13
+ After that, cover the in-page console feature. Explain how it works, how to print messages to it, and any customization options it provides. Again, use code examples to clearly demonstrate its usage.
14
+
15
+ Also, provide a section on installation and setup instructions for the library, and any other important details like browser compatibility or known issues.
16
+
17
+ Ensure that the documentation is clear, thorough, and easy to follow. Use a lot of code examples to illustrate how to use the various features of 'cavalion-js.' Provide enough detail so that both novice and experienced JavaScript developers can effectively use the library in their projects.
18
+
19
+ Throughout this process, use the best practices for writing technical documentation, such as clear language, logical organization, and regular updates as the library evolves."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -70,7 +70,6 @@ define(function(require) {
70
70
  });
71
71
 
72
72
  var Printer = {
73
-
74
73
  prototype: {
75
74
  _node: null,
76
75
 
@@ -105,6 +104,8 @@ define(function(require) {
105
104
  }
106
105
  this._node.appendChild(line.getNode());
107
106
  this._node.scrollTop = this._node.scrollHeight;
107
+
108
+ return arguments.length > 1 ? arguments[1] : arguments[0];
108
109
  }
109
110
  }
110
111
  };
File without changes
@@ -16,9 +16,7 @@ define(function(require) {
16
16
  var JsObject = Class.define;
17
17
 
18
18
  return (JsObject = JsObject(require, {
19
-
20
19
  inherits: Object,
21
-
22
20
  prototype: {
23
21
 
24
22
  '@hashCode': null,
@@ -84,7 +82,6 @@ define(function(require) {
84
82
  return this;
85
83
  }
86
84
  },
87
-
88
85
  statics: {
89
86
 
90
87
  $: references,
@@ -18,10 +18,6 @@ define(function(require) {
18
18
  return (Property = Property(require, {
19
19
 
20
20
  prototype: {
21
-
22
- /**
23
- *
24
- */
25
21
  constructor: function(declaringClass, name, decl) {
26
22
  this._declaringClass = declaringClass;
27
23
  this._name = name;
@@ -76,10 +72,6 @@ define(function(require) {
76
72
  getDeclaringClass: function() {
77
73
  return this._declaringClass;
78
74
  },
79
-
80
- /**
81
- *
82
- */
83
75
  getPropertyClass: function() {
84
76
  throw new Error("Unknown class");
85
77
  },
@@ -101,10 +93,6 @@ define(function(require) {
101
93
  }
102
94
  return this._editorClass;
103
95
  },
104
-
105
- /**
106
- *
107
- */
108
96
  getEditorInfo: function(path) {
109
97
  return path === undefined ? this._editorInfo : js.get(path, this._editorInfo || {});
110
98
  },
@@ -168,10 +156,6 @@ define(function(require) {
168
156
  isStrict: function() {
169
157
  return this._strict;
170
158
  },
171
-
172
- /**
173
- *
174
- */
175
159
  isReadOnly: function() {
176
160
  return this.__set === Property.prototype.__set;
177
161
  },
@@ -202,10 +186,6 @@ define(function(require) {
202
186
  get: function(obj) {
203
187
  return this.__get(obj);
204
188
  },
205
-
206
- /**
207
- *
208
- */
209
189
  __get: function(obj) {
210
190
  throw new Error("No getter defined");
211
191
  },
@@ -216,10 +196,6 @@ define(function(require) {
216
196
  set: function(obj, value) {
217
197
  return this.__set(obj, value);
218
198
  },
219
-
220
- /**
221
- *
222
- */
223
199
  __set: function(obj, value) {
224
200
  throw new Error("No setter defined");
225
201
  }
@@ -227,10 +203,6 @@ define(function(require) {
227
203
  },
228
204
 
229
205
  statics: {
230
-
231
- /**
232
- *
233
- */
234
206
  isReferencedClass: function(cls) {
235
207
  if(Class.isConstructor(cls)) {
236
208
  if(referencedClasses.indexOf(cls) !== -1) {
@@ -241,10 +213,6 @@ define(function(require) {
241
213
  return false;
242
214
  },
243
215
 
244
-
245
- /**
246
- *
247
- */
248
216
  registerReferencedClass: function(cls) {
249
217
  if(Class.isConstructor(cls)) {
250
218
  referencedClasses.push(cls);
@@ -252,10 +220,6 @@ define(function(require) {
252
220
  throw new Error(String.format("%s is not a class constructor"));
253
221
  }
254
222
  },
255
-
256
- /**
257
- *
258
- */
259
223
  initialize: function(property, prop) {
260
224
 
261
225
  var ctor = property._declaringClass;
@@ -465,171 +429,83 @@ define(function(require) {
465
429
  },
466
430
 
467
431
  GetDefaultValue: {
468
-
469
- /**
470
- *
471
- */
472
432
  VALUE: function(obj) {
473
433
  return this._defaultValue;
474
434
  },
475
-
476
- /**
477
- *
478
- */
479
435
  METHOD: function(obj) {
480
436
  return obj[this._defaultValue]();
481
437
  },
482
-
483
- /**
484
- *
485
- */
486
438
  INLINE: function(obj) {
487
439
  return this._defaultValue.apply(obj, []);
488
440
  }
489
441
  },
490
-
491
442
  Getter: {
492
-
493
- /**
494
- *
495
- */
496
443
  MEMBER: function(obj) {
497
444
  return obj[this._getter];
498
445
  },
499
-
500
- /**
501
- *
502
- */
503
446
  METHOD: function(obj) {
504
447
  return obj[this._getter]();
505
448
  },
506
-
507
- /**
508
- *
509
- */
510
449
  INLINE: function(obj) {
511
450
  return this._getter.apply(obj, []);
512
451
  }
513
452
  },
514
453
 
515
454
  IsAssignable: {
516
-
517
- /**
518
- *
519
- */
520
455
  VALUE: function(obj) {
521
456
  return this._assignable;
522
457
  },
523
-
524
- /**
525
- *
526
- */
527
458
  METHOD: function(obj) {
528
459
  return obj[this._assignable](obj);
529
460
  },
530
-
531
- /**
532
- *
533
- */
534
461
  INLINE: function(obj) {
535
462
  return this._assignable.apply(this, [obj]);
536
463
  }
537
464
  },
538
-
539
465
  IsEnabled: {
540
-
541
- /**
542
- *
543
- */
544
466
  VALUE: function(obj) {
545
467
  return this._enabled;
546
468
  },
547
-
548
- /**
549
- *
550
- */
551
469
  METHOD: function(obj) {
552
470
  return obj[this._enabled]();
553
471
  },
554
-
555
- /**
556
- *
557
- */
558
472
  INLINE: function(obj) {
559
473
  return this._enabled.apply(obj, []);
560
474
  }
561
475
  },
562
-
563
476
  IsStored: {
564
-
565
- /**
566
- *
567
- */
568
477
  VALUE: function(obj) {
569
478
  return this.hasDefaultValue(obj) ? false : this._stored;
570
479
  },
571
-
572
- /**
573
- *
574
- */
575
480
  METHOD: function(obj) {
576
481
  return this.hasDefaultValue(obj) ? false : obj[this._stored](obj);
577
482
  },
578
-
579
- /**
580
- *
581
- */
582
483
  INLINE: function(obj) {
583
484
  return this.hasDefaultValue(obj) ? false : this._stored.apply(this, [obj]);
584
485
  }
585
486
  },
586
-
587
487
  IsVisible: {
588
-
589
- /**
590
- *
591
- */
592
488
  VALUE: function(obj) {
593
489
  return this._visible;
594
490
  },
595
-
596
- /**
597
- *
598
- */
599
491
  METHOD: function(obj) {
600
492
  return obj[this._visible]();
601
493
  },
602
-
603
- /**
604
- *
605
- */
606
494
  INLINE: function(obj) {
607
495
  return this._visible.apply(obj, []);
608
496
  }
609
497
  },
610
498
 
611
499
  Setter: {
612
-
613
- /**
614
- *
615
- */
616
500
  MEMBER: function(obj, value) {
617
501
  if(this._strict === true && !Type.isCompatible(this._type, value)) {
618
502
  throw new TypeError(String.format("%s is not a valid %s", value, this._type));
619
503
  }
620
504
  return (obj[this._setter] = value);
621
505
  },
622
-
623
- /**
624
- *
625
- */
626
506
  METHOD: function(obj, value) {
627
507
  return obj[this._setter](value);
628
508
  },
629
-
630
- /**
631
- *
632
- */
633
509
  INLINE: function(obj, value) {
634
510
  return this._setter.apply(obj, [value]);
635
511
  }
@@ -141,18 +141,20 @@ define(function(require) {
141
141
  return r.toLowerCase();
142
142
  };
143
143
  String.escape = function (s) {
144
+ return JSON.stringify(s).slice(1, -1);
144
145
  /**
145
146
  *
146
147
  * @param s
147
148
  * @returns
148
149
  */
149
- return ('"' + s.replace(/(["\\])/g, '\\$1') + '"').
150
- replace(/[\f]/g, "\\f").
151
- replace(/[\b]/g, "\\b").
152
- replace(/\n/g, "\\n").
153
- replace(/[\t]/g, "\\t").
154
- replace(/[\r]/g, "\\r");
150
+ // return ('"' + s.replace(/(["\\])/g, '\\$1') + '"').
151
+ // replace(/[\f]/g, "\\f").
152
+ // replace(/[\b]/g, "\\b").
153
+ // replace(/\n/g, "\\n").
154
+ // replace(/[\t]/g, "\\t").
155
+ // replace(/[\r]/g, "\\r");
155
156
  };
157
+ String.unescape = (escapedString) => JSON.parse(`"${escapedString}"`);
156
158
  String.escapeHtml = function(s) {
157
159
  /**
158
160
  *
package/src/js.js CHANGED
@@ -25,7 +25,7 @@ define(function(require) {
25
25
  } catch(e) {
26
26
  return e;
27
27
  }
28
- }
28
+ }
29
29
  });
30
30
 
31
31
  });
package/src/locale.js CHANGED
@@ -14,7 +14,7 @@ define(function(require) {
14
14
 
15
15
  function locale(id) {
16
16
  var loc = locale.loc;//arguments.callee.loc;
17
-
17
+
18
18
  function resolve(id) {
19
19
  /*- Find in the dictionary */
20
20
  var r = window.locale[loc][id], i, nid, dash = id.indexOf("-"), dot = id.indexOf(".");
@@ -157,7 +157,7 @@ define(function(require) {
157
157
  locale.define(prefix, arguments[1]);
158
158
  }
159
159
 
160
- return function(id/*, ... */) {
160
+ const prefixed = function(id/*, ... */) {
161
161
  if(arguments.length === 0) {
162
162
  return prefix;
163
163
  }
@@ -171,6 +171,10 @@ define(function(require) {
171
171
  }
172
172
  return locale.apply(this, args);
173
173
  };
174
+
175
+ prefixed.has = (id) => locale.has(prefix + id);
176
+
177
+ return prefixed;
174
178
  };
175
179
  locale.define = function(prefix, defaults) {
176
180
  for(var loc in defaults) {
@@ -184,6 +188,7 @@ define(function(require) {
184
188
  // console.log(2, locale[loc], L);
185
189
  }
186
190
  };
191
+ locale.has = (key) => locale[locale.loc].hasOwnProperty(key);
187
192
 
188
193
  if(typeof window !== "undefined" && typeof window.location !== "undefined") {
189
194
  locale.loc = (location.search.split('locale=')[1]||'').split('&')[0];
@@ -240,6 +245,11 @@ define(function(require) {
240
245
  onLoad(dict);
241
246
  });
242
247
  },
248
+ mixIn: function(dict) {
249
+ const dest = locale[locale.loc], proto = {};
250
+ dict = unwrap(js.mi(js.obj2kvp(proto), js.obj2kvp(dict)));
251
+ js.mi(dest, dict);
252
+ },
243
253
  define: locale.define
244
254
  };
245
255
  });