@esportsplus/ui 0.10.4 → 0.10.5

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,6 +1,7 @@
1
1
  import './scss/index.scss';
2
- declare const _default: ({ currency, delay, max, suffix, value }: {
2
+ declare const _default: ({ currency, decimals, delay, max, suffix, value }: {
3
3
  currency?: "IGNORE" | "EUR" | "GBP" | "USD";
4
+ decimals?: number;
4
5
  delay?: number;
5
6
  max?: number;
6
7
  suffix?: string;
@@ -2,24 +2,30 @@ import { effect, reactive } from '@esportsplus/reactivity';
2
2
  import { html } from '@esportsplus/template';
3
3
  import './scss/index.scss';
4
4
  let formatters = {};
5
- export default ({ currency, delay, max, suffix, value }) => {
6
- let api = reactive({ value: -1 }), formatter = currency === 'IGNORE' ? undefined : formatters[currency || 'USD'] ??= new Intl.NumberFormat('en-US', {
7
- style: 'currency',
8
- currency: currency || 'USD'
9
- }), rendering = true, state = reactive({
5
+ export default ({ currency, decimals, delay, max, suffix, value }) => {
6
+ let api = reactive({ value: -1 }), formatter = currency === 'IGNORE'
7
+ ? undefined
8
+ : formatters[currency || 'USD'] ??= new Intl.NumberFormat('en-US', {
9
+ style: 'currency',
10
+ currency: currency || 'USD'
11
+ }), rendering = true, state = reactive({
10
12
  length: 0,
11
13
  render: []
12
14
  });
15
+ decimals ??= 2;
13
16
  effect(() => {
14
17
  if (api.value !== -1) {
15
18
  value = api.value;
16
19
  }
17
- let padding = (max || value).toFixed(2).length - value.toFixed(2).length, values = value.toString().padStart(value.toString().length + padding, '1');
20
+ let padding = (max || value).toFixed(decimals).length - value.toFixed(decimals).length, values = value.toString().padStart(value.toString().length + padding, '1');
18
21
  if (formatter) {
19
22
  values = formatter.format(values);
20
23
  }
21
24
  else {
22
- values = Number(values).toLocaleString();
25
+ values = Number(values).toLocaleString([], {
26
+ minimumFractionDigits: 0,
27
+ maximumFractionDigits: decimals
28
+ });
23
29
  }
24
30
  values = values.split('');
25
31
  if (suffix) {
package/package.json CHANGED
@@ -47,7 +47,7 @@
47
47
  "private": false,
48
48
  "sideEffects": false,
49
49
  "type": "module",
50
- "version": "0.10.4",
50
+ "version": "0.10.5",
51
51
  "scripts": {
52
52
  "build": "run-s build:vite build:ts",
53
53
  "build:ts": "tsc && tsc-alias",
@@ -7,31 +7,38 @@ let formatters: Record<string, Intl.NumberFormat> = {};
7
7
 
8
8
 
9
9
  // TODO: Prevent rounding
10
- export default ({ currency, delay, max, suffix, value }: { currency?: 'IGNORE' | 'EUR' | 'GBP' | 'USD', delay?: number, max?: number, suffix?: string, value: number }) => {
10
+ export default ({ currency, decimals, delay, max, suffix, value }: { currency?: 'IGNORE' | 'EUR' | 'GBP' | 'USD', decimals?: number, delay?: number, max?: number, suffix?: string, value: number }) => {
11
11
  let api = reactive({ value: -1 }),
12
- formatter = currency === 'IGNORE' ? undefined : formatters[currency || 'USD'] ??= new Intl.NumberFormat('en-US', {
13
- style: 'currency',
14
- currency: currency || 'USD'
15
- }),
12
+ formatter = currency === 'IGNORE'
13
+ ? undefined
14
+ : formatters[currency || 'USD'] ??= new Intl.NumberFormat('en-US', {
15
+ style: 'currency',
16
+ currency: currency || 'USD'
17
+ }),
16
18
  rendering = true,
17
19
  state = reactive({
18
20
  length: 0,
19
21
  render: [] as string[]
20
22
  });
21
23
 
24
+ decimals ??= 2;
25
+
22
26
  effect(() => {
23
27
  if (api.value !== -1) {
24
28
  value = api.value;
25
29
  }
26
30
 
27
- let padding = (max || value).toFixed(2).length - value.toFixed(2).length,
31
+ let padding = (max || value).toFixed(decimals).length - value.toFixed(decimals).length,
28
32
  values = value.toString().padStart( value.toString().length + padding, '1') as any;
29
33
 
30
34
  if (formatter) {
31
35
  values = formatter.format(values);
32
36
  }
33
37
  else {
34
- values = Number(values).toLocaleString();
38
+ values = Number(values).toLocaleString([], {
39
+ minimumFractionDigits: 0,
40
+ maximumFractionDigits: decimals
41
+ });
35
42
  }
36
43
 
37
44
  values = values.split('');