@dative-gpi/foundation-shared-services 1.1.24-unit-formatter-4 → 1.1.24-widget-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.
@@ -1,7 +1,6 @@
1
1
  export * from "./services";
2
2
  export * from "./app";
3
3
 
4
- export * from "./units";
5
4
  export * from "./useDateFormat";
6
5
  export * from "./useFiles";
7
6
  export * from "./useFoundationShared";
package/config/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./literals";
2
2
  export * from "./timeDuration";
3
- export * from "./units";
4
3
  export * from "./urls";
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.1.24-unit-formatter-4",
7
+ "version": "1.1.24-widget-2",
8
8
  "description": "",
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@dative-gpi/foundation-shared-domain": "1.1.24-unit-formatter-4",
16
+ "@dative-gpi/foundation-shared-domain": "1.1.24-widget-2",
17
17
  "@vueuse/core": "^14.0.0"
18
18
  },
19
19
  "peerDependencies": {
@@ -22,5 +22,5 @@
22
22
  "vue": "3.5.26",
23
23
  "vue-router": "^4.3.0"
24
24
  },
25
- "gitHead": "8a2bf62ad21d6657cd447e0198b55f91859e8462"
25
+ "gitHead": "e3b64258974077d06ddad77bc4133e4e5aa08c31"
26
26
  }
@@ -1,2 +0,0 @@
1
- export * from "./units";
2
- export * from "./useUnitFormat";
@@ -1,14 +0,0 @@
1
- import { SI_PREFIXES } from "@dative-gpi/foundation-shared-services/config";
2
- import type { ComputedRef } from "vue";
3
-
4
- export interface FormattedQuantity {
5
- displayValue: ComputedRef<string>;
6
- unit: ComputedRef<string>;
7
- displayText: ComputedRef<string>;
8
- }
9
-
10
- export const NO_VALUE = "-";
11
-
12
- export const DECADES_PER_PREFIX = 3;
13
- export const SMALLEST_PREFIX_EXPONENT = Math.round(Math.log10(SI_PREFIXES[0].factor));
14
- export const BASE_PREFIX_INDEX = -SMALLEST_PREFIX_EXPONENT / DECADES_PER_PREFIX;
@@ -1,66 +0,0 @@
1
- import { computed, toValue, type MaybeRefOrGetter } from "vue";
2
- import { SI_PREFIXES } from "@dative-gpi/foundation-shared-services/config";
3
- import { BASE_PREFIX_INDEX, DECADES_PER_PREFIX, NO_VALUE, SMALLEST_PREFIX_EXPONENT, type FormattedQuantity } from "./units";
4
-
5
- import { useAppLanguageCode } from "../app";
6
-
7
- export const useUnitFormat = (precision?: MaybeRefOrGetter<number | undefined>) => {
8
- const { languageCode } = useAppLanguageCode();
9
-
10
- const numberFormatter = computed(() => {
11
- const decimals = toValue(precision);
12
- const locale = languageCode.value ?? "fr-FR";
13
-
14
- return new Intl.NumberFormat(locale, {
15
- minimumFractionDigits: decimals,
16
- maximumFractionDigits: decimals,
17
- });
18
- });
19
-
20
- const format = (rawValue: MaybeRefOrGetter<number>, baseUnit: MaybeRefOrGetter<string>): FormattedQuantity => {
21
-
22
- const quantityWithPrefix = computed(() => {
23
- const numericValue = toValue(rawValue);
24
- if (!Number.isFinite(numericValue)) {
25
- return null;
26
- }
27
- const prefix = (() => {
28
- if (numericValue === 0) {
29
- return SI_PREFIXES[BASE_PREFIX_INDEX];
30
- }
31
-
32
- const valueExponent = Math.floor(Math.log10(Math.abs(numericValue)));
33
-
34
- const prefixExponent = Math.floor(valueExponent / DECADES_PER_PREFIX) * DECADES_PER_PREFIX;
35
-
36
- const prefixIndex = (prefixExponent - SMALLEST_PREFIX_EXPONENT) / DECADES_PER_PREFIX;
37
-
38
- const clampedPrefixIndex = Math.max(0, Math.min(prefixIndex, SI_PREFIXES.length - 1 ));
39
-
40
- return SI_PREFIXES[clampedPrefixIndex];
41
- })();
42
-
43
- return {
44
- scaledValue: numericValue / prefix.factor,
45
- unitSymbol: `${prefix.prefix}${toValue(baseUnit)}`,
46
- };
47
- });
48
-
49
- const displayValue = computed(() => {
50
- if (quantityWithPrefix.value === null) {
51
- return NO_VALUE;
52
- }
53
- return numberFormatter.value.format(quantityWithPrefix.value.scaledValue);
54
- });
55
-
56
- const unit = computed(() => quantityWithPrefix.value?.unitSymbol ?? "");
57
-
58
- const displayText = computed(() =>
59
- quantityWithPrefix.value === null ? NO_VALUE : `${displayValue.value} ${unit.value}`
60
- );
61
-
62
- return { displayValue, unit, displayText };
63
- };
64
-
65
- return { format };
66
- };
@@ -1 +0,0 @@
1
- export * from "./unitPrefixes";
@@ -1,13 +0,0 @@
1
- import { UnitPrefix } from "@dative-gpi/foundation-shared-domain/enums/units";
2
-
3
- export const SI_PREFIXES = [
4
- { prefix: UnitPrefix.Nano, factor: 1e-9 },
5
- { prefix: UnitPrefix.Micro, factor: 1e-6 },
6
- { prefix: UnitPrefix.Milli, factor: 1e-3 },
7
- { prefix: UnitPrefix.None, factor: 1 },
8
- { prefix: UnitPrefix.Kilo, factor: 1e3 },
9
- { prefix: UnitPrefix.Mega, factor: 1e6 },
10
- { prefix: UnitPrefix.Giga, factor: 1e9 },
11
- { prefix: UnitPrefix.Tera, factor: 1e12 },
12
- { prefix: UnitPrefix.Peta, factor: 1e15 },
13
- ];