fit-file-parser 6.0.2 → 6.1.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/CHANGELOG.md +39 -0
- package/PROFILE.md +16 -8
- package/README.md +62 -6
- package/dist/cjs/fit-parser.d.ts +3 -0
- package/dist/cjs/fit-parser.js +17 -1
- package/dist/cjs/fit_types.d.ts +1 -1
- package/dist/cjs/profile-lookup-data.d.ts +12 -0
- package/dist/cjs/profile-lookup-data.js +990 -0
- package/dist/cjs/profile-lookup.d.ts +19 -0
- package/dist/cjs/profile-lookup.js +145 -0
- package/dist/cjs/profile.js +6 -979
- package/dist/cjs/raw-message-reader.d.ts +60 -0
- package/dist/cjs/raw-message-reader.js +377 -0
- package/dist/fit-parser.d.ts +3 -0
- package/dist/fit-parser.js +2 -0
- package/dist/fit_types.d.ts +1 -1
- package/dist/profile-lookup-data.d.ts +12 -0
- package/dist/profile-lookup-data.js +987 -0
- package/dist/profile-lookup.d.ts +19 -0
- package/dist/profile-lookup.js +135 -0
- package/dist/profile.js +6 -979
- package/dist/raw-message-reader.d.ts +60 -0
- package/dist/raw-message-reader.js +368 -0
- package/package.json +33 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Resolves a FIT manufacturer identifier to its canonical profile name. */
|
|
2
|
+
export declare function getFitManufacturerName(value: number | string | null | undefined): string | null;
|
|
3
|
+
/** Resolves a Garmin product identifier to its canonical profile name. */
|
|
4
|
+
export declare function getFitGarminProductName(value: number | string | null | undefined): string | null;
|
|
5
|
+
/** Resolves a FIT sport identifier to its canonical profile name. */
|
|
6
|
+
export declare function getFitSportName(value: number | string | null | undefined): string | null;
|
|
7
|
+
/** Resolves a FIT sub-sport identifier to its canonical profile name. */
|
|
8
|
+
export declare function getFitSubSportName(value: number | string | null | undefined): string | null;
|
|
9
|
+
/** Resolves a FIT sport name to its numeric profile identifier. */
|
|
10
|
+
export declare function getFitSportId(value: string | null | undefined): number | null;
|
|
11
|
+
/** Resolves a FIT sub-sport name to its numeric profile identifier. */
|
|
12
|
+
export declare function getFitSubSportId(value: string | null | undefined): number | null;
|
|
13
|
+
/** Resolves a FIT course-point name to its numeric profile identifier. */
|
|
14
|
+
export declare function getFitCoursePointId(value: string | null | undefined): number | null;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a Garmin product identifier to a human-readable device name.
|
|
17
|
+
* This does not alter parsed `product` or `product_name` fields.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getFitGarminProductDisplayName(value: number | string | null | undefined): string | null;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFitManufacturerName = getFitManufacturerName;
|
|
4
|
+
exports.getFitGarminProductName = getFitGarminProductName;
|
|
5
|
+
exports.getFitSportName = getFitSportName;
|
|
6
|
+
exports.getFitSubSportName = getFitSubSportName;
|
|
7
|
+
exports.getFitSportId = getFitSportId;
|
|
8
|
+
exports.getFitSubSportId = getFitSubSportId;
|
|
9
|
+
exports.getFitCoursePointId = getFitCoursePointId;
|
|
10
|
+
exports.getFitGarminProductDisplayName = getFitGarminProductDisplayName;
|
|
11
|
+
const profile_lookup_data_js_1 = require("./profile-lookup-data.js");
|
|
12
|
+
function normalizeProfileName(value) {
|
|
13
|
+
return value.trim().toLowerCase().replace(/[\s_-]/g, '');
|
|
14
|
+
}
|
|
15
|
+
function createProfileIdMap(mapping) {
|
|
16
|
+
return new Map(Object.entries(mapping)
|
|
17
|
+
.filter((entry) => typeof entry[1] === 'string')
|
|
18
|
+
.map(([id, name]) => [normalizeProfileName(name), Number(id)]));
|
|
19
|
+
}
|
|
20
|
+
const FIT_PROFILE_SPORT_IDS = createProfileIdMap(profile_lookup_data_js_1.FIT_PROFILE_SPORTS);
|
|
21
|
+
const FIT_PROFILE_SUB_SPORT_IDS = createProfileIdMap(profile_lookup_data_js_1.FIT_PROFILE_SUB_SPORTS);
|
|
22
|
+
const FIT_PROFILE_COURSE_POINT_IDS = createProfileIdMap(profile_lookup_data_js_1.FIT_PROFILE_COURSE_POINTS);
|
|
23
|
+
function getProfileName(mapping, value) {
|
|
24
|
+
if (value === null || value === undefined) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const normalizedValue = typeof value === 'string' ? value.trim() : value;
|
|
31
|
+
if (normalizedValue === '' || (typeof normalizedValue === 'string' && !/^\d+$/.test(normalizedValue))) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const id = Number(normalizedValue);
|
|
35
|
+
if (!Number.isSafeInteger(id) || id < 0) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const name = mapping[id];
|
|
39
|
+
return typeof name === 'string' ? name : null;
|
|
40
|
+
}
|
|
41
|
+
function getProfileId(mapping, value) {
|
|
42
|
+
var _a;
|
|
43
|
+
if (typeof value !== 'string') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const name = normalizeProfileName(value);
|
|
47
|
+
if (name === '') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return (_a = mapping.get(name)) !== null && _a !== void 0 ? _a : null;
|
|
51
|
+
}
|
|
52
|
+
/** Resolves a FIT manufacturer identifier to its canonical profile name. */
|
|
53
|
+
function getFitManufacturerName(value) {
|
|
54
|
+
return getProfileName(profile_lookup_data_js_1.FIT_PROFILE_MANUFACTURERS, value);
|
|
55
|
+
}
|
|
56
|
+
/** Resolves a Garmin product identifier to its canonical profile name. */
|
|
57
|
+
function getFitGarminProductName(value) {
|
|
58
|
+
return getProfileName(profile_lookup_data_js_1.FIT_PROFILE_GARMIN_PRODUCTS, value);
|
|
59
|
+
}
|
|
60
|
+
/** Resolves a FIT sport identifier to its canonical profile name. */
|
|
61
|
+
function getFitSportName(value) {
|
|
62
|
+
return getProfileName(profile_lookup_data_js_1.FIT_PROFILE_SPORTS, value);
|
|
63
|
+
}
|
|
64
|
+
/** Resolves a FIT sub-sport identifier to its canonical profile name. */
|
|
65
|
+
function getFitSubSportName(value) {
|
|
66
|
+
return getProfileName(profile_lookup_data_js_1.FIT_PROFILE_SUB_SPORTS, value);
|
|
67
|
+
}
|
|
68
|
+
/** Resolves a FIT sport name to its numeric profile identifier. */
|
|
69
|
+
function getFitSportId(value) {
|
|
70
|
+
return getProfileId(FIT_PROFILE_SPORT_IDS, value);
|
|
71
|
+
}
|
|
72
|
+
/** Resolves a FIT sub-sport name to its numeric profile identifier. */
|
|
73
|
+
function getFitSubSportId(value) {
|
|
74
|
+
return getProfileId(FIT_PROFILE_SUB_SPORT_IDS, value);
|
|
75
|
+
}
|
|
76
|
+
/** Resolves a FIT course-point name to its numeric profile identifier. */
|
|
77
|
+
function getFitCoursePointId(value) {
|
|
78
|
+
return getProfileId(FIT_PROFILE_COURSE_POINT_IDS, value);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Resolves a Garmin product identifier to a human-readable device name.
|
|
82
|
+
* This does not alter parsed `product` or `product_name` fields.
|
|
83
|
+
*/
|
|
84
|
+
function getFitGarminProductDisplayName(value) {
|
|
85
|
+
const name = getFitGarminProductName(value);
|
|
86
|
+
if (!name) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
// Preserve the established display spelling for the optical heart-rate product.
|
|
90
|
+
const displaySource = name === 'o_hr' ? 'o_h_r' : name;
|
|
91
|
+
const formatted = displaySource
|
|
92
|
+
.replace(/^fr(\d+)/i, 'Forerunner $1')
|
|
93
|
+
.replace(/^fenix(\d+)/i, 'Fenix $1')
|
|
94
|
+
.replace(/^edge(\d+)/i, 'Edge $1')
|
|
95
|
+
.replace(/^vivoactive/i, 'VivoActive')
|
|
96
|
+
.replace(/^vivosmart/i, 'VivoSmart')
|
|
97
|
+
.replace(/^vivofit/i, 'VivoFit')
|
|
98
|
+
.replace(/^vivomove/i, 'VivoMove')
|
|
99
|
+
.replace(/^vivosport/i, 'VivoSport')
|
|
100
|
+
.replace(/^approach([A-Z\d])/i, 'Approach $1')
|
|
101
|
+
.replace(/^marq([A-Z])/i, 'Marq $1')
|
|
102
|
+
.replace(/^hrm/i, 'HRM ')
|
|
103
|
+
.replace(/_/g, ' ')
|
|
104
|
+
.replace(/([a-z])([A-Z0-9])/g, '$1 $2')
|
|
105
|
+
.replace(/(\d)([a-z])/gi, '$1 $2');
|
|
106
|
+
return formatted
|
|
107
|
+
.split(' ')
|
|
108
|
+
.map((word) => {
|
|
109
|
+
const lower = word.toLowerCase();
|
|
110
|
+
if (lower === 'apac')
|
|
111
|
+
return 'APAC';
|
|
112
|
+
if (lower === 'xt')
|
|
113
|
+
return 'XT';
|
|
114
|
+
if (lower === 'lte')
|
|
115
|
+
return 'LTE';
|
|
116
|
+
if (lower === 'hr')
|
|
117
|
+
return 'HR';
|
|
118
|
+
if (lower === 'gps')
|
|
119
|
+
return 'GPS';
|
|
120
|
+
if (lower === 'mtb')
|
|
121
|
+
return 'MTB';
|
|
122
|
+
if (lower === 'ii')
|
|
123
|
+
return 'II';
|
|
124
|
+
if (lower === 'iii')
|
|
125
|
+
return 'III';
|
|
126
|
+
if (lower === 'm' && name.toLowerCase().includes('645m'))
|
|
127
|
+
return 'Music';
|
|
128
|
+
if (lower === 'jpn')
|
|
129
|
+
return 'Japan';
|
|
130
|
+
if (lower === 'chn')
|
|
131
|
+
return 'China';
|
|
132
|
+
if (lower === 'twn')
|
|
133
|
+
return 'Taiwan';
|
|
134
|
+
if (lower === 'kor')
|
|
135
|
+
return 'Korea';
|
|
136
|
+
if (lower === 'rus')
|
|
137
|
+
return 'Russia';
|
|
138
|
+
if (lower === 'sea')
|
|
139
|
+
return 'SEA';
|
|
140
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
141
|
+
})
|
|
142
|
+
.join(' ')
|
|
143
|
+
.replace(/Vivo Active/g, 'VivoActive')
|
|
144
|
+
.trim();
|
|
145
|
+
}
|