@garmin/fitsdk 21.141.0 → 21.161.0

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/src/stream.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /////////////////////////////////////////////////////////////////////////////////////////////
2
- // Copyright 2024 Garmin International, Inc.
2
+ // Copyright 2025 Garmin International, Inc.
3
3
  // Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
4
4
  // may not use this file except in compliance with the Flexible and Interoperable Data
5
5
  // Transfer (FIT) Protocol License.
6
6
  /////////////////////////////////////////////////////////////////////////////////////////////
7
7
  // ****WARNING**** This file is auto-generated! Do NOT edit this file.
8
- // Profile Version = 21.141.0Release
9
- // Tag = production/release/21.141.0-0-g2aa27e1
8
+ // Profile Version = 21.161.0Release
9
+ // Tag = production/release/21.161.0-0-g58854c0
10
10
  /////////////////////////////////////////////////////////////////////////////////////////////
11
11
 
12
12
 
@@ -112,10 +112,10 @@ class Stream {
112
112
  throw Error(`FIT Runtime Error end of stream at byte ${this.#position}`);
113
113
  }
114
114
 
115
- const bytes = this.#arrayBuffer.slice(this.#position, this.#position + size);
115
+ const bytes = new Uint8Array(this.#arrayBuffer, this.#position, size);
116
116
  this.#position += size;
117
117
 
118
- this.#crcCalculator?.addBytes(new Uint8Array(bytes), 0, size);
118
+ this.#crcCalculator?.addBytes(bytes, 0, size);
119
119
 
120
120
  return bytes;
121
121
  }
@@ -168,14 +168,14 @@ class Stream {
168
168
  const baseTypeSize = FIT.BaseTypeDefinitions[baseType].size;
169
169
  const baseTypeInvalid = FIT.BaseTypeDefinitions[baseType].invalid;
170
170
 
171
- const arrayBuffer = this.readBytes(size);
171
+ const bytes = this.readBytes(size);
172
172
 
173
173
  if (size % baseTypeSize !== 0) {
174
174
  return convertInvalidToNull ? null : baseTypeInvalid;
175
175
  }
176
176
 
177
177
  if (baseType === FIT.BaseType.STRING) {
178
- const string = this.#textDecoder.decode(arrayBuffer).replace(/\uFFFD/g, "");
178
+ const string = this.#textDecoder.decode(bytes).replace(/\uFFFD/g, "");
179
179
  const strings = string.split('\0');
180
180
 
181
181
  while (strings[strings.length - 1] === "") {
@@ -189,7 +189,7 @@ class Stream {
189
189
  return strings.length === 1 ? strings[0] : strings;
190
190
  }
191
191
 
192
- const dataView = new DataView(arrayBuffer);
192
+ const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
193
193
  let values = [];
194
194
 
195
195
  const count = size / baseTypeSize;
@@ -1,12 +1,12 @@
1
1
  /////////////////////////////////////////////////////////////////////////////////////////////
2
- // Copyright 2024 Garmin International, Inc.
2
+ // Copyright 2025 Garmin International, Inc.
3
3
  // Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
4
4
  // may not use this file except in compliance with the Flexible and Interoperable Data
5
5
  // Transfer (FIT) Protocol License.
6
6
  /////////////////////////////////////////////////////////////////////////////////////////////
7
7
  // ****WARNING**** This file is auto-generated! Do NOT edit this file.
8
- // Profile Version = 21.141.0Release
9
- // Tag = production/release/21.141.0-0-g2aa27e1
8
+ // Profile Version = 21.161.0Release
9
+ // Tag = production/release/21.161.0-0-g58854c0
10
10
  /////////////////////////////////////////////////////////////////////////////////////////////
11
11
 
12
12
 
@@ -1,12 +1,12 @@
1
1
  /////////////////////////////////////////////////////////////////////////////////////////////
2
- // Copyright 2024 Garmin International, Inc.
2
+ // Copyright 2025 Garmin International, Inc.
3
3
  // Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
4
4
  // may not use this file except in compliance with the Flexible and Interoperable Data
5
5
  // Transfer (FIT) Protocol License.
6
6
  /////////////////////////////////////////////////////////////////////////////////////////////
7
7
  // ****WARNING**** This file is auto-generated! Do NOT edit this file.
8
- // Profile Version = 21.141.0Release
9
- // Tag = production/release/21.141.0-0-g2aa27e1
8
+ // Profile Version = 21.161.0Release
9
+ // Tag = production/release/21.161.0-0-g58854c0
10
10
  /////////////////////////////////////////////////////////////////////////////////////////////
11
11
 
12
12
 
package/src/utils.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /////////////////////////////////////////////////////////////////////////////////////////////
2
- // Copyright 2024 Garmin International, Inc.
2
+ // Copyright 2025 Garmin International, Inc.
3
3
  // Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
4
4
  // may not use this file except in compliance with the Flexible and Interoperable Data
5
5
  // Transfer (FIT) Protocol License.
6
6
  /////////////////////////////////////////////////////////////////////////////////////////////
7
7
  // ****WARNING**** This file is auto-generated! Do NOT edit this file.
8
- // Profile Version = 21.141.0Release
9
- // Tag = production/release/21.141.0-0-g2aa27e1
8
+ // Profile Version = 21.161.0Release
9
+ // Tag = production/release/21.161.0-0-g58854c0
10
10
  /////////////////////////////////////////////////////////////////////////////////////////////
11
11
 
12
12
 
@@ -25,7 +25,42 @@ const convertDateTimeToDate = (datetime) => {
25
25
  return new Date((datetime ?? 0) * 1000 + FIT_EPOCH_MS);
26
26
  };
27
27
 
28
+ /**
29
+ * Convert a JavaScript Date to a FIT DateTime
30
+ * @param {Date} A JavaScript Date object
31
+ * @return {number} datetime - Seconds since FIT EPOCH
32
+ */
33
+ const convertDateToDateTime = (date) => {
34
+ return (date.getTime() - FIT_EPOCH_MS) / 1000;
35
+ };
36
+
37
+
38
+ /**
39
+ * FIT Base Type enum, for use with Developer Data Field Descriptions
40
+ */
41
+ const FitBaseType = Object.freeze({
42
+ enum: 0,
43
+ sint8: 1,
44
+ uint8: 2,
45
+ sint16: 131,
46
+ uint16: 132,
47
+ sint32: 133,
48
+ uint32: 134,
49
+ string: 7,
50
+ float32: 136,
51
+ float64: 137,
52
+ uint8z: 10,
53
+ uint16z: 139,
54
+ uint32z: 140,
55
+ byte: 13,
56
+ sint64: 142,
57
+ uint64: 143,
58
+ uint64z: 144,
59
+ });
60
+
28
61
  export default {
29
62
  FIT_EPOCH_MS,
30
63
  convertDateTimeToDate,
64
+ convertDateToDateTime,
65
+ FitBaseType,
31
66
  };