vueless 0.0.464 → 0.0.465

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.464",
3
+ "version": "0.0.465",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -12,12 +12,12 @@
12
12
  v-text="symbol + currencySpace"
13
13
  />
14
14
 
15
- <span v-if="sum" v-bind="mathSignAttrs" v-text="mathSign" />
15
+ <span v-if="value" v-bind="mathSignAttrs" v-text="mathSign" />
16
16
 
17
17
  <span v-bind="integerAttrs" v-text="preparedMoney.integer" />
18
18
 
19
19
  <span
20
- v-if="!integer"
20
+ v-if="maxFractionDigits > 0"
21
21
  v-bind="pennyAttrs"
22
22
  v-text="preparedMoney.decimalSeparator + preparedMoney.penny"
23
23
  />
@@ -52,7 +52,7 @@ const props = defineProps({
52
52
  /**
53
53
  * Money value.
54
54
  */
55
- sum: {
55
+ value: {
56
56
  type: Number,
57
57
  default: 0,
58
58
  },
@@ -110,11 +110,19 @@ const props = defineProps({
110
110
  },
111
111
 
112
112
  /**
113
- * Set the numeral decimal scale after the comma.
113
+ * Minimal number of signs after the decimal separator (fractional part of a number).
114
114
  */
115
- decimalScale: {
115
+ minFractionDigits: {
116
116
  type: Number,
117
- default: getDefault(defaultConfig, UMoney).decimalScale,
117
+ default: getDefault(defaultConfig, UMoney).minFractionDigits,
118
+ },
119
+
120
+ /**
121
+ * Maximal number of signs after the decimal separator (fractional part of a number).
122
+ */
123
+ maxFractionDigits: {
124
+ type: Number,
125
+ default: getDefault(defaultConfig, UMoney).maxFractionDigits,
118
126
  },
119
127
 
120
128
  /**
@@ -126,20 +134,20 @@ const props = defineProps({
126
134
  },
127
135
 
128
136
  /**
129
- * Money align.
130
- * @values right, left
137
+ * A symbol used to separate the thousand parts of a number.
131
138
  */
132
- align: {
139
+ thousandsSeparator: {
133
140
  type: String,
134
- default: getDefault(defaultConfig, UMoney).align,
141
+ default: getDefault(defaultConfig, UMoney).thousandsSeparator,
135
142
  },
136
143
 
137
144
  /**
138
- * Make money sum integer.
145
+ * Money align.
146
+ * @values right, left
139
147
  */
140
- integer: {
141
- type: Boolean,
142
- default: getDefault(defaultConfig, UMoney).integer,
148
+ align: {
149
+ type: String,
150
+ default: getDefault(defaultConfig, UMoney).align,
143
151
  },
144
152
 
145
153
  /**
@@ -200,6 +208,12 @@ const mathSign = computed(() => {
200
208
  });
201
209
 
202
210
  const preparedMoney = computed(() => {
203
- return separatedMoney(Math.abs(props.sum), props.decimalScale, props.decimalSeparator);
211
+ return separatedMoney(
212
+ Math.abs(props.value),
213
+ props.minFractionDigits,
214
+ props.maxFractionDigits,
215
+ props.decimalSeparator,
216
+ props.thousandsSeparator,
217
+ );
204
218
  });
205
219
  </script>
@@ -53,8 +53,10 @@ export default /*tw*/ {
53
53
  sign: "default",
54
54
  align: "left",
55
55
  symbolAlign: "right",
56
- decimalScale: 2,
56
+ minFractionDigits: 0,
57
+ maxFractionDigits: 2,
57
58
  decimalSeparator: ",",
59
+ thousandsSeparator: " ",
58
60
  planned: false,
59
61
  integer: false,
60
62
  symbolDivided: true,
@@ -16,7 +16,7 @@ export default {
16
16
  title: "Text & Content / Money",
17
17
  component: UMoney,
18
18
  args: {
19
- sum: 10,
19
+ value: 10,
20
20
  symbol: "$",
21
21
  sign: "positive",
22
22
  },
@@ -73,12 +73,12 @@ export const Default = DefaultTemplate.bind({});
73
73
  Default.args = {};
74
74
 
75
75
  export const OtherValues = DefaultTemplate.bind({});
76
- OtherValues.args = { sum: 10, symbol: "$", sign: "negative" };
76
+ OtherValues.args = { value: 10, symbol: "$", sign: "negative" };
77
77
 
78
78
  export const Colors = EnumVariantTemplate.bind({});
79
79
  Colors.args = {
80
80
  enum: "color",
81
- sum: 0,
81
+ value: 0,
82
82
  symbol: "$",
83
83
  sign: "default",
84
84
  };
@@ -95,11 +95,8 @@ SymbolAlign.args = { enum: "symbolAlign" };
95
95
  export const Planned = DefaultTemplate.bind({});
96
96
  Planned.args = { planned: true };
97
97
 
98
- export const Integer = DefaultTemplate.bind({});
99
- Integer.args = { integer: true };
100
-
101
- export const NumeralDecimalScale3 = DefaultTemplate.bind({});
102
- NumeralDecimalScale3.args = { numeralDecimalScale: 3 };
98
+ export const MinFractionDigits3 = DefaultTemplate.bind({});
99
+ MinFractionDigits3.args = { value: 25.67, minFractionDigits: 3, maxFractionDigits: 3 };
103
100
 
104
101
  export const Align = EnumVariantTemplate.bind({});
105
102
  Align.args = { enum: "align" };
@@ -8,21 +8,39 @@ export const ADD_SPACE_IN_MONEY_REG_EX = /(\d)(?=(\d{3})+(\D|$))/g;
8
8
  export const SINGLE_ZERO = "0";
9
9
  export const DOUBLE_ZERO = "00";
10
10
 
11
- export function separatedMoney(money, decimalPlaces = 2, decimalSeparator = ",") {
12
- const roundedMoney = money ? money.toFixed(decimalPlaces) : 0;
11
+ export function separatedMoney(
12
+ money,
13
+ minFractionDigits = 0,
14
+ maxFractionDigits = 2,
15
+ decimalSeparator = ",",
16
+ thousandsSeparator = " ",
17
+ ) {
18
+ const options = {
19
+ minimumFractionDigits: minFractionDigits,
20
+ maximumFractionDigits: maxFractionDigits,
21
+ };
13
22
 
14
- let [integer, penny] = String(roundedMoney).split(".");
23
+ const formattedMoney =
24
+ money !== undefined && money !== null ? Number(money).toLocaleString("en-US", options) : "0";
15
25
 
16
- integer = integer.replace(ADD_SPACE_IN_MONEY_REG_EX, "$1 ");
26
+ let [integer, penny = ""] = formattedMoney.split(".");
17
27
 
18
- if (!roundedMoney) {
28
+ integer = integer.replace(/,/g, thousandsSeparator);
29
+
30
+ if (!money && money !== 0) {
19
31
  integer = SINGLE_ZERO;
20
32
  penny = DOUBLE_ZERO;
21
33
  }
22
34
 
23
- if (decimalPlaces === 0) {
35
+ if (penny === "") {
36
+ decimalSeparator = "";
37
+ }
38
+
39
+ if (minFractionDigits === 0 && maxFractionDigits === 0) {
24
40
  decimalSeparator = "";
25
41
  penny = "";
42
+ } else if (penny.length < minFractionDigits) {
43
+ penny = penny.padEnd(minFractionDigits, "0");
26
44
  }
27
45
 
28
46
  return { integer, penny, decimalSeparator };
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.464",
4
+ "version": "0.0.465",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -6745,7 +6745,7 @@
6745
6745
  "description": "",
6746
6746
  "attributes": [
6747
6747
  {
6748
- "name": "sum",
6748
+ "name": "value",
6749
6749
  "description": "Money value.",
6750
6750
  "value": {
6751
6751
  "kind": "expression",
@@ -6808,8 +6808,17 @@
6808
6808
  "default": "default"
6809
6809
  },
6810
6810
  {
6811
- "name": "decimalScale",
6812
- "description": "Set the numeral decimal scale after the comma.",
6811
+ "name": "minFractionDigits",
6812
+ "description": "Minimal number of signs after the decimal separator (fractional part of a number).",
6813
+ "value": {
6814
+ "kind": "expression",
6815
+ "type": "number"
6816
+ },
6817
+ "default": "0"
6818
+ },
6819
+ {
6820
+ "name": "maxFractionDigits",
6821
+ "description": "Maximal number of signs after the decimal separator (fractional part of a number).",
6813
6822
  "value": {
6814
6823
  "kind": "expression",
6815
6824
  "type": "number"
@@ -6826,22 +6835,22 @@
6826
6835
  "default": ","
6827
6836
  },
6828
6837
  {
6829
- "name": "align",
6830
- "description": "Money align.",
6838
+ "name": "thousandsSeparator",
6839
+ "description": "A symbol used to separate the thousand parts of a number.",
6831
6840
  "value": {
6832
6841
  "kind": "expression",
6833
- "type": "'right' | 'left'"
6842
+ "type": "string"
6834
6843
  },
6835
- "default": "left"
6844
+ "default": " "
6836
6845
  },
6837
6846
  {
6838
- "name": "integer",
6839
- "description": "Make money sum integer.",
6847
+ "name": "align",
6848
+ "description": "Money align.",
6840
6849
  "value": {
6841
6850
  "kind": "expression",
6842
- "type": "boolean"
6851
+ "type": "'right' | 'left'"
6843
6852
  },
6844
- "default": "false"
6853
+ "default": "left"
6845
6854
  },
6846
6855
  {
6847
6856
  "name": "planned",