@util.js/privates 0.41.1 → 0.41.3
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/dist/Privates.js +20 -57
- package/package.json +4 -4
package/dist/Privates.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/weak-map"));
|
|
6
|
-
|
|
7
5
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
8
|
-
|
|
9
6
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
10
|
-
|
|
11
7
|
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
12
|
-
|
|
13
8
|
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
14
|
-
|
|
15
9
|
var _getPrototypeOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of"));
|
|
16
|
-
|
|
17
10
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
18
|
-
|
|
19
11
|
var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
|
|
20
|
-
|
|
21
12
|
var _getOwnPropertyNames = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-names"));
|
|
22
|
-
|
|
23
13
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
24
|
-
|
|
25
14
|
var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
|
|
26
|
-
|
|
27
15
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
28
|
-
|
|
29
16
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
30
|
-
|
|
31
17
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
32
|
-
|
|
33
18
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
34
|
-
|
|
35
19
|
var RethrownError = require("@util.js/errors/RethrownError");
|
|
20
|
+
|
|
36
21
|
/**
|
|
37
22
|
* JavaScript utility class for private member variables.
|
|
38
23
|
*
|
|
@@ -56,21 +41,18 @@ var RethrownError = require("@util.js/errors/RethrownError");
|
|
|
56
41
|
* @public
|
|
57
42
|
* @class Privates
|
|
58
43
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
44
|
module.exports = /*#__PURE__*/function () {
|
|
62
45
|
function Privates() {
|
|
63
46
|
(0, _classCallCheck2["default"])(this, Privates);
|
|
64
47
|
this.privates = new _weakMap["default"]();
|
|
65
48
|
}
|
|
49
|
+
|
|
66
50
|
/**
|
|
67
51
|
* Calls `this.get(thiz, property)()`.
|
|
68
52
|
*
|
|
69
53
|
* @public
|
|
70
54
|
* @function Privates#call
|
|
71
55
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
56
|
(0, _createClass2["default"])(Privates, [{
|
|
75
57
|
key: "call",
|
|
76
58
|
value: function call(thiz, property) {
|
|
@@ -81,7 +63,6 @@ module.exports = /*#__PURE__*/function () {
|
|
|
81
63
|
return this.get(thiz, property)();
|
|
82
64
|
} catch (e) {
|
|
83
65
|
var _context, _context2;
|
|
84
|
-
|
|
85
66
|
var propertyStr = getPropertyErrorString(property);
|
|
86
67
|
throw new RethrownError(e, (0, _concat["default"])(_context = (0, _concat["default"])(_context2 = "privates.call(".concat(thiz, ", ")).call(_context2, propertyStr, ") failed. ")).call(_context, e.message));
|
|
87
68
|
}
|
|
@@ -93,7 +74,6 @@ module.exports = /*#__PURE__*/function () {
|
|
|
93
74
|
return this.getProps(thiz)[property];
|
|
94
75
|
} catch (e) {
|
|
95
76
|
var _context3, _context4;
|
|
96
|
-
|
|
97
77
|
var propertyStr = getPropertyErrorString(property);
|
|
98
78
|
throw new RethrownError(e, (0, _concat["default"])(_context3 = (0, _concat["default"])(_context4 = "privates.get(".concat(thiz, ", ")).call(_context4, propertyStr, ") failed. ")).call(_context3, e.message));
|
|
99
79
|
}
|
|
@@ -122,13 +102,11 @@ module.exports = /*#__PURE__*/function () {
|
|
|
122
102
|
value: function lambdaize(properties) {
|
|
123
103
|
try {
|
|
124
104
|
var _context5;
|
|
125
|
-
|
|
126
105
|
var lambdaProperties = {};
|
|
127
106
|
(0, _forEach["default"])(_context5 = (0, _entries["default"])(properties)).call(_context5, function (_ref) {
|
|
128
107
|
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
108
|
+
property = _ref2[0],
|
|
109
|
+
value = _ref2[1];
|
|
132
110
|
return lambdaProperties[property] = function () {
|
|
133
111
|
return value;
|
|
134
112
|
};
|
|
@@ -149,7 +127,6 @@ module.exports = /*#__PURE__*/function () {
|
|
|
149
127
|
value = lazyLoadFunction();
|
|
150
128
|
loaded = true;
|
|
151
129
|
}
|
|
152
|
-
|
|
153
130
|
return value;
|
|
154
131
|
});
|
|
155
132
|
}
|
|
@@ -157,19 +134,15 @@ module.exports = /*#__PURE__*/function () {
|
|
|
157
134
|
key: "lazyLoadProps",
|
|
158
135
|
value: function lazyLoadProps(thiz) {
|
|
159
136
|
var t = this;
|
|
160
|
-
|
|
161
137
|
for (var _len = arguments.length, lazilyLoadedProperties = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
162
138
|
lazilyLoadedProperties[_key - 1] = arguments[_key];
|
|
163
139
|
}
|
|
164
|
-
|
|
165
140
|
(0, _forEach["default"])(lazilyLoadedProperties).call(lazilyLoadedProperties, function (currentProperties) {
|
|
166
141
|
var _context6;
|
|
167
|
-
|
|
168
142
|
(0, _forEach["default"])(_context6 = (0, _entries["default"])(currentProperties)).call(_context6, function (_ref3) {
|
|
169
143
|
var _ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
144
|
+
property = _ref4[0],
|
|
145
|
+
lazyLoadFunction = _ref4[1];
|
|
173
146
|
return t.lazyLoad(thiz, property, lazyLoadFunction);
|
|
174
147
|
});
|
|
175
148
|
});
|
|
@@ -181,7 +154,6 @@ module.exports = /*#__PURE__*/function () {
|
|
|
181
154
|
this.getProps(thiz)[property] = newValue;
|
|
182
155
|
} catch (e) {
|
|
183
156
|
var _context7, _context8, _context9;
|
|
184
|
-
|
|
185
157
|
var propertyStr = getPropertyErrorString(property);
|
|
186
158
|
throw new RethrownError(e, (0, _concat["default"])(_context7 = (0, _concat["default"])(_context8 = (0, _concat["default"])(_context9 = "privates.set(".concat(thiz, ", ")).call(_context9, propertyStr, ", ")).call(_context8, newValue, ") failed. ")).call(_context7, e.message));
|
|
187
159
|
}
|
|
@@ -190,24 +162,19 @@ module.exports = /*#__PURE__*/function () {
|
|
|
190
162
|
key: "setProps",
|
|
191
163
|
value: function setProps(thiz) {
|
|
192
164
|
var t = this;
|
|
193
|
-
|
|
194
165
|
for (var _len2 = arguments.length, properties = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
195
166
|
properties[_key2 - 1] = arguments[_key2];
|
|
196
167
|
}
|
|
197
|
-
|
|
198
168
|
(0, _forEach["default"])(properties).call(properties, function (currentProperties) {
|
|
199
169
|
var _context10, _context11;
|
|
200
|
-
|
|
201
170
|
(0, _forEach["default"])(_context10 = (0, _entries["default"])(currentProperties)).call(_context10, function (_ref5) {
|
|
202
171
|
var _ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
172
|
+
property = _ref6[0],
|
|
173
|
+
value = _ref6[1];
|
|
206
174
|
return t.set(thiz, property, value);
|
|
207
175
|
});
|
|
208
176
|
(0, _forEach["default"])(_context11 = getAllMethods(currentProperties)).call(_context11, function (method) {
|
|
209
177
|
var _context12;
|
|
210
|
-
|
|
211
178
|
return t.set(thiz, method, (0, _bind["default"])(_context12 = currentProperties[method]).call(_context12, currentProperties));
|
|
212
179
|
});
|
|
213
180
|
});
|
|
@@ -216,54 +183,50 @@ module.exports = /*#__PURE__*/function () {
|
|
|
216
183
|
key: "subset",
|
|
217
184
|
value: function subset(thiz) {
|
|
218
185
|
var object = {};
|
|
219
|
-
|
|
220
186
|
for (var _len3 = arguments.length, properties = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
221
187
|
properties[_key3 - 1] = arguments[_key3];
|
|
222
188
|
}
|
|
223
|
-
|
|
224
|
-
for (var i = 0; i < properties.length; i++) {
|
|
225
|
-
object[properties[i]] = this.get(thiz, properties[i]);
|
|
226
|
-
}
|
|
227
|
-
|
|
189
|
+
for (var i = 0; i < properties.length; i++) object[properties[i]] = this.get(thiz, properties[i]);
|
|
228
190
|
return object;
|
|
229
191
|
}
|
|
230
192
|
}]);
|
|
231
193
|
return Privates;
|
|
232
194
|
}();
|
|
233
|
-
|
|
234
195
|
function getPropertyErrorString(property) {
|
|
235
196
|
// https://stackoverflow.com/a/7772724
|
|
236
197
|
if (typeof property === "string" || property instanceof String) return "\"".concat(property, "\"");
|
|
237
198
|
return "".concat(property);
|
|
238
199
|
}
|
|
239
|
-
|
|
240
200
|
function callProp(obj, property) {
|
|
241
201
|
try {
|
|
242
202
|
return obj[property]();
|
|
243
203
|
} catch (e) {
|
|
244
204
|
throw new RethrownError(e, "Calling \"".concat(property, "\" as a function failed."));
|
|
245
205
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
206
|
+
}
|
|
248
207
|
|
|
208
|
+
// https://stackoverflow.com/questions/31054910/get-functions-methods-of-a-class
|
|
249
209
|
function getAllMethods(obj) {
|
|
250
210
|
if (!(0, _getPrototypeOf["default"])(obj)) return [];
|
|
251
211
|
var props = [];
|
|
252
|
-
|
|
253
212
|
do {
|
|
254
213
|
var _context13, _context14, _context15, _context16;
|
|
255
|
-
|
|
256
214
|
var l = (0, _filter["default"])(_context13 = (0, _sort["default"])(_context14 = (0, _concat["default"])(_context15 = (0, _getOwnPropertyNames["default"])(obj)).call(_context15, (0, _map["default"])(_context16 = (0, _getOwnPropertySymbols["default"])(obj)).call(_context16, function (s) {
|
|
257
215
|
return s.toString();
|
|
258
216
|
}))).call(_context14)).call(_context13, function (p, i, arr) {
|
|
259
|
-
return typeof obj[p] === "function" &&
|
|
260
|
-
|
|
261
|
-
|
|
217
|
+
return typeof obj[p] === "function" &&
|
|
218
|
+
// only the methods
|
|
219
|
+
p !== "constructor" && (
|
|
220
|
+
// not the constructor
|
|
221
|
+
i === 0 || p !== arr[i - 1]) &&
|
|
222
|
+
// not overriding in this prototype
|
|
262
223
|
(0, _indexOf["default"])(props).call(props, p) === -1;
|
|
263
224
|
} // not overridden in a child
|
|
264
225
|
);
|
|
226
|
+
|
|
265
227
|
props = (0, _concat["default"])(props).call(props, l);
|
|
266
|
-
} while ((obj = (0, _getPrototypeOf["default"])(obj)) &&
|
|
228
|
+
} while ((obj = (0, _getPrototypeOf["default"])(obj)) &&
|
|
229
|
+
// walk-up the prototype chain
|
|
267
230
|
(0, _getPrototypeOf["default"])(obj) // not the the Object prototype methods (hasOwnProperty, etc...)
|
|
268
231
|
);
|
|
269
232
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@babel/runtime-corejs3": "7.
|
|
5
|
-
"@util.js/errors": "0.41.
|
|
4
|
+
"@babel/runtime-corejs3": "7.21.0",
|
|
5
|
+
"@util.js/errors": "0.41.3"
|
|
6
6
|
},
|
|
7
7
|
"description": "JavaScript utility class for private member variables",
|
|
8
8
|
"keywords": [
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"type": "git",
|
|
30
30
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-privates"
|
|
31
31
|
},
|
|
32
|
-
"version": "0.41.
|
|
33
|
-
"gitHead": "
|
|
32
|
+
"version": "0.41.3",
|
|
33
|
+
"gitHead": "e17139b7f85c3abec178d8facdacc2aa6c5bb553"
|
|
34
34
|
}
|