utilium 0.3.1 → 0.3.2

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/objects.js CHANGED
@@ -33,6 +33,8 @@ export function isJSON(str) {
33
33
  }
34
34
  }
35
35
  export class FileMap {
36
+ path;
37
+ fs;
36
38
  get [Symbol.toStringTag]() {
37
39
  return 'FileMap';
38
40
  }
@@ -69,6 +71,7 @@ export class FileMap {
69
71
  * A Map overlaying a JSON file
70
72
  */
71
73
  export class JSONFileMap extends FileMap {
74
+ options;
72
75
  get [Symbol.toStringTag]() {
73
76
  return 'JSONFileMap';
74
77
  }
@@ -124,6 +127,7 @@ export class JSONFileMap extends FileMap {
124
127
  * A Map overlaying a folder
125
128
  */
126
129
  export class FolderMap extends FileMap {
130
+ options;
127
131
  get [Symbol.toStringTag]() {
128
132
  return 'FolderMap';
129
133
  }
package/dist/struct.js CHANGED
@@ -51,7 +51,7 @@ export function align(value, alignment) {
51
51
  export function struct(options = {}) {
52
52
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
53
  return function (target, _) {
54
- target[init] || (target[init] = []);
54
+ target[init] ||= [];
55
55
  let size = 0;
56
56
  const members = new Map();
57
57
  for (const { name, type, length } of target[init]) {
@@ -75,13 +75,15 @@ export function struct(options = {}) {
75
75
  */
76
76
  export function member(type, length) {
77
77
  return function (target, context) {
78
- var _a;
79
78
  let name = typeof context == 'object' ? context.name : context;
80
79
  if (typeof name == 'symbol') {
81
80
  console.warn('Symbol used for struct member name will be coerced to string: ' + name.toString());
82
81
  name = name.toString();
83
82
  }
84
- (_a = target.constructor)[init] || (_a[init] = []);
83
+ if ((typeof target != 'object' || typeof target != 'function') && !('constructor' in target)) {
84
+ throw new TypeError('Invalid member for struct field');
85
+ }
86
+ target.constructor[init] ||= [];
85
87
  target.constructor[init].push({ name, type, length });
86
88
  };
87
89
  }
@@ -147,7 +149,7 @@ export function deserialize(instance, _buffer) {
147
149
  continue;
148
150
  }
149
151
  if (length > 0) {
150
- object || (object = []);
152
+ object ||= [];
151
153
  }
152
154
  const Type = capitalize(type);
153
155
  const fn = ('get' + Type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Typescript utilies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/struct.ts CHANGED
@@ -140,6 +140,10 @@ export function member(type: ValidPrimitiveType | ClassLike, length?: number) {
140
140
  name = name.toString();
141
141
  }
142
142
 
143
+ if ((typeof target != 'object' || typeof target != 'function') && !('constructor' in target)) {
144
+ throw new TypeError('Invalid member for struct field');
145
+ }
146
+
143
147
  target.constructor[init] ||= [];
144
148
  target.constructor[init].push({ name, type, length } satisfies MemberInit);
145
149
  };