utilium 1.7.16 → 1.7.17

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/struct.js CHANGED
@@ -33,19 +33,19 @@ export function sizeof(type) {
33
33
  if (isStatic(type))
34
34
  return size;
35
35
  for (const member of struct.members.values()) {
36
- if (isInstance(member) && member.constructor[Symbol.metadata].struct.isDynamic) {
36
+ const value = type[member.name];
37
+ if (isInstance(value) && value.constructor[Symbol.metadata].struct.isDynamic) {
37
38
  if (struct.isUnion)
38
- size = Math.max(size, sizeof(member));
39
+ size = Math.max(size, sizeof(value));
39
40
  else
40
- size += sizeof(member);
41
+ size += sizeof(value);
41
42
  continue;
42
43
  }
43
44
  if (typeof member.length != 'string')
44
45
  continue;
45
46
  let subSize = 0;
46
47
  for (let i = 0; i < type[member.length]; i++) {
47
- const value = type[member.name][i];
48
- subSize += sizeof(isStruct(value) ? value : member.type);
48
+ subSize += sizeof(isStruct(value[i]) ? value[i] : member.type);
49
49
  }
50
50
  if (struct.isUnion)
51
51
  size = Math.max(size, subSize);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "1.7.16",
3
+ "version": "1.7.17",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",
package/src/struct.ts CHANGED
@@ -65,9 +65,11 @@ export function sizeof<T extends TypeLike>(type: T | T[]): Size<T> {
65
65
  if (isStatic(type)) return size as Size<T>;
66
66
 
67
67
  for (const member of struct.members.values()) {
68
- if (isInstance(member) && member.constructor[Symbol.metadata].struct.isDynamic) {
69
- if (struct.isUnion) size = Math.max(size, sizeof(member));
70
- else size += sizeof(member);
68
+ const value = (type as any)[member.name];
69
+
70
+ if (isInstance(value) && value.constructor[Symbol.metadata].struct.isDynamic) {
71
+ if (struct.isUnion) size = Math.max(size, sizeof(value));
72
+ else size += sizeof(value);
71
73
  continue;
72
74
  }
73
75
 
@@ -76,9 +78,7 @@ export function sizeof<T extends TypeLike>(type: T | T[]): Size<T> {
76
78
  let subSize = 0;
77
79
 
78
80
  for (let i = 0; i < (type as any)[member.length]; i++) {
79
- const value = (type as any)[member.name][i];
80
-
81
- subSize += sizeof(isStruct(value) ? value : member.type);
81
+ subSize += sizeof(isStruct(value[i]) ? value[i] : member.type);
82
82
  }
83
83
 
84
84
  if (struct.isUnion) size = Math.max(size, subSize);