@lumjs/core 1.5.0 → 1.5.1
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/docs/changelogs/1.x.md +9 -1
- package/lib/meta.js +60 -7
- package/package.json +1 -1
package/docs/changelogs/1.x.md
CHANGED
|
@@ -6,6 +6,13 @@ See [Changelogs](index.md) for more information on the changelogs.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.5.1] - 2022-09-29
|
|
10
|
+
### Changed
|
|
11
|
+
- Removed `constructor()` from `AbstractClass`.
|
|
12
|
+
- Added `$needs()` to `AbstractClass`.
|
|
13
|
+
### Fixed
|
|
14
|
+
- `AbstractClass` actually works properly now.
|
|
15
|
+
|
|
9
16
|
## [1.5.0] - 2022-09-27
|
|
10
17
|
### Changed
|
|
11
18
|
- Updated a few DocBlocks.
|
|
@@ -91,7 +98,8 @@ See [Changelogs](index.md) for more information on the changelogs.
|
|
|
91
98
|
- See [1.0-beta.md](1.0-beta.md) for the beta versions of `1.0`
|
|
92
99
|
- See [lum.js](https://github.com/supernovus/lum.js) for the original library set this is replacing.
|
|
93
100
|
|
|
94
|
-
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.5.
|
|
101
|
+
[Unreleased]: https://github.com/supernovus/lum.core.js/compare/v1.5.1...HEAD
|
|
102
|
+
[1.5.1]: https://github.com/supernovus/lum.core.js/compare/v1.5.0...v1.5.1
|
|
95
103
|
[1.5.0]: https://github.com/supernovus/lum.core.js/compare/v1.4.0...v1.5.0
|
|
96
104
|
[1.4.0]: https://github.com/supernovus/lum.core.js/compare/v1.3.1...v1.4.0
|
|
97
105
|
[1.3.1]: https://github.com/supernovus/lum.core.js/compare/v1.3.0...v1.3.1
|
package/lib/meta.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* @module @lumjs/core/meta
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const {F,S,isArray,isa} = require('./types');
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Get a stacktrace. Differs from browser to browser.
|
|
8
10
|
*
|
|
@@ -30,20 +32,71 @@ exports.stacktrace = stacktrace;
|
|
|
30
32
|
class AbstractClass
|
|
31
33
|
{
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* If you want to mark a method as abstract use this.
|
|
34
36
|
*/
|
|
35
|
-
|
|
37
|
+
$abstract(name)
|
|
36
38
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (name.indexOf('(') === -1)
|
|
40
|
+
{ // Add empty method signature.
|
|
41
|
+
name += '()';
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Abstract method ${name} was not implemented`);
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/**
|
|
42
|
-
*
|
|
47
|
+
* Check for required properties
|
|
48
|
+
*
|
|
49
|
+
* @param {...(string|Array)} needs - What is needed
|
|
50
|
+
*
|
|
51
|
+
* If this is a `string` it should be in a format like:
|
|
52
|
+
*
|
|
53
|
+
* - `methodName(arg1,arg2,arg3)`
|
|
54
|
+
* - `anotherMethod(number, string, object) : boolean`
|
|
55
|
+
* - `yetAnother (className) : resultClass`
|
|
56
|
+
*
|
|
57
|
+
* The names are case sensitive, and we'll look for the method after
|
|
58
|
+
* stripping off anything from the first *non-word* character.
|
|
59
|
+
*
|
|
60
|
+
* If this is an `Array`, the first item must be the name of a property,
|
|
61
|
+
* and each other item should be a type checking value, or array of type
|
|
62
|
+
* checking values from the [TYPES]{@link module:@lumjs/core/types.TYPES}
|
|
63
|
+
* object, as used by [isa()]{@link module:@lumjs/core/types.isa}.
|
|
64
|
+
*
|
|
65
|
+
* If you are calling this in an abstract class constructor, likely only
|
|
66
|
+
* the method checks will be useful, as the `super()` call must be done
|
|
67
|
+
* *before* any instance property assignments.
|
|
68
|
+
*
|
|
43
69
|
*/
|
|
44
|
-
$
|
|
70
|
+
$needs(...needs)
|
|
45
71
|
{
|
|
46
|
-
|
|
72
|
+
const className = this.constructor.name;
|
|
73
|
+
|
|
74
|
+
const getName = fullName => fullName.replace(/\W.*/, '');
|
|
75
|
+
const missing = propName =>
|
|
76
|
+
{
|
|
77
|
+
throw new Error(`${className} is missing ${propName}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const need of needs)
|
|
81
|
+
{
|
|
82
|
+
if (typeof need === S)
|
|
83
|
+
{ // A simple method
|
|
84
|
+
const meth = getName(need);
|
|
85
|
+
if (typeof this[meth] !== F)
|
|
86
|
+
{
|
|
87
|
+
missing(need);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (isArray(need))
|
|
91
|
+
{
|
|
92
|
+
const prop = getName(need[0]);
|
|
93
|
+
const types = need.slice(1);
|
|
94
|
+
if (!isa(this[prop], ...types))
|
|
95
|
+
{
|
|
96
|
+
missing(need);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
47
100
|
}
|
|
48
101
|
|
|
49
102
|
}
|