cavalion-js 1.0.71 โ†’ 1.0.73

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,4 +1,6 @@
1
- * [CHANGELOG.md]() - [README.md]() - [package.json]() - [.js]()
1
+ * [CHANGELOG.md]() - [README.md]() - [package.json]()
2
+ * [.workspace](`(devtools/Workspace<${ws.getSpecializer()}>)`) - [.js]()
3
+
2
4
 
3
5
  # cavalion-js
4
6
 
@@ -45,15 +47,34 @@
45
47
  - [Scaffold.js](src/js/:)
46
48
  - [Type.js](src/js/:)
47
49
 
48
- # `0913`
50
+ # `2022/11/02`
51
+
52
+ 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.
53
+
54
+ if(!js.waitAll) {
55
+ js.waitAll = function(/* ... */) {
56
+ return Promise.all(js.copy_args(arguments).flat().map(p => {
57
+ if(typeof p === "string" && p.endsWith("ms")) { // for syntax/code that says it all
58
+ return new Promise(resolve => setTimeout(resolve, parseInt(p, 10)));
59
+ } else if(typeof p === "number") { // ok, we'll do this too ;-)
60
+ return new Promise(resolve => setTimeout(resolve, p));
61
+ } else if(!(p instanceof Promise)) {
62
+ throw new Error("Can not wait for", p);
63
+ }
64
+ return p;
65
+ }));
66
+ }
67
+ }
68
+
69
+ # `2022/09/13`
49
70
 
50
- Working on [README.md]().
71
+ * Working on [README.md]().
51
72
 
52
- # `0725`
73
+ # `2022/07/25`
53
74
 
54
- Enhancing `js.groupBy` to accept multiple keys for grouping.
75
+ * Enhancing `js.groupBy` to accept multiple keys for grouping.
55
76
 
56
- # `0429`
77
+ # `2022/04/29`
57
78
 
58
79
  I want to be able to activate these source files with [an overlay]([!prototypes/Hover]{}) of Markdown. Or... no, I want to overlay the source I guess. ๐Ÿ˜‡๐Ÿคจ๐Ÿค”
59
80
 
@@ -72,7 +93,7 @@ Still, it would be nice to just:
72
93
  * Press (**โ‡งโŒ˜.**) and overlay _the current context_ (whatever that might be anyways, probably a JavaScript module, rapportage-script) with _whatever_, starting with a _context-local_-[.md]()-file, sprouting in to whatever, but _mas-que-nada_ a starting point in order to...
73
94
  * ...overlay notes, bookmarks, links, scripts, photos, ...
74
95
 
75
- # `0424`
96
+ # `2022/04/24`
76
97
 
77
98
  * `js.args(arr)` - concats and filters `arr` for non-undefined values
78
99
 
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 2023/03/01 - 1.0.73
2
+
3
+ * Introduces `js.mi` alias for `js.mixIn`
4
+ * Fixes a bug in `js.sf` (ie. String.format) where specifiers where not handled correctly for %X.Yf like formats
5
+
6
+ ### 2022/11/15 - 1.0.72
7
+
8
+ * DocumentHook: Adds the events onmouseover and onmouseout
9
+
10
+ ### 2022/11/07
11
+
12
+ * Adds `js.waitAll()`
13
+
1
14
  ### 2022/07/28 10/29 - 1.0.71
2
15
 
3
16
  * Adjusts/enhances `js.groupBy()` to use js.get(key,obj) in case obj doesn't have key
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Cavalion common JavaScript library. It consist of:
4
4
 
5
5
  * Constructor class registration
6
- * Console
6
+ * Console printing out vars
7
7
  * Data interfaces
8
8
  * Design(er) package (in development)
9
9
  * Utility Classes
@@ -27,7 +27,7 @@ Cavalion common JavaScript library. It consist of:
27
27
  * [JsObject](src/js/:.js) - _kind of super class_
28
28
  * [Method](src/js/:.js) - _hacking with functions_
29
29
  * [Class](src/js/:.js) - _Class.make() is where the meat is_
30
- * [extensions](src/js/:.js)
30
+ * [extensions](src/js/:.js) - _extending native JS objects_
31
31
  * [mixIn](src/js/:.js)
32
32
  * [nameOf](src/js/:.js)
33
33
  * [Method](src/js/:.js)
@@ -0,0 +1,69 @@
1
+ # JavaScript Classes: The Complete Guide To Creating Your Own Custom Class System
2
+
3
+ JavaScript is a powerful programming language that allows you to create custom code that works in the browser. If you want to create your own custom class system, then this article is for you. It will teach you how to define classes in JavaScript and turn them into something that can be used anywhere on your website.
4
+
5
+ ## The Basics of JavaScript Classes
6
+
7
+ In JavaScript, a class is just a special type of function. Classes are in fact "special functions", and just like you can define function expressions and function declarations, the same goes for classes.
8
+ There are two ways to create a class in JavaScript:
9
+
10
+ The first way is to use a class declaration. To do this, you use the class keyword followed by the name of the class. For example:
11
+
12
+ class Rectangle {
13
+ // ...
14
+ }
15
+
16
+ This creates a new class called Rectangle. You can then add properties and methods to this class by using the prototype property of the Rectangle class:
17
+
18
+ Rectangle.prototype.width = 10;
19
+ Rectangle.prototype.height = 5;
20
+
21
+ You can also add methods to the prototype:
22
+
23
+ Rectangle.prototype.getArea = function() {
24
+ return this.width * this.height;
25
+ }
26
+
27
+ ## Defining a Class System in JavaScript
28
+
29
+ In JavaScript, a class is a blueprint for an object. It is a template that you can use to create new objects with the same characteristics. A class system is a way of organizing and defining classes so that they can be easily reused and extended.
30
+
31
+ There are several ways to define a class system in JavaScript. The most common way is to use the prototype-based approach. This approach uses the prototype property of objects to create new classes. The prototype property is an object that contains the properties and methods that will be inherited by all instances of the class.
32
+
33
+ Another way to define a class system in JavaScript is to use the constructor function. This function allows you to create objects with the same characteristics as the constructor function's prototype object. The constructor function is used to initialize the new object's properties and methods.
34
+
35
+ Once you have defined your class system, you can use it to create new objects. To do this, you first need to create a constructor function for your class. This function will take any arguments that you want to pass into your new object. Once you have created your constructor function, you can then use the new keyword to create an instance of your class.
36
+
37
+ ## Step by Step Creation of a Class Definition
38
+
39
+ Assuming you have a basic understanding of Object-Oriented Programming concepts, creating a class in JavaScript is very simple. In fact, there are only a few steps involved:
40
+
41
+ * 1) First, create a function that will serve as the class constructor. This function should accept any parameters that you wish to pass into the class instance when it is created.
42
+
43
+ * 2) Next, create any properties or methods that you wish to add to the class. These can be defined directly within the constructor function, or they can be added after the fact using the prototype object.
44
+
45
+ * 3) Finally, return the newly created class from the constructor function.
46
+
47
+ That's all there is to it! With these three steps, you can create your own custom classes in JavaScript.
48
+
49
+ ## Using the New Class in JS
50
+
51
+ Assuming you have a basic understanding of JavaScript classes, let's explore how to use the new class in JS.
52
+
53
+ As we discussed earlier, the new keyword is used to create an instance of a class. When creating an instance of a class, you must provide the arguments that will be passed to the class constructor function. For example:
54
+
55
+ class MyClass {
56
+ constructor(arg1, arg2) {
57
+ this.arg1 = arg1;
58
+ this.arg2 = arg2;
59
+ }
60
+ myMethod() {
61
+ // do something with this.arg1 and this.arg2 here
62
+ }
63
+ }
64
+
65
+ const myInstance = new MyClass('foo', 'bar');
66
+
67
+ ## Conclusion
68
+
69
+ In conclusion, JavaScript classes provide a great way to create your own custom class system. With the help of this guide, you should now be able to create your own custom classes and use them in your web development projects. If you have any questions or if there is anything we missed, please feel free to reach out and let us know. We would be more than happy to help you out.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/js/Class.js CHANGED
@@ -29,7 +29,6 @@ define(function(require) {
29
29
  }
30
30
  return classMap["js/JsObject"];
31
31
  }
32
-
33
32
  function classConstructorToString() {
34
33
  /**
35
34
  * toString implementation for constructors
@@ -39,7 +38,6 @@ define(function(require) {
39
38
  }
40
39
  return Function.prototype.toString.apply(this, arguments);
41
40
  }
42
-
43
41
  function namedFunction(name, f) {
44
42
  /**
45
43
  * This is Chrome specific (as far as I know). It will show fancy names for
@@ -76,7 +74,6 @@ define(function(require) {
76
74
  }
77
75
  return f;
78
76
  }
79
-
80
77
  function createConstructor(name) {
81
78
  /**
82
79
  * Create a constructor function used for instances of Class.defin(e)itions
package/src/js/_js.js CHANGED
@@ -33,17 +33,14 @@ define(function(require) {
33
33
  $: JsObject.$,
34
34
 
35
35
  b: beautify,
36
- m: minify,
36
+ m: minify, mi: mixIn,
37
37
  n: nameOf,
38
38
  sj: JSON.stringify,//serialize.serialize,
39
39
  pj: JSON.parse,
40
40
  sf: String.format,
41
41
  nameOf: nameOf,
42
42
  defineClass: defineClass,
43
- mixIn: mixIn,
44
- // groupBy: (arr, key) => {
45
- // return arr.reduce((a, o) => ((a[js.get(key, o)] || (a[js.get(key, o)] = [])).push(o), a), {});
46
- // },
43
+ mixIn: mixIn,
47
44
  groupBy: (arr, keys, mth) => {
48
45
  /*- groupBy: receives an array of objects and returns an object
49
46
  which keys hold reference to the resulting groups.
@@ -381,6 +378,17 @@ define(function(require) {
381
378
  * @returns
382
379
  */
383
380
  return window.clearTimeout(id);
384
- }
385
- });
381
+ },
382
+ waitAll: function(/* ... */) {
383
+ return Promise.all(js.copy_args(arguments).flat().map(p => {
384
+ if(typeof p === "string" && p.endsWith("ms")) { // for syntax/code that says it all
385
+ return new Promise(resolve => setTimeout(resolve, parseInt(p, 10)));
386
+ } else if(typeof p === "number") { // ok, we'll do this too ;-)
387
+ return new Promise(resolve => setTimeout(resolve, p));
388
+ } else if(!(p instanceof Promise)) {
389
+ throw new Error("Can not wait for", p);
390
+ }
391
+ return p;
392
+ }));
393
+ }, });
386
394
  });
@@ -274,10 +274,11 @@ define(function(require) {
274
274
  }
275
275
  s.push(value);
276
276
  } else if(ch === "f") {
277
- if (mod.charAt(0) === ".") {
278
- len = parseInt(mod.substring(1), 10) || 0;
277
+ mod = mod.split(".");
278
+ if(mod.length === 2) {
279
+ len = parseInt(mod[1], 10) || 0;
279
280
  value = arguments[i++];
280
- var i1 = parseInt(value, 10) || 0;
281
+ var i1 = String.format("%" + mod[0] + "d", value);
281
282
  var f = Math.abs(value - i1);
282
283
  f *= Math.pow(10, len + 1);
283
284
  f = "" + Math.round(Math.round(f) / 10);
@@ -375,6 +376,16 @@ define(function(require) {
375
376
  }
376
377
  return n;
377
378
  };
379
+ Math.f_= (value, regexps) => {
380
+ if(value === undefined || value === null) return null;
381
+
382
+ regexps = regexps || [/0000+.$/, /9999+.$/];
383
+
384
+ value = value.toString();
385
+ regexps.forEach(re => value = value.replace(re, ""));
386
+
387
+ return parseFloat(value);
388
+ };
378
389
 
379
390
 
380
391
  /*--- */
@@ -18,7 +18,7 @@ define(function(require) {
18
18
  _events: [
19
19
  "ontransitionend",
20
20
  "ontouchstart", "ontouchend", "ontouchmove", "ontap", "ondbltap", "ongesture",
21
- "onclick", "ondblclick",
21
+ "onclick", "ondblclick", "onmouseout", "onmouseover",
22
22
  "onmousemove", "onmousedown", "onmouseup", "_onmousewheel", "onmouseenter", "onmouseleave",
23
23
  "onkeydown", "onkeyup", "onkeypress",
24
24
  "onfocus", "onblur",
package/src/util/Xml.js CHANGED
@@ -1,8 +1,31 @@
1
1
  define(function() {
2
-
2
+
3
+ var prettifyXml = function(sourceXml) {
4
+ var xmlDoc = new DOMParser().parseFromString(sourceXml, 'application/xml');
5
+ var xsltDoc = new DOMParser().parseFromString([
6
+ // describes how we want to modify the XML - indent everything
7
+ '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">',
8
+ ' <xsl:strip-space elements="*"/>',
9
+ ' <xsl:template match="para[content-style][not(text())]">', // change to just text() to strip space in text nodes
10
+ ' <xsl:value-of select="normalize-space(.)"/>',
11
+ ' </xsl:template>',
12
+ ' <xsl:template match="node()|@*">',
13
+ ' <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>',
14
+ ' </xsl:template>',
15
+ ' <xsl:output indent="yes"/>',
16
+ '</xsl:stylesheet>',
17
+ ].join('\n'), 'application/xml');
18
+
19
+ var xsltProcessor = new XSLTProcessor();
20
+ xsltProcessor.importStylesheet(xsltDoc);
21
+ var resultDoc = xsltProcessor.transformToDocument(xmlDoc);
22
+ var resultXml = new XMLSerializer().serializeToString(resultDoc);
23
+ return resultXml;
24
+ };
25
+
3
26
  var Xml = {
4
-
5
- beautify(xml) {
27
+ beautify: prettifyXml,
28
+ beautify_(xml) {
6
29
  var formatted = "";
7
30
  var reg = /(>)(<)(\/*)/g;
8
31
  xml = xml.replace(reg, "$1\n$2$3");