@dative-gpi/foundation-shared-domain 1.0.190 → 1.0.191-add-unit-formatter

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/enums/index.ts CHANGED
@@ -17,6 +17,7 @@ export * from "./messages";
17
17
  export * from "./playlists";
18
18
  export * from "./roles";
19
19
  export * from "./times";
20
+ export * from "./units";
20
21
  export * from "./users";
21
22
  export * from "./widgetTemplates";
22
23
  export * from "./reports";
package/enums/units.ts ADDED
@@ -0,0 +1,150 @@
1
+ export enum UnitPrefix {
2
+ None = "",
3
+ Nano = "n",
4
+ Micro = "µ",
5
+ Milli = "m",
6
+ Kilo = "k",
7
+ Mega = "M",
8
+ Giga = "G",
9
+ Tera = "T",
10
+ Peta = "P"
11
+ }
12
+
13
+ export enum EnergyUnit {
14
+ Wh = "Wh",
15
+ kWh = "kWh",
16
+ MWh = "MWh",
17
+ GWh = "GWh",
18
+ TWh = "TWh",
19
+ }
20
+
21
+ export enum PowerUnit {
22
+ W = "W",
23
+ kW = "kW",
24
+ MW = "MW",
25
+ GW = "GW",
26
+ TW = "TW",
27
+ }
28
+
29
+ export enum VolumeUnit {
30
+ mL = "mL",
31
+ L = "L",
32
+ m3 = "m3",
33
+ dam3 = "dam3",
34
+ }
35
+
36
+ export enum GasVolumeUnit {
37
+ Nm3 = "Nm3",
38
+ kNm3 = "kNm3",
39
+ MNm3 = "MNm3",
40
+ GNm3 = "GNm3",
41
+ }
42
+
43
+ export enum WaterFlowUnit {
44
+ mL_s = "mL/s",
45
+ L_s = "L/s",
46
+ m3_s = "m3/s",
47
+ L_min = "L/min",
48
+ m3_h = "m3/h",
49
+ }
50
+
51
+ export enum GasFlowUnit {
52
+ Nm3_h = "Nm3/h",
53
+ kNm3_h = "kNm3/h",
54
+ MNm3_h = "MNm3/h",
55
+ }
56
+
57
+ export enum PressureUnit {
58
+ Pa = "Pa",
59
+ kPa = "kPa",
60
+ MPa = "MPa",
61
+ GPa = "GPa",
62
+ bar = "bar",
63
+ mbar = "mbar",
64
+ }
65
+
66
+ export enum TemperatureUnit {
67
+ Celsius = "°C",
68
+ Kelvin = "K",
69
+ Fahrenheit = "°F",
70
+ }
71
+
72
+ export enum SpeedUnit {
73
+ m_s = "m/s",
74
+ km_h = "km/h",
75
+ knot = "kn",
76
+ }
77
+
78
+ export enum DistanceUnit {
79
+ mm = "mm",
80
+ cm = "cm",
81
+ m = "m",
82
+ km = "km",
83
+ }
84
+
85
+ export enum MassUnit {
86
+ mg = "mg",
87
+ g = "g",
88
+ kg = "kg",
89
+ t = "t",
90
+ kt = "kt",
91
+ Mt = "Mt",
92
+ }
93
+
94
+ export enum MassFlowUnit {
95
+ g_s = "g/s",
96
+ kg_s = "kg/s",
97
+ t_s = "t/s",
98
+ kg_h = "kg/h",
99
+ t_h = "t/h",
100
+ }
101
+
102
+ export enum FrequencyUnit {
103
+ Hz = "Hz",
104
+ kHz = "kHz",
105
+ MHz = "MHz",
106
+ GHz = "GHz",
107
+ rpm = "rpm",
108
+ }
109
+
110
+ export enum VoltageUnit {
111
+ mV = "mV",
112
+ V = "V",
113
+ kV = "kV",
114
+ MV = "MV",
115
+ }
116
+
117
+ export enum CurrentUnit {
118
+ mA = "mA",
119
+ A = "A",
120
+ kA = "kA",
121
+ }
122
+
123
+ export enum ResistanceUnit {
124
+ mΩ = "mΩ",
125
+ Ω = "Ω",
126
+ kΩ = "kΩ",
127
+ MΩ = "MΩ",
128
+ }
129
+
130
+ export enum PercentageUnit {
131
+ Percent = "%",
132
+ RelativeHumidity = "%RH",
133
+ }
134
+
135
+ export enum CapacityUnit {
136
+ pers = "pers",
137
+ pers_h = "pers/h",
138
+ }
139
+
140
+ export enum SnowProductionUnit {
141
+ m3_neige_h = "m3_neige/h",
142
+ }
143
+
144
+ export enum EfficiencyUnit {
145
+ kWh_m3 = "kWh/m3",
146
+ kWh_kg = "kWh/kg",
147
+ }
148
+
149
+
150
+
package/models/index.ts CHANGED
@@ -11,5 +11,6 @@ export * from "./permissions";
11
11
  export * from "./terminals";
12
12
  export * from "./timeZones";
13
13
  export * from "./translations";
14
+ export * from "./units";
14
15
  export * from "./userLegalInformations";
15
16
  export * from "./users";
@@ -0,0 +1,2 @@
1
+ export * from "./unitDetails";
2
+ export * from "./unitsRegistry";
@@ -0,0 +1,19 @@
1
+ export type UnitScaleStep = { unit: string; ratioToParent: number };
2
+
3
+ export type UnitConversion = {
4
+ sourceUnit: string;
5
+ targetUnit: string;
6
+ conversionRate: number;
7
+ minThreshold?: number;
8
+ };
9
+
10
+ export interface UnitDefinition {
11
+ symbol: string;
12
+ precision: number;
13
+ parent?: string;
14
+ conversions?: Array<{
15
+ targetUnit: string;
16
+ conversionRate: number;
17
+ minThreshold?: number;
18
+ }>;
19
+ }
@@ -0,0 +1,443 @@
1
+ import { EnergyUnit, PowerUnit, GasFlowUnit, PressureUnit, TemperatureUnit, SpeedUnit, DistanceUnit, MassUnit, MassFlowUnit, FrequencyUnit, VoltageUnit, CurrentUnit, ResistanceUnit, PercentageUnit, CapacityUnit, SnowProductionUnit, EfficiencyUnit, VolumeUnit, GasVolumeUnit, WaterFlowUnit } from "@dative-gpi/foundation-shared-domain/enums"
2
+ import type { UnitDefinition } from "./unitDetails"
3
+
4
+ export const unitRegistry: Record<string, UnitDefinition> = {
5
+ // ===== ÉNERGIE =====
6
+ [EnergyUnit.Wh]: {
7
+ symbol: "Wh",
8
+ precision: 0,
9
+ parent: EnergyUnit.kWh,
10
+ },
11
+ [EnergyUnit.kWh]: {
12
+ symbol: "kWh",
13
+ precision: 2,
14
+ parent: EnergyUnit.MWh,
15
+ },
16
+ [EnergyUnit.MWh]: {
17
+ symbol: "MWh",
18
+ precision: 2,
19
+ parent: EnergyUnit.GWh,
20
+ },
21
+ [EnergyUnit.GWh]: {
22
+ symbol: "GWh",
23
+ precision: 2,
24
+ parent: EnergyUnit.TWh,
25
+ },
26
+ [EnergyUnit.TWh]: {
27
+ symbol: "TWh",
28
+ precision: 2,
29
+ },
30
+
31
+ // ===== PUISSANCE =====
32
+ [PowerUnit.W]: {
33
+ symbol: "W",
34
+ precision: 0,
35
+ parent: PowerUnit.kW,
36
+ },
37
+ [PowerUnit.kW]: {
38
+ symbol: "kW",
39
+ precision: 2,
40
+ parent: PowerUnit.MW,
41
+ },
42
+ [PowerUnit.MW]: {
43
+ symbol: "MW",
44
+ precision: 2,
45
+ parent: PowerUnit.GW,
46
+ },
47
+ [PowerUnit.GW]: {
48
+ symbol: "GW",
49
+ precision: 2,
50
+ parent: PowerUnit.TW,
51
+ },
52
+ [PowerUnit.TW]: {
53
+ symbol: "TW",
54
+ precision: 2,
55
+ },
56
+
57
+ // ===== VOLUME (EAU) =====
58
+ [VolumeUnit.mL]: {
59
+ symbol: "mL",
60
+ precision: 0,
61
+ parent: VolumeUnit.L,
62
+ },
63
+ [VolumeUnit.L]: {
64
+ symbol: "L",
65
+ precision: 1,
66
+ parent: VolumeUnit.m3,
67
+ },
68
+ [VolumeUnit.m3]: {
69
+ symbol: "m3",
70
+ precision: 2,
71
+ parent: VolumeUnit.dam3,
72
+ },
73
+ [VolumeUnit.dam3]: {
74
+ symbol: "dam3",
75
+ precision: 2,
76
+ },
77
+
78
+ // ===== VOLUME (GAZ) =====
79
+ [GasVolumeUnit.Nm3]: {
80
+ symbol: "Nm3",
81
+ precision: 2,
82
+ parent: GasVolumeUnit.kNm3,
83
+ },
84
+ [GasVolumeUnit.kNm3]: {
85
+ symbol: "kNm3",
86
+ precision: 2,
87
+ parent: GasVolumeUnit.MNm3,
88
+ },
89
+ [GasVolumeUnit.MNm3]: {
90
+ symbol: "MNm3",
91
+ precision: 2,
92
+ parent: GasVolumeUnit.GNm3,
93
+ },
94
+ [GasVolumeUnit.GNm3]: {
95
+ symbol: "GNm3",
96
+ precision: 2,
97
+ },
98
+
99
+ // ===== DÉBIT D'EAU =====
100
+ [WaterFlowUnit.mL_s]: {
101
+ symbol: "mL/s",
102
+ precision: 0,
103
+ parent: WaterFlowUnit.L_s,
104
+ },
105
+ [WaterFlowUnit.L_s]: {
106
+ symbol: "L/s",
107
+ precision: 2,
108
+ parent: WaterFlowUnit.m3_s,
109
+ conversions: [
110
+ {
111
+ targetUnit: WaterFlowUnit.m3_h,
112
+ conversionRate: 3.6,
113
+ minThreshold: 100,
114
+ },
115
+ ],
116
+ },
117
+ [WaterFlowUnit.m3_s]: {
118
+ symbol: "m3/s",
119
+ precision: 3,
120
+ },
121
+ [WaterFlowUnit.L_min]: {
122
+ symbol: "L/min",
123
+ precision: 1,
124
+ conversions: [
125
+ {
126
+ targetUnit: WaterFlowUnit.L_s,
127
+ conversionRate: 1 / 60,
128
+ minThreshold: 60,
129
+ },
130
+ ],
131
+ },
132
+ [WaterFlowUnit.m3_h]: {
133
+ symbol: "m3/h",
134
+ precision: 1,
135
+ },
136
+
137
+ // ===== DÉBIT DE GAZ =====
138
+ [GasFlowUnit.Nm3_h]: {
139
+ symbol: "Nm3/h",
140
+ precision: 1,
141
+ parent: GasFlowUnit.kNm3_h,
142
+ },
143
+ [GasFlowUnit.kNm3_h]: {
144
+ symbol: "kNm3/h",
145
+ precision: 2,
146
+ parent: GasFlowUnit.MNm3_h,
147
+ },
148
+ [GasFlowUnit.MNm3_h]: {
149
+ symbol: "MNm3/h",
150
+ precision: 2,
151
+ },
152
+
153
+ // ===== PRESSION =====
154
+ [PressureUnit.Pa]: {
155
+ symbol: "Pa",
156
+ precision: 0,
157
+ parent: PressureUnit.kPa,
158
+ },
159
+ [PressureUnit.kPa]: {
160
+ symbol: "kPa",
161
+ precision: 2,
162
+ parent: PressureUnit.MPa,
163
+ },
164
+ [PressureUnit.MPa]: {
165
+ symbol: "MPa",
166
+ precision: 2,
167
+ parent: PressureUnit.GPa,
168
+ },
169
+ [PressureUnit.GPa]: {
170
+ symbol: "GPa",
171
+ precision: 2,
172
+ },
173
+ [PressureUnit.bar]: {
174
+ symbol: "bar",
175
+ precision: 2,
176
+ conversions: [
177
+ {
178
+ targetUnit: PressureUnit.kPa,
179
+ conversionRate: 100,
180
+ },
181
+ ],
182
+ },
183
+ [PressureUnit.mbar]: {
184
+ symbol: "mbar",
185
+ precision: 1,
186
+ conversions: [
187
+ {
188
+ targetUnit: PressureUnit.Pa,
189
+ conversionRate: 100,
190
+ minThreshold: 10,
191
+ },
192
+ ],
193
+ },
194
+
195
+ // ===== TEMPÉRATURE =====
196
+ [TemperatureUnit.Celsius]: {
197
+ symbol: "°C",
198
+ precision: 1,
199
+ },
200
+ [TemperatureUnit.Kelvin]: {
201
+ symbol: "K",
202
+ precision: 1,
203
+ },
204
+ [TemperatureUnit.Fahrenheit]: {
205
+ symbol: "°F",
206
+ precision: 1,
207
+ },
208
+
209
+ // ===== VITESSE =====
210
+ [SpeedUnit.m_s]: {
211
+ symbol: "m/s",
212
+ precision: 2,
213
+ conversions: [
214
+ {
215
+ targetUnit: SpeedUnit.km_h,
216
+ conversionRate: 3.6,
217
+ },
218
+ ],
219
+ },
220
+ [SpeedUnit.km_h]: {
221
+ symbol: "km/h",
222
+ precision: 1,
223
+ },
224
+ [SpeedUnit.knot]: {
225
+ symbol: "kn",
226
+ precision: 0,
227
+ conversions: [
228
+ {
229
+ targetUnit: SpeedUnit.km_h,
230
+ conversionRate: 1.852,
231
+ },
232
+ ],
233
+ },
234
+
235
+ // ===== DISTANCE =====
236
+ [DistanceUnit.mm]: {
237
+ symbol: "mm",
238
+ precision: 0,
239
+ conversions: [
240
+ {
241
+ targetUnit: DistanceUnit.cm,
242
+ conversionRate: 0.1,
243
+ minThreshold: 10,
244
+ },
245
+ ],
246
+ },
247
+ [DistanceUnit.cm]: {
248
+ symbol: "cm",
249
+ precision: 1,
250
+ conversions: [
251
+ {
252
+ targetUnit: DistanceUnit.m,
253
+ conversionRate: 0.01,
254
+ minThreshold: 100,
255
+ },
256
+ ],
257
+ },
258
+ [DistanceUnit.m]: {
259
+ symbol: "m",
260
+ precision: 0,
261
+ parent: DistanceUnit.km,
262
+ },
263
+ [DistanceUnit.km]: {
264
+ symbol: "km",
265
+ precision: 2,
266
+ },
267
+
268
+ // ===== MASSE =====
269
+ [MassUnit.mg]: {
270
+ symbol: "mg",
271
+ precision: 0,
272
+ parent: MassUnit.g,
273
+ },
274
+ [MassUnit.g]: {
275
+ symbol: "g",
276
+ precision: 0,
277
+ parent: MassUnit.kg,
278
+ },
279
+ [MassUnit.kg]: {
280
+ symbol: "kg",
281
+ precision: 2,
282
+ parent: MassUnit.t,
283
+ },
284
+ [MassUnit.t]: {
285
+ symbol: "t",
286
+ precision: 2,
287
+ parent: MassUnit.kt,
288
+ },
289
+ [MassUnit.kt]: {
290
+ symbol: "kt",
291
+ precision: 2,
292
+ },
293
+
294
+ // ===== DÉBIT MASSIQUE =====
295
+ [MassFlowUnit.g_s]: {
296
+ symbol: "g/s",
297
+ precision: 1,
298
+ parent: MassFlowUnit.kg_s,
299
+ },
300
+ [MassFlowUnit.kg_s]: {
301
+ symbol: "kg/s",
302
+ precision: 2,
303
+ parent: MassFlowUnit.t_s,
304
+ conversions: [
305
+ {
306
+ targetUnit: MassFlowUnit.t_h,
307
+ conversionRate: 3.6,
308
+ minThreshold: 100,
309
+ },
310
+ ],
311
+ },
312
+ [MassFlowUnit.t_s]: {
313
+ symbol: "t/s",
314
+ precision: 3,
315
+ },
316
+ [MassFlowUnit.kg_h]: {
317
+ symbol: "kg/h",
318
+ precision: 1,
319
+ },
320
+ [MassFlowUnit.t_h]: {
321
+ symbol: "t/h",
322
+ precision: 1,
323
+ },
324
+
325
+ // ===== FRÉQUENCE =====
326
+ [FrequencyUnit.Hz]: {
327
+ symbol: "Hz",
328
+ precision: 1,
329
+ parent: FrequencyUnit.kHz,
330
+ },
331
+ [FrequencyUnit.kHz]: {
332
+ symbol: "kHz",
333
+ precision: 2,
334
+ parent: FrequencyUnit.MHz,
335
+ },
336
+ [FrequencyUnit.MHz]: {
337
+ symbol: "MHz",
338
+ precision: 2,
339
+ parent: FrequencyUnit.GHz,
340
+ },
341
+ [FrequencyUnit.GHz]: {
342
+ symbol: "GHz",
343
+ precision: 2,
344
+ },
345
+ [FrequencyUnit.rpm]: {
346
+ symbol: "rpm",
347
+ precision: 0,
348
+ },
349
+
350
+ // ===== TENSION =====
351
+ [VoltageUnit.mV]: {
352
+ symbol: "mV",
353
+ precision: 0,
354
+ parent: VoltageUnit.V,
355
+ },
356
+ [VoltageUnit.V]: {
357
+ symbol: "V",
358
+ precision: 1,
359
+ parent: VoltageUnit.kV,
360
+ },
361
+ [VoltageUnit.kV]: {
362
+ symbol: "kV",
363
+ precision: 2,
364
+ parent: VoltageUnit.MV,
365
+ },
366
+ [VoltageUnit.MV]: {
367
+ symbol: "MV",
368
+ precision: 2,
369
+ },
370
+
371
+ // ===== COURANT =====
372
+ [CurrentUnit.mA]: {
373
+ symbol: "mA",
374
+ precision: 1,
375
+ parent: CurrentUnit.A,
376
+ },
377
+ [CurrentUnit.A]: {
378
+ symbol: "A",
379
+ precision: 2,
380
+ parent: CurrentUnit.kA,
381
+ },
382
+ [CurrentUnit.kA]: {
383
+ symbol: "kA",
384
+ precision: 2,
385
+ },
386
+
387
+ // ===== RÉSISTANCE =====
388
+ [ResistanceUnit.mΩ]: {
389
+ symbol: "mΩ",
390
+ precision: 1,
391
+ parent: ResistanceUnit.Ω,
392
+ },
393
+ [ResistanceUnit.Ω]: {
394
+ symbol: "Ω",
395
+ precision: 1,
396
+ parent: ResistanceUnit.kΩ,
397
+ },
398
+ [ResistanceUnit.kΩ]: {
399
+ symbol: "kΩ",
400
+ precision: 2,
401
+ parent: ResistanceUnit.MΩ,
402
+ },
403
+ [ResistanceUnit.MΩ]: {
404
+ symbol: "MΩ",
405
+ precision: 2,
406
+ },
407
+
408
+ // ===== POURCENTAGE =====
409
+ [PercentageUnit.Percent]: {
410
+ symbol: "%",
411
+ precision: 1,
412
+ },
413
+ [PercentageUnit.RelativeHumidity]: {
414
+ symbol: "%RH",
415
+ precision: 0,
416
+ },
417
+
418
+ // ===== CAPACITÉ =====
419
+ [CapacityUnit.pers]: {
420
+ symbol: "pers.",
421
+ precision: 0,
422
+ },
423
+ [CapacityUnit.pers_h]: {
424
+ symbol: "pers./h",
425
+ precision: 0,
426
+ },
427
+
428
+ // ===== PRODUCTION NEIGE =====
429
+ [SnowProductionUnit.m3_neige_h]: {
430
+ symbol: "m3/h",
431
+ precision: 0,
432
+ },
433
+
434
+ // ===== RENDEMENT =====
435
+ [EfficiencyUnit.kWh_m3]: {
436
+ symbol: "kWh/m3",
437
+ precision: 2,
438
+ },
439
+ [EfficiencyUnit.kWh_kg]: {
440
+ symbol: "kWh/kg",
441
+ precision: 2,
442
+ },
443
+ };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://github.com/Dative-GPI/foundation-shared-ui.git"
5
5
  },
6
6
  "sideEffects": false,
7
- "version": "1.0.190",
7
+ "version": "1.0.191-add-unit-formatter",
8
8
  "description": "",
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -15,5 +15,5 @@
15
15
  "peerDependencies": {
16
16
  "date-fns": "^3.6.0"
17
17
  },
18
- "gitHead": "c828caf6ee06215c92beb11d9cc8241f12d4abe0"
18
+ "gitHead": "0a19e29a6ff02531f7a54c712d7fcd27c328fc27"
19
19
  }