utilium 1.7.3 → 1.7.4

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
@@ -44,7 +44,7 @@ export function align(value, alignment) {
44
44
  */
45
45
  function _memberLength(struct, length, name) {
46
46
  if (length === undefined)
47
- return 1;
47
+ return 0;
48
48
  if (typeof length != 'string')
49
49
  return Number.isSafeInteger(length) && length >= 0
50
50
  ? length
@@ -124,7 +124,7 @@ export function serialize(instance) {
124
124
  // for unions we should write members in ascending last modified order, but we don't have that info.
125
125
  for (const [name, { type, length: rawLength, offset }] of members) {
126
126
  const length = _memberLength(instance.constructor, rawLength, name);
127
- for (let i = 0; i < length; i++) {
127
+ for (let i = 0; i < (length || 1); i++) {
128
128
  const iOff = offset + sizeof(type) * i;
129
129
  let value = length > 0 ? instance[name][i] : instance[name];
130
130
  if (typeof value == 'string') {
@@ -175,7 +175,7 @@ export function deserialize(instance, _buffer) {
175
175
  const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
176
176
  for (const [name, { type, offset, length: rawLength }] of members) {
177
177
  const length = _memberLength(instance.constructor, rawLength, name);
178
- for (let i = 0; i < length; i++) {
178
+ for (let i = 0; i < (length || 1); i++) {
179
179
  let object = length > 0 ? instance[name] : instance;
180
180
  const key = length > 0 ? i : name, iOff = offset + sizeof(type) * i;
181
181
  if (typeof instance[name] == 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",
package/src/struct.ts CHANGED
@@ -70,7 +70,7 @@ function _memberLength<T extends Metadata>(
70
70
  length: string | number | undefined,
71
71
  name: string
72
72
  ): number {
73
- if (length === undefined) return 1;
73
+ if (length === undefined) return 0;
74
74
  if (typeof length != 'string')
75
75
  return Number.isSafeInteger(length) && length >= 0
76
76
  ? length
@@ -169,7 +169,7 @@ export function serialize(instance: unknown): Uint8Array {
169
169
  // for unions we should write members in ascending last modified order, but we don't have that info.
170
170
  for (const [name, { type, length: rawLength, offset }] of members) {
171
171
  const length = _memberLength(instance.constructor, rawLength, name);
172
- for (let i = 0; i < length; i++) {
172
+ for (let i = 0; i < (length || 1); i++) {
173
173
  const iOff = offset + sizeof(type) * i;
174
174
 
175
175
  let value = length > 0 ? instance[name][i] : instance[name];
@@ -234,7 +234,7 @@ export function deserialize(instance: unknown, _buffer: ArrayBufferLike | ArrayB
234
234
 
235
235
  for (const [name, { type, offset, length: rawLength }] of members) {
236
236
  const length = _memberLength(instance.constructor, rawLength, name);
237
- for (let i = 0; i < length; i++) {
237
+ for (let i = 0; i < (length || 1); i++) {
238
238
  let object = length > 0 ? instance[name] : instance;
239
239
  const key = length > 0 ? i : name,
240
240
  iOff = offset + sizeof(type) * i;