vueless 0.0.761 → 0.0.762

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.761",
3
+ "version": "0.0.762",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -2,7 +2,6 @@ import type { FormatOptions } from "./types.ts";
2
2
 
3
3
  const isNumberValueRegExp = /^[\d,.\s-]+$/;
4
4
  const rawDecimalMark = ".";
5
- const comma = ",";
6
5
  const minus = "-";
7
6
 
8
7
  export function getRawValue(value: string | number, options: FormatOptions): string {
@@ -14,7 +13,8 @@ export function getRawValue(value: string | number, options: FormatOptions): str
14
13
 
15
14
  const rawValueWithPrefix = value
16
15
  .replaceAll(thousandsSeparator, "")
17
- .replace(decimalSeparator, ".");
16
+ .replaceAll(" ", "")
17
+ .replace(decimalSeparator, rawDecimalMark);
18
18
 
19
19
  return rawValueWithPrefix.replace(prefix, "");
20
20
  }
@@ -30,11 +30,14 @@ export function getFormattedValue(value: string | number, options: FormatOptions
30
30
  } = options;
31
31
 
32
32
  const invalidValuesRegExp = new RegExp("[^\\d,\\d.\\s-" + decimalSeparator + "]", "g");
33
- const doubleValueRegExp = new RegExp("([,\\.\\s" + decimalSeparator + "])+", "g");
33
+ const doubleValueRegExp = new RegExp("([,\\.\\s\\-" + decimalSeparator + "])+", "g");
34
+
35
+ const actualMinFractionDigit =
36
+ minFractionDigits <= maxFractionDigits ? minFractionDigits : maxFractionDigits;
34
37
 
35
38
  // slice to first decimal mark
36
39
  value = String(value)
37
- .replaceAll(comma, decimalSeparator)
40
+ .replaceAll(rawDecimalMark, decimalSeparator)
38
41
  .split(decimalSeparator)
39
42
  .slice(0, 2)
40
43
  .map((value: string, index: number) =>
@@ -51,14 +54,23 @@ export function getFormattedValue(value: string | number, options: FormatOptions
51
54
  const isNumber = isNumberValueRegExp.test(value);
52
55
  const isFloat = value.endsWith(rawDecimalMark) || value.endsWith(".0");
53
56
  const isMinus = value === minus;
54
- const isMinusWithin = value.includes(minus) && !value.startsWith(minus);
55
57
 
56
58
  if (isMinus && positiveOnly) {
57
59
  value = "";
58
60
  }
59
61
 
60
- if (isMinusWithin) {
61
- value = value.replaceAll(minus, "");
62
+ if (value.includes(minus)) {
63
+ let isFirstMinus = value.startsWith(minus);
64
+
65
+ value = value.replaceAll(minus, (match) => {
66
+ if (isFirstMinus) {
67
+ isFirstMinus = false;
68
+
69
+ return match;
70
+ }
71
+
72
+ return "";
73
+ });
62
74
  }
63
75
 
64
76
  if (!value || !isNumber || isFloat || isMinus) {
@@ -66,9 +78,9 @@ export function getFormattedValue(value: string | number, options: FormatOptions
66
78
  }
67
79
 
68
80
  const intlNumberOptions: Intl.NumberFormatOptions = {
69
- minimumFractionDigits:
70
- minFractionDigits <= maxFractionDigits ? minFractionDigits : maxFractionDigits,
81
+ minimumFractionDigits: actualMinFractionDigit,
71
82
  maximumFractionDigits: maxFractionDigits,
83
+ roundingMode: "trunc",
72
84
  };
73
85
 
74
86
  if (positiveOnly) {
@@ -86,20 +98,26 @@ export function getFormattedValue(value: string | number, options: FormatOptions
86
98
  positiveOnly: false,
87
99
  });
88
100
 
89
- const [integer, fraction = ""] = rawValue.split(rawDecimalMark);
90
- const bigInteger = intlNumber.format(BigInt(integer));
101
+ const formattedValue = intlNumber
102
+ .formatToParts((rawValue || 0) as unknown as number)
103
+ .map((part) => {
104
+ if (part.type === "group") part.value = thousandsSeparator;
105
+ if (part.type === "decimal") part.value = decimalSeparator;
106
+
107
+ if (part.type === "fraction") {
108
+ const fraction = rawValue.split(rawDecimalMark).at(-1) || "";
109
+ const formattedFraction = fraction
110
+ .split("")
111
+ .slice(actualMinFractionDigit, maxFractionDigits)
112
+ .join("");
91
113
 
92
- const formattedFraction = fraction
93
- .slice(minFractionDigits, maxFractionDigits)
94
- .padStart(maxFractionDigits, "0");
114
+ part.value = formattedFraction;
115
+ }
95
116
 
96
- const formattedBigInt = fraction
97
- ? bigInteger + `${rawDecimalMark}${formattedFraction}`
98
- : bigInteger;
117
+ return part;
118
+ });
99
119
 
100
- const formattedValue = formattedBigInt
101
- .replaceAll(comma, thousandsSeparator)
102
- .replaceAll(rawDecimalMark, decimalSeparator);
120
+ formattedValue.unshift({ value: prefix, type: "minusSign" });
103
121
 
104
- return prefix + formattedValue;
122
+ return formattedValue.map((part) => part.value).join("");
105
123
  }