v-money3 3.24.1 → 3.25.1

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/README.md CHANGED
@@ -7,64 +7,49 @@
7
7
 
8
8
  ![The Mask Money](https://cdn-images-1.medium.com/max/600/1*Rpc289FpghuHrnzyVpOUig.gif)
9
9
 
10
- ## Disclaimer
10
+ ## Introduction
11
11
 
12
- The old [`v-money`](https://github.com/vuejs-tips/v-money) library seems to be abandoned!
13
- Since I use it in many projects and part of then will be upgraded to Vue3,
14
- I needed it to work after the upgrades.
15
-
16
- Feel free to open an issue or post a pull request!
12
+ Welcome to `v-money3`, a versatile money masking solution designed specifically for `Vue 3` applications. This library serves as a replacement for the now-abandoned [`v-money`](https://github.com/vuejs-tips/v-money) library, ensuring compatibility and functionality for projects transitioning to `Vue 3`.
17
13
 
18
14
  ## Features
19
15
 
20
- - Arbitrary Precision with `BigInt`
21
- - Lightweight (<4KB gzipped)
22
- - Dependency free
23
- - Mobile support
24
- - Component or Directive flavors
25
- - Accept copy/paste
26
- - Editable
27
- - Min / Max Limits
28
-
29
- ## Arbitrary precision
30
-
31
- Arbitrary precision is only supported with `v-model`.
32
- It expects to receive a string representation of a number, such as `'12345.67'`
33
-
34
- Some break changes were introduced in this release.
35
- Let's follow a train of thought:
36
- If your precision is set to `2` and you set a default model value of `'55'`,
37
- it will be interpreted as `'0.55'`.
38
- To instruct the correct format on setup you need to pass in `'55.00'`
39
- when using `v-model`. The same is true for `'5.5'`.
40
- It will be interpreted as `'0.55'`. Another example: `'55.5'` => `'5.55'`.
41
- Arbitrary precision is supported by using `string` and `BigInt` with `v-model`.
42
-
43
- For the majority of users, it will make sense to use float numbers and stay within the
44
- boundaries of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
45
- If you fit this instance, you need to use `v-model`
46
- with the number modifier, or `v-model.number`. But than,
47
- you are stuck with numbers smaller than `2^53 - 1` or
48
- `9007199254740991` or `9,007,199,254,740,991`. - Little more than nine quadrilion...
49
- See [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER).
50
-
51
- For those who are using `v-model.number`, integers and floats are completely
52
- understood.
53
- Let's follow another train of thought:
54
- If your precision is set to `2` and you set a default model value of `55`,
55
- it will be interpreted as `55.00`. The same is true for `5.5`.
56
- It will be interpreted as `5.50`. Another example: `55.5` => `55.50`.
16
+ - **Arbitrary Precision:** Utilize [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) for precise calculations.
17
+ - **Lightweight:** Less than 4KB when gzipped.
18
+ - **Dependency-free:** No external dependencies for seamless integration.
19
+ - **Mobile Support:** Ensures a consistent experience across devices.
20
+ - **Component or Directive Flavors:** Choose between component-based or directive-based implementation.
21
+ - **Copy/Paste Support:** Easily accept input via copy/paste actions.
22
+ - **Min/Max Limits:** Set minimum and maximum limits for input values.
23
+
24
+ ## Arbitrary Precision
25
+
26
+ In this release, some breaking changes have been introduced. Let's delve into the details:
27
+
28
+ `v-money3` supports arbitrary precision through the use of `BigInt`. Arbitrary precision is only supported with `v-model`. When using `v-model`, ensure the input is provided as a string representation of a number (e.g., `'12345.67'`). If your precision is set to `2` and you provide a default `v-model` value of `'55'`, it will be interpreted as `'0.55'`. To maintain the correct format, ensure you pass `'55.00'` when using `v-model`.
29
+
30
+
31
+ For most users, it's advisable to utilize floating-point numbers and adhere to the boundaries of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number). In such cases, employing `v-model` with the number modifier, or `v-model.number`, is recommended. However, this limits you to numbers smaller than `2^53 - 1` or `9007199254740991` (approximately nine quadrillion). Refer to [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) for more information. For users employing `v-model.number`, integers and floats are intuitively understood. If your precision is set to `2` and you input a default `v-model.number` value of `55`, it will be interpreted as `55.00`. The same applies to `5.5`, which will be rendered as `5.50`.
32
+
57
33
 
58
34
  [More Examples](https://github.com/jonathanpmartins/v-money3/issues/38#issuecomment-903214235)
59
35
 
60
- ## Usage
36
+ ## Browser Target
61
37
 
62
- ### Installation
38
+ If you encounter the error message: `Big integer literals are not available in the configured target environment`, please ensure your browser targets are updated to include at least the following entries:
39
+ ```
40
+ ['es2020', 'safari14']
41
+ ```
42
+ Can I use `bigInt`? https://caniuse.com/bigint
43
+
44
+ More information: [#66](https://github.com/jonathanpmartins/v-money3/issues/66), [#70](https://github.com/jonathanpmartins/v-money3/issues/70), [#89](https://github.com/jonathanpmartins/v-money3/issues/89)
45
+
46
+ ## Installation
63
47
 
64
48
  ```bash
65
49
  npm i v-money3 --save
66
50
  ```
67
51
 
52
+ ## Usage
68
53
 
69
54
  ### Register Globally ([view codesandbox](https://codesandbox.io/s/v-money3-global-registering-lv1jv?file=/src/main.js))
70
55
 
@@ -129,6 +114,7 @@ app.directive('money3', Money3Directive)
129
114
  min: null,
130
115
  max: null,
131
116
  allowBlank: false,
117
+ treatZeroAsBlank: true,
132
118
  minimumNumberOfCharacters: 0,
133
119
  shouldRound: true,
134
120
  focusOnRight: false,
@@ -141,16 +127,12 @@ app.directive('money3', Money3Directive)
141
127
 
142
128
  ### Component v-model number modifier ([view codesandbox](https://codesandbox.io/s/v-money3-use-as-component-forked-523de?file=/src/App.vue))
143
129
 
144
- `v-model` will always return a string.
145
- If the `masked` property is set to true it will be formatted,
146
- otherwise it will be a fixed string representation of a float number.
147
- If you need your model to be a float number use the `number` modifier.
148
- Ex.: `v-model.number="amount"`
130
+ When using `v-model`, the returned value will always be a `string`.
131
+ If the `masked` property is set to `true`, it will be formatted accordingly; otherwise, it will be a fixed string representation of a floating-point number.
132
+ If you require your model to be a floating-point number, utilize the `number` modifier. For example:
149
133
 
150
- - `v-model="amount"` will return a fixed string with typeof `string`.
151
- Ex.: "123456.78"
152
- - `v-model.number="amount"` will return a float number with typeof
153
- `number`. Ex.: 123456.78
134
+ - `v-model="amount"` will return a fixed string with a typeof `string`. For instance: `'123456.78'`
135
+ - `v-model.number="amount"` will return a floating-point number with a typeof `number`. For example: `123456.78`
154
136
 
155
137
  ```html
156
138
  <template>
@@ -173,7 +155,7 @@ Ex.: "123456.78"
173
155
  ```
174
156
 
175
157
  ### Use as directive ([view codesandbox](https://codesandbox.io/s/v-money3-use-as-directive-e7ror?file=/src/App.vue))
176
- Must use `v-model.lazy` to bind works properly.
158
+ To ensure proper functionality, you must use `v-model.lazy` for binding.
177
159
  ```html
178
160
  <template>
179
161
  <input v-model.lazy="amount" v-money3="config" />
@@ -197,6 +179,7 @@ Must use `v-model.lazy` to bind works properly.
197
179
  min: null,
198
180
  max: null,
199
181
  allowBlank: false,
182
+ treatZeroAsBlank: true,
200
183
  minimumNumberOfCharacters: 0,
201
184
  shouldRound: true,
202
185
  focusOnRight: false,
@@ -208,10 +191,8 @@ Must use `v-model.lazy` to bind works properly.
208
191
  </script>
209
192
  ```
210
193
 
211
- By default, directives work with `v-model`.
212
- It is not possible to use `v-model.number` on directives, so, if you need
213
- to work with floats/integers on directives you need to configure the `number`
214
- modifier manually.
194
+ By default, directives are only compatible with `v-model`. It's important to note that using `v-model.number` directly on directives is not supported.
195
+ If you need to work with `float` or `integer` on directives, you'll need to manually configure the number modifier.
215
196
 
216
197
  Using config:
217
198
  ```javascipt
@@ -219,7 +200,7 @@ modelModifiers: {
219
200
  number: true,
220
201
  }
221
202
  ```
222
- If you bind it directly you are just fine too:
203
+ If you directly bind it, you're perfectly fine as well:
223
204
  ```html
224
205
  <input :model-modifiers="{ number: true }" v-model.lazy="amount" v-money3="config" />
225
206
  ```
@@ -239,6 +220,7 @@ If you bind it directly you are just fine too:
239
220
  | min | false | Number | null | The min value allowed |
240
221
  | max | false | Number | null | The max value allowed |
241
222
  | allow-blank | false | Boolean | false | If the field can start blank and be cleared out by user |
223
+ | treat-zero-as-blank | false | Boolean | true | When `allow-blank` is true, controls whether zero is rendered as blank. Set to `false` to distinguish zero from blank (e.g. show `0.00` and only blank on empty input). Has no effect when `allow-blank` is false |
242
224
  | minimum-number-of-characters | false | Number | 0 | The minimum number of characters that the mask should show |
243
225
  | should-round | false | Boolean | true | Should default values be rounded or sliced |
244
226
  | focus-on-right | false | Boolean | false | When focus, set the cursor to the far right |
@@ -257,8 +239,7 @@ Numbers `0-9` and the following characters...
257
239
  - `prefix`
258
240
  - `suffix`
259
241
 
260
- Restricted inputs will be filter out of the final mask.
261
- A console warn with more information will be shown!
242
+ Restricted inputs will be filtered out of the final mask, and a console warning with more information will be displayed.
262
243
 
263
244
 
264
245
  ## Don't want to use a package manager?
@@ -289,6 +270,7 @@ const config = {
289
270
  min: null,
290
271
  max: null,
291
272
  allowBlank: false,
273
+ treatZeroAsBlank: true,
292
274
  minimumNumberOfCharacters: 0,
293
275
  modelModifiers: {
294
276
  number: false,
@@ -314,6 +296,16 @@ console.log(unformatted);
314
296
  // output float number: 12345.67
315
297
  ```
316
298
 
299
+
300
+ ### Contribution and Feedback
301
+ Your contributions and feedback are highly valued! If you encounter any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request on GitHub.
302
+
303
+ The previous `v-money` library has been abandoned, prompting the development of v-money3 to accommodate projects migrating to `Vue 3`.
304
+
305
+ Happy coding with v-money3!
306
+
307
+
317
308
  ### References
318
309
 
319
310
  - https://github.com/vuejs-tips/v-money (based on `v-money`)
311
+
@@ -68,6 +68,10 @@ declare const _default: import("vue").DefineComponent<{
68
68
  type: BooleanConstructor;
69
69
  default: () => boolean;
70
70
  };
71
+ treatZeroAsBlank: {
72
+ type: BooleanConstructor;
73
+ default: () => boolean;
74
+ };
71
75
  minimumNumberOfCharacters: {
72
76
  type: NumberConstructor;
73
77
  default: () => number;
@@ -80,9 +84,9 @@ declare const _default: import("vue").DefineComponent<{
80
84
  type: BooleanConstructor;
81
85
  default: () => boolean;
82
86
  };
83
- }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
87
+ }, unknown, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
84
88
  "update:model-value": (value: string | number) => void;
85
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
89
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
86
90
  debug: {
87
91
  required: false;
88
92
  type: BooleanConstructor;
@@ -152,6 +156,10 @@ declare const _default: import("vue").DefineComponent<{
152
156
  type: BooleanConstructor;
153
157
  default: () => boolean;
154
158
  };
159
+ treatZeroAsBlank: {
160
+ type: BooleanConstructor;
161
+ default: () => boolean;
162
+ };
155
163
  minimumNumberOfCharacters: {
156
164
  type: NumberConstructor;
157
165
  default: () => number;
@@ -179,10 +187,11 @@ declare const _default: import("vue").DefineComponent<{
179
187
  min: string | number;
180
188
  max: string | number;
181
189
  allowBlank: boolean;
190
+ treatZeroAsBlank: boolean;
182
191
  minimumNumberOfCharacters: number;
183
192
  modelModifiers: Record<string, any>;
184
193
  shouldRound: boolean;
185
194
  focusOnRight: boolean;
186
195
  id: string | number;
187
- }>;
196
+ }, {}>;
188
197
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { DirectiveBinding } from 'vue';
2
2
  declare const _default: {
3
- mounted(el: HTMLInputElement, binding: DirectiveBinding): void;
4
- updated(el: HTMLInputElement, binding: DirectiveBinding): void;
5
- beforeUnmount(el: HTMLInputElement): void;
3
+ mounted(host: HTMLInputElement, binding: DirectiveBinding): void;
4
+ updated(host: HTMLInputElement, binding: DirectiveBinding): void;
5
+ beforeUnmount(host: HTMLInputElement): void;
6
6
  };
7
7
  export default _default;
package/dist/options.d.ts CHANGED
@@ -11,10 +11,12 @@ export interface VMoneyOptions {
11
11
  min: number | string | null;
12
12
  max: number | string | null;
13
13
  allowBlank: boolean;
14
+ treatZeroAsBlank: boolean;
14
15
  minimumNumberOfCharacters: number;
15
16
  modelModifiers: any;
16
17
  shouldRound: boolean;
17
18
  focusOnRight: boolean;
19
+ lazy: boolean;
18
20
  [key: string]: any;
19
21
  }
20
22
  declare const _default: VMoneyOptions;