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 +4 -0
- package/package.json +1 -1
- package/src/js/extensions.js +0 -4
- package/src/js/nameOf.js +13 -10
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/js/extensions.js
CHANGED
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
|
});
|