cavalion-js 1.0.66 → 1.0.67

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,3 +1,7 @@
1
+ ### 2022/01/02 - 1.0.67
2
+
3
+ * Introducing `js.nameOf.methods.set(name, impl)` - it allows for overriding/extending a certain method iteratively
4
+
1
5
  ### 2021/12/17 - 1.0.66
2
6
 
3
7
  - Enhancing `locale`, now supporting references with the ::-prefix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cavalion-js",
3
- "version": "1.0.66",
3
+ "version": "1.0.67",
4
4
  "description": "Cavalion common JavaScript library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -112,10 +112,6 @@ define(function(require) {
112
112
  }
113
113
 
114
114
  if(String.of === undefined) {
115
- /**
116
- *
117
- * @param obj
118
- */
119
115
  String.of = function(obj) {
120
116
  return obj && obj.toString();
121
117
  };
package/src/js/nameOf.js CHANGED
@@ -1,6 +1,10 @@
1
1
  define(function() {
2
+
3
+ String.of = function(obj) { // TODO require("String.of")
4
+ return nameOf(obj);
5
+ };
2
6
 
3
- var methods = [
7
+ var methods = (nameOf.methods = [
4
8
  (obj) => (obj.id || obj.Id || obj.ID),
5
9
  (obj) => (obj.opmerking || obj.Opmerking),
6
10
  (obj) => (obj.naam || obj.omschrijving || obj.code || obj.name || obj.description),
@@ -14,12 +18,18 @@ define(function() {
14
18
 
15
19
  // return typeof s === "string" ? s : undefined;
16
20
  // }
17
- ];
18
-
21
+ ]);
22
+
19
23
  methods.before = [];
20
24
  methods.after = [
21
25
  (obj) => obj instanceof Array ? nameOfArr(obj): undefined
22
26
  ];
27
+ methods.set = (name, impl) => {
28
+ if(!methods[name]) {
29
+ methods.push((obj) => methods[name](obj));
30
+ }
31
+ return (methods[name] = impl);
32
+ };
23
33
 
24
34
  function nameOf(obj, test) {
25
35
  if(obj === undefined || obj === null) return String(obj);
@@ -53,18 +63,11 @@ define(function() {
53
63
  return test ? ["one-of", obj.toString(), obj.constructor.prototype.toString.apply(obj, []), String(obj)]
54
64
  : obj ? obj.toString() || obj.constructor.prototype.toString.apply(obj, []) : String(obj);
55
65
  }
56
-
57
66
  function nameOfArr(arr) {
58
67
  var ignore = [undefined, "[object Object]"];
59
68
  var names = arr.map(obj => js.nameOf(obj)).filter(_ => ignore.indexOf(_) !== -1);
60
69
  return names.length ? names.join(", ") : js.sf("%s item%s", arr.length || "No", arr.length !== -1 ? "s" : "");
61
70
  }
62
71
 
63
- String.of = function(obj) {
64
- return nameOf(obj);
65
- };
66
-
67
- nameOf.methods = methods;
68
-
69
72
  return nameOf;
70
73
  });