v-money3 3.23.0 → 3.24.0

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
@@ -29,9 +29,9 @@ Feel free to open an issue or post a pull request!
29
29
  ## Arbitrary precision
30
30
 
31
31
  Arbitrary precision is only supported with `v-model`.
32
- It expects to receive a string representation of a number. `'12345.67'`
32
+ It expects to receive a string representation of a number, such as `'12345.67'`
33
33
 
34
- Some break changes where introduced in this release.
34
+ Some break changes were introduced in this release.
35
35
  Let's follow a train of thought:
36
36
  If your precision is set to `2` and you set a default model value of `'55'`,
37
37
  it will be interpreted as `'0.55'`.
@@ -45,11 +45,10 @@ boundaries of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript
45
45
  If you fit this instance, you need to use `v-model`
46
46
  with the number modifier, or `v-model.number`. But than,
47
47
  you are stuck with numbers smaller than `2^53 - 1` or
48
- `9007199254740991` or `9,007,199,254,740,991`.
49
- Little more than nine quadrilion...
48
+ `9007199254740991` or `9,007,199,254,740,991`. - Little more than nine quadrilion...
50
49
  See [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER).
51
50
 
52
- For those who are using `v-model.number`, integers and floats are compleatly
51
+ For those who are using `v-model.number`, integers and floats are completely
53
52
  understood.
54
53
  Let's follow another train of thought:
55
54
  If your precision is set to `2` and you set a default model value of `55`,
@@ -131,6 +130,8 @@ app.directive('money3', Money3Directive)
131
130
  max: null,
132
131
  allowBlank: false,
133
132
  minimumNumberOfCharacters: 0,
133
+ shouldRound: true,
134
+ focusOnRight: false,
134
135
  }
135
136
  }
136
137
  }
@@ -197,6 +198,8 @@ Must use `v-model.lazy` to bind works properly.
197
198
  max: null,
198
199
  allowBlank: false,
199
200
  minimumNumberOfCharacters: 0,
201
+ shouldRound: true,
202
+ focusOnRight: false,
200
203
  }
201
204
  }
202
205
  },
@@ -205,7 +208,7 @@ Must use `v-model.lazy` to bind works properly.
205
208
  </script>
206
209
  ```
207
210
 
208
- By default directives work with `v-model`.
211
+ By default, directives work with `v-model`.
209
212
  It is not possible to use `v-model.number` on directives, so, if you need
210
213
  to work with floats/integers on directives you need to configure the `number`
211
214
  modifier manually.
@@ -223,21 +226,23 @@ If you bind it directly you are just fine too:
223
226
 
224
227
  ## Properties
225
228
 
226
- | property | Required | Type | Default | Description |
227
- |-----------|----------|---------|---------|---------------------------------------------------------|
228
- | precision | **true** | Number | 2 | How many decimal places |
229
- | decimal | false | String | "." | Decimal separator |
230
- | thousands | false | String | "," | Thousands separator |
231
- | prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
232
- | suffix | false | String | "" | Percentage for example: " %" |
233
- | masked | false | Boolean | false | If the component output should include the mask or not |
234
- | disable-negative | false | Boolean | false | Component does not allow negative values |
235
- | disabled | false | Boolean | false | Disable the inner input tag |
236
- | min | false | Number | null | The min value allowed |
237
- | max | false | Number | null | The max value allowed |
238
- | allow-blank | false | Boolean | false | If the field can start blank and be cleared out by user |
239
- | minimum-number-of-characters | false | Number | 0 | The minimum number of characters that the mask should show |
240
- | should-round | false | Boolean | true | Should default values be rounded or sliced |
229
+ | property | Required | Type | Default | Description |
230
+ |------------------------------|----------|----------|---------|------------------------------------------------------------|
231
+ | precision | **true** | Number | 2 | How many decimal places |
232
+ | decimal | false | String | "." | Decimal separator |
233
+ | thousands | false | String | "," | Thousands separator |
234
+ | prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
235
+ | suffix | false | String | "" | Percentage for example: " %" |
236
+ | masked | false | Boolean | false | If the component output should include the mask or not |
237
+ | disable-negative | false | Boolean | false | Component does not allow negative values |
238
+ | disabled | false | Boolean | false | Disable the inner input tag |
239
+ | min | false | Number | null | The min value allowed |
240
+ | max | false | Number | null | The max value allowed |
241
+ | allow-blank | false | Boolean | false | If the field can start blank and be cleared out by user |
242
+ | minimum-number-of-characters | false | Number | 0 | The minimum number of characters that the mask should show |
243
+ | should-round | false | Boolean | true | Should default values be rounded or sliced |
244
+ | focus-on-right | false | Boolean | false | When focus, set the cursor to the far right |
245
+
241
246
 
242
247
  ## Restricted Characters
243
248
 
@@ -261,7 +266,7 @@ A console warn with more information will be shown!
261
266
  Use it directly in the browser!
262
267
 
263
268
  ```html
264
- <script src="https://unpkg.com/v-money3@3.23.0/dist/v-money3.umd.js"></script>
269
+ <script src="https://unpkg.com/v-money3@3.24.0/dist/v-money3.umd.js"></script>
265
270
  ```
266
271
 
267
272
  Take a look at issue [#15](https://github.com/jonathanpmartins/v-money3/issues/15#issuecomment-830988807) and also this [codesandbox](https://codesandbox.io/s/mystifying-paper-bpfyn?file=/index.html) working example.
@@ -288,6 +293,8 @@ const config = {
288
293
  modelModifiers: {
289
294
  number: false,
290
295
  },
296
+ shouldRound: true,
297
+ focusOnRight: false,
291
298
  }
292
299
 
293
300
  const formatted = format(12345.67, config);
@@ -1,7 +1,7 @@
1
1
  type NumberParam = bigint | number | string;
2
2
  export default class BigNumber {
3
- private number;
4
- private decimal;
3
+ protected number: bigint;
4
+ protected decimal: number;
5
5
  constructor(number: NumberParam);
6
6
  getNumber(): bigint;
7
7
  getDecimalPrecision(): number;
package/dist/Utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ExtractPropTypes } from 'vue';
1
2
  import { VMoneyOptions } from './options';
2
3
  export declare const RESTRICTED_CHARACTERS: string[];
3
4
  export declare const RESTRICTED_OPTIONS: string[];
@@ -7,8 +8,8 @@ export declare function onlyNumbers(input: number | string): string;
7
8
  export declare function addThousandSeparator(integer: string, separator: string): string;
8
9
  export declare function joinIntegerAndDecimal(integer: string, decimal: string, separator: string): string;
9
10
  export declare function validateRestrictedInput(value: string, caller: string): boolean;
10
- export declare function validateRestrictedOptions(opt: VMoneyOptions): boolean;
11
- export declare function filterOptRestrictions(opt: VMoneyOptions): VMoneyOptions;
11
+ export declare function validateRestrictedOptions(opt: VMoneyOptions | ExtractPropTypes<never>): boolean;
12
+ export declare function filterOptRestrictions(opt: VMoneyOptions | ExtractPropTypes<never>): VMoneyOptions | ExtractPropTypes<never>;
12
13
  export declare function guessFloatPrecision(string: string): number;
13
14
  export declare function removeLeadingZeros(string: string): string;
14
15
  export declare function isValidInteger(str: string): boolean;
@@ -17,4 +18,4 @@ export declare function replaceAt(str: string, index: number, chr: string | numb
17
18
  export declare function round(string: string, precision: number): string;
18
19
  export declare function setCursor(el: HTMLInputElement, position: number): void;
19
20
  export declare function event(name: string): Event;
20
- export declare function debug({ debug }: VMoneyOptions, ...args: any): void;
21
+ export declare function debug({ debug }: VMoneyOptions | ExtractPropTypes<never>, ...args: any): void;
@@ -76,6 +76,10 @@ declare const _default: import("vue").DefineComponent<{
76
76
  type: BooleanConstructor;
77
77
  default: () => boolean;
78
78
  };
79
+ focusOnRight: {
80
+ type: BooleanConstructor;
81
+ default: () => boolean;
82
+ };
79
83
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
80
84
  "update:model-value": (value: string | number) => void;
81
85
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
@@ -156,6 +160,10 @@ declare const _default: import("vue").DefineComponent<{
156
160
  type: BooleanConstructor;
157
161
  default: () => boolean;
158
162
  };
163
+ focusOnRight: {
164
+ type: BooleanConstructor;
165
+ default: () => boolean;
166
+ };
159
167
  }>> & {
160
168
  "onUpdate:model-value"?: ((value: string | number) => any) | undefined;
161
169
  }, {
@@ -174,6 +182,7 @@ declare const _default: import("vue").DefineComponent<{
174
182
  minimumNumberOfCharacters: number;
175
183
  modelModifiers: Record<string, any>;
176
184
  shouldRound: boolean;
185
+ focusOnRight: boolean;
177
186
  id: string | number;
178
187
  }>;
179
188
  export default _default;
package/dist/format.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ import { ExtractPropTypes } from 'vue';
1
2
  import { VMoneyOptions } from './options';
2
- export default function format(input: string | number | null | undefined, opt?: VMoneyOptions, caller?: string): string;
3
+ export default function format(input: string | number | null | undefined, opt?: VMoneyOptions | ExtractPropTypes<never>, caller?: string): string;
package/dist/options.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface VMoneyOptions {
14
14
  minimumNumberOfCharacters: number;
15
15
  modelModifiers: any;
16
16
  shouldRound: boolean;
17
+ focusOnRight: boolean;
17
18
  [key: string]: any;
18
19
  }
19
20
  declare const _default: VMoneyOptions;
@@ -1,2 +1,3 @@
1
+ import { ExtractPropTypes } from 'vue';
1
2
  import { VMoneyOptions } from './options';
2
- export default function unformat(input: string, opt?: VMoneyOptions, caller?: string): string | number;
3
+ export default function unformat(input: string, opt?: VMoneyOptions | ExtractPropTypes<never>, caller?: string): string | number;
package/dist/v-money3.mjs CHANGED
@@ -1,58 +1,77 @@
1
- var L = Object.defineProperty;
2
- var H = (t, e, n) => e in t ? L(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var w = (t, e, n) => (H(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- import { defineComponent as K, getCurrentInstance as W, toRefs as Z, ref as z, watch as G, useAttrs as J, computed as Q, resolveDirective as X, withDirectives as Y, openBlock as ee, createElementBlock as te, mergeProps as ne, unref as b } from "vue";
5
- const M = ["+", "-"], $ = ["decimal", "thousands", "prefix", "suffix"];
6
- function f(t) {
1
+ var W = Object.defineProperty;
2
+ var Z = (t, e, n) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var w = (t, e, n) => (Z(t, typeof e != "symbol" ? e + "" : e, n), n);
4
+ import { defineComponent as z, getCurrentInstance as G, toRefs as J, ref as Q, watch as X, useAttrs as Y, computed as ee, resolveDirective as te, withDirectives as ne, openBlock as ie, createElementBlock as re, mergeProps as ae, unref as v } from "vue";
5
+ const l = {
6
+ debug: !1,
7
+ masked: !1,
8
+ prefix: "",
9
+ suffix: "",
10
+ thousands: ",",
11
+ decimal: ".",
12
+ precision: 2,
13
+ disableNegative: !1,
14
+ disabled: !1,
15
+ min: null,
16
+ max: null,
17
+ allowBlank: !1,
18
+ minimumNumberOfCharacters: 0,
19
+ modelModifiers: {
20
+ number: !1
21
+ },
22
+ shouldRound: !0,
23
+ focusOnRight: !1
24
+ }, $ = ["+", "-"], V = ["decimal", "thousands", "prefix", "suffix"];
25
+ function d(t) {
7
26
  return Math.max(0, Math.min(t, 1e3));
8
27
  }
9
- function y(t, e) {
28
+ function N(t, e) {
10
29
  return t = t.padStart(e + 1, "0"), e === 0 ? t : `${t.slice(0, -e)}.${t.slice(-e)}`;
11
30
  }
12
- function V(t) {
31
+ function F(t) {
13
32
  return t = t ? t.toString() : "", t.replace(/\D+/g, "") || "0";
14
33
  }
15
- function ie(t, e) {
34
+ function se(t, e) {
16
35
  return t.replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${e}`);
17
36
  }
18
- function re(t, e, n) {
37
+ function ue(t, e, n) {
19
38
  return e ? t + n + e : t;
20
39
  }
21
- function h(t, e) {
22
- return M.includes(t) ? (console.warn(`v-money3 "${e}" property don't accept "${t}" as a value.`), !1) : /\d/g.test(t) ? (console.warn(`v-money3 "${e}" property don't accept "${t}" (any number) as a value.`), !1) : !0;
40
+ function b(t, e) {
41
+ return $.includes(t) ? (console.warn(`v-money3 "${e}" property don't accept "${t}" as a value.`), !1) : /\d/g.test(t) ? (console.warn(`v-money3 "${e}" property don't accept "${t}" (any number) as a value.`), !1) : !0;
23
42
  }
24
- function ae(t) {
25
- for (const e of $)
26
- if (!h(t[e], e))
43
+ function le(t) {
44
+ for (const e of V)
45
+ if (!b(t[e], e))
27
46
  return !1;
28
47
  return !0;
29
48
  }
30
- function N(t) {
31
- for (const e of $) {
49
+ function x(t) {
50
+ for (const e of V) {
32
51
  t[e] = t[e].replace(/\d+/g, "");
33
- for (const n of M)
52
+ for (const n of $)
34
53
  t[e] = t[e].replaceAll(n, "");
35
54
  }
36
55
  return t;
37
56
  }
38
- function F(t) {
57
+ function I(t) {
39
58
  const e = t.length, n = t.indexOf(".");
40
59
  return e - (n + 1);
41
60
  }
42
61
  function C(t) {
43
62
  return t.replace(/^(-?)0+(?!\.)(.+)/, "$1$2");
44
63
  }
45
- function I(t) {
64
+ function A(t) {
46
65
  return /^-?[\d]+$/g.test(t);
47
66
  }
48
- function O(t) {
67
+ function D(t) {
49
68
  return /^-?[\d]+(\.[\d]+)$/g.test(t);
50
69
  }
51
- function R(t, e, n) {
70
+ function O(t, e, n) {
52
71
  return e > t.length - 1 ? t : t.substring(0, e) + n + t.substring(e + 1);
53
72
  }
54
- function A(t, e) {
55
- const n = e - F(t);
73
+ function P(t, e) {
74
+ const n = e - I(t);
56
75
  if (n >= 0)
57
76
  return t;
58
77
  let i = t.slice(0, n);
@@ -63,46 +82,27 @@ function A(t, e) {
63
82
  if (u !== "." && u !== "-") {
64
83
  const o = parseInt(u, 10) + 1;
65
84
  if (o < 10)
66
- return R(i, s, o);
67
- i = R(i, s, "0");
85
+ return O(i, s, o);
86
+ i = O(i, s, "0");
68
87
  }
69
88
  }
70
89
  return `1${i}`;
71
90
  }
72
91
  return i;
73
92
  }
74
- function se(t, e) {
93
+ function _(t, e) {
75
94
  const n = () => {
76
95
  t.setSelectionRange(e, e);
77
96
  };
78
97
  t === document.activeElement && (n(), setTimeout(n, 1));
79
98
  }
80
- function D(t) {
99
+ function j(t) {
81
100
  return new Event(t, { bubbles: !0, cancelable: !1 });
82
101
  }
83
102
  function r({ debug: t = !1 }, ...e) {
84
103
  t && console.log(...e);
85
104
  }
86
- const l = {
87
- debug: !1,
88
- masked: !1,
89
- prefix: "",
90
- suffix: "",
91
- thousands: ",",
92
- decimal: ".",
93
- precision: 2,
94
- disableNegative: !1,
95
- disabled: !1,
96
- min: null,
97
- max: null,
98
- allowBlank: !1,
99
- minimumNumberOfCharacters: 0,
100
- modelModifiers: {
101
- number: !1
102
- },
103
- shouldRound: !0
104
- };
105
- class x {
105
+ class p {
106
106
  constructor(e) {
107
107
  w(this, "number", 0n);
108
108
  w(this, "decimal", 0);
@@ -120,7 +120,7 @@ class x {
120
120
  toFixed(e = 0, n = !0) {
121
121
  let i = this.toString();
122
122
  const a = e - this.getDecimalPrecision();
123
- return a > 0 ? (i.includes(".") || (i += "."), i.padEnd(i.length + a, "0")) : a < 0 ? n ? A(i, e) : i.slice(0, a) : i;
123
+ return a > 0 ? (i.includes(".") || (i += "."), i.padEnd(i.length + a, "0")) : a < 0 ? n ? P(i, e) : i.slice(0, a) : i;
124
124
  }
125
125
  toString() {
126
126
  let e = this.number.toString();
@@ -143,16 +143,16 @@ class x {
143
143
  return n === i;
144
144
  }
145
145
  setupString(e) {
146
- if (e = C(e), I(e))
146
+ if (e = C(e), A(e))
147
147
  this.number = BigInt(e);
148
- else if (O(e))
149
- this.decimal = F(e), this.number = BigInt(e.replace(".", ""));
148
+ else if (D(e))
149
+ this.decimal = I(e), this.number = BigInt(e.replace(".", ""));
150
150
  else
151
151
  throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`);
152
152
  }
153
153
  adjustComparisonNumbers(e) {
154
154
  let n;
155
- e.constructor.name !== "BigNumber" ? n = new x(e) : n = e;
155
+ e.constructor.name !== "BigNumber" ? n = new p(e) : n = e;
156
156
  const i = this.getDecimalPrecision() - n.getDecimalPrecision();
157
157
  let a = this.getNumber(), s = n.getNumber();
158
158
  return i > 0 ? s = n.getNumber() * 10n ** BigInt(i) : i < 0 && (a = this.getNumber() * 10n ** BigInt(i * -1)), [a, s];
@@ -162,62 +162,65 @@ function k(t, e = l, n = "") {
162
162
  if (r(e, "utils format() - caller", n), r(e, "utils format() - input1", t), t == null)
163
163
  t = "";
164
164
  else if (typeof t == "number")
165
- e.shouldRound ? t = t.toFixed(f(e.precision)) : t = t.toFixed(f(e.precision) + 1).slice(0, -1);
166
- else if (e.modelModifiers && e.modelModifiers.number && I(t))
167
- t = Number(t).toFixed(f(e.precision));
165
+ e.shouldRound ? t = t.toFixed(d(e.precision)) : t = t.toFixed(d(e.precision) + 1).slice(0, -1);
166
+ else if (e.modelModifiers && e.modelModifiers.number && A(t))
167
+ t = Number(t).toFixed(d(e.precision));
168
168
  else if (!e.disableNegative && t === "-")
169
169
  return t;
170
170
  r(e, "utils format() - input2", t);
171
171
  const i = e.disableNegative ? "" : t.indexOf("-") >= 0 ? "-" : "";
172
172
  let a = t.replace(e.prefix, "").replace(e.suffix, "");
173
- r(e, "utils format() - filtered", a), !e.precision && e.thousands !== "." && O(a) && (a = A(a, 0), r(e, "utils format() - !opt.precision && isValidFloat()", a));
174
- const s = V(a);
175
- r(e, "utils format() - numbers", s), r(e, "utils format() - numbersToCurrency", i + y(s, e.precision));
176
- const u = new x(i + y(s, e.precision));
173
+ r(e, "utils format() - filtered", a), !e.precision && e.thousands !== "." && D(a) && (a = P(a, 0), r(e, "utils format() - !opt.precision && isValidFloat()", a));
174
+ const s = F(a);
175
+ r(e, "utils format() - numbers", s), r(e, "utils format() - numbersToCurrency", i + N(s, e.precision));
176
+ const u = new p(i + N(s, e.precision));
177
177
  r(e, "utils format() - bigNumber1", u.toString()), e.max && u.biggerThan(e.max) && u.setNumber(e.max), e.min && u.lessThan(e.min) && u.setNumber(e.min);
178
- const o = u.toFixed(f(e.precision), e.shouldRound);
179
- if (r(e, "utils format() - bigNumber2", u.toFixed(f(e.precision))), /^0(\.0+)?$/g.test(o) && e.allowBlank)
178
+ const o = u.toFixed(d(e.precision), e.shouldRound);
179
+ if (r(e, "utils format() - bigNumber2", u.toFixed(d(e.precision))), /^0(\.0+)?$/g.test(o) && e.allowBlank)
180
180
  return "";
181
- let [c, m] = o.split(".");
182
- const p = m !== void 0 ? m.length : 0;
183
- c = c.padStart(e.minimumNumberOfCharacters - p, "0"), c = ie(c, e.thousands);
184
- const v = e.prefix + re(c, m, e.decimal) + e.suffix;
185
- return r(e, "utils format() - output", v), v;
181
+ let [g, f] = o.split(".");
182
+ const h = f !== void 0 ? f.length : 0;
183
+ g = g.padStart(e.minimumNumberOfCharacters - h, "0"), g = se(g, e.thousands);
184
+ const y = e.prefix + ue(g, f, e.decimal) + e.suffix;
185
+ return r(e, "utils format() - output", y), y;
186
186
  }
187
187
  function S(t, e = l, n = "") {
188
188
  if (r(e, "utils unformat() - caller", n), r(e, "utils unformat() - input", t), !e.disableNegative && t === "-")
189
189
  return r(e, "utils unformat() - return netagive symbol", t), t;
190
190
  const i = e.disableNegative ? "" : t.indexOf("-") >= 0 ? "-" : "", a = t.replace(e.prefix, "").replace(e.suffix, "");
191
191
  r(e, "utils unformat() - filtered", a);
192
- const s = V(a);
192
+ const s = F(a);
193
193
  r(e, "utils unformat() - numbers", s);
194
- const u = new x(i + y(s, e.precision));
194
+ const u = new p(i + N(s, e.precision));
195
195
  r(e, "utils unformat() - bigNumber1", s.toString()), e.max && u.biggerThan(e.max) && u.setNumber(e.max), e.min && u.lessThan(e.min) && u.setNumber(e.min);
196
- let o = u.toFixed(f(e.precision), e.shouldRound);
196
+ let o = u.toFixed(d(e.precision), e.shouldRound);
197
197
  return e.modelModifiers && e.modelModifiers.number && (o = parseFloat(o)), r(e, "utils unformat() - output", o), o;
198
198
  }
199
- const B = (t, e, n) => {
200
- if (r(e, "directive setValue() - caller", n), !ae(e)) {
199
+ const R = (t, e, n) => {
200
+ if (r(e, "directive setValue() - caller", n), !le(e)) {
201
201
  r(e, "directive setValue() - validateRestrictedOptions() return false. Stopping here...", t.value);
202
202
  return;
203
203
  }
204
204
  let i = t.value.length - (t.selectionEnd || 0);
205
- t.value = k(t.value, e, n), i = Math.max(i, e.suffix.length), i = t.value.length - i, i = Math.max(i, e.prefix.length), se(t, i), t.dispatchEvent(D("change"));
205
+ t.value = k(t.value, e, n), i = Math.max(i, e.suffix.length), i = t.value.length - i, i = Math.max(i, e.prefix.length), _(t, i), t.dispatchEvent(j("change"));
206
206
  }, T = (t, e) => {
207
207
  const n = t.currentTarget, i = t.code === "Backspace" || t.code === "Delete", a = n.value.length - (n.selectionEnd || 0) === 0;
208
- if (r(e, "directive onkeydown() - el.value", n.value), r(e, "directive onkeydown() - backspacePressed", i), r(e, "directive onkeydown() - isAtEndPosition", a), e.allowBlank && i && a && S(n.value, e, "directive onkeydown allowBlank") === 0 && (r(e, 'directive onkeydown() - set el.value = ""', n.value), n.value = "", n.dispatchEvent(D("change"))), r(e, "directive onkeydown() - e.key", t.key), t.key === "+") {
208
+ if (r(e, "directive onkeydown() - el.value", n.value), r(e, "directive onkeydown() - backspacePressed", i), r(e, "directive onkeydown() - isAtEndPosition", a), e.allowBlank && i && a && S(n.value, e, "directive onkeydown allowBlank") === 0 && (r(e, 'directive onkeydown() - set el.value = ""', n.value), n.value = "", n.dispatchEvent(j("change"))), r(e, "directive onkeydown() - e.key", t.key), t.key === "+") {
209
209
  r(e, "directive onkeydown() - unformat el.value", n.value);
210
210
  let s = S(n.value, e, "directive onkeydown +");
211
211
  typeof s == "string" && (s = parseFloat(s)), s < 0 && (n.value = String(s * -1));
212
212
  }
213
213
  }, E = (t, e) => {
214
214
  const n = t.currentTarget;
215
- r(e, "directive oninput()", n.value), /^[1-9]$/.test(n.value) && (n.value = y(n.value, f(e.precision)), r(e, "directive oninput() - is 1-9", n.value)), B(n, e, "directive oninput");
216
- }, P = {
215
+ r(e, "directive oninput()", n.value), /^[1-9]$/.test(n.value) && (n.value = N(n.value, d(e.precision)), r(e, "directive oninput() - is 1-9", n.value)), R(n, e, "directive oninput");
216
+ }, M = (t, e) => {
217
+ const n = t.currentTarget;
218
+ r(e, "directive onFocus()", n.value), e.focusOnRight && _(n, n.value.length - e.suffix.length);
219
+ }, q = {
217
220
  mounted(t, e) {
218
221
  if (!e.value)
219
222
  return;
220
- const n = N({ ...l, ...e.value });
223
+ const n = x({ ...l, ...e.value });
221
224
  if (r(n, "directive mounted() - opt", n), t.tagName.toLocaleUpperCase() !== "INPUT") {
222
225
  const i = t.getElementsByTagName("input");
223
226
  i.length !== 1 || (t = i[0]);
@@ -226,29 +229,33 @@ const B = (t, e, n) => {
226
229
  T(i, n);
227
230
  }, t.oninput = (i) => {
228
231
  E(i, n);
229
- }, r(n, "directive mounted() - el.value", t.value), B(t, n, "directive mounted");
232
+ }, t.onfocus = (i) => {
233
+ M(i, n);
234
+ }, r(n, "directive mounted() - el.value", t.value), R(t, n, "directive mounted");
230
235
  },
231
236
  updated(t, e) {
232
237
  if (!e.value)
233
238
  return;
234
- const n = N({ ...l, ...e.value });
239
+ const n = x({ ...l, ...e.value });
235
240
  t.onkeydown = (i) => {
236
241
  T(i, n);
237
242
  }, t.oninput = (i) => {
238
243
  E(i, n);
239
- }, r(n, "directive updated() - el.value", t.value), r(n, "directive updated() - opt", n), B(t, n, "directive updated");
244
+ }, t.onfocus = (i) => {
245
+ M(i, n);
246
+ }, r(n, "directive updated() - el.value", t.value), r(n, "directive updated() - opt", n), R(t, n, "directive updated");
240
247
  },
241
248
  beforeUnmount(t) {
242
249
  t.onkeydown = null, t.oninput = null, t.onfocus = null;
243
250
  }
244
- }, ue = ["id", "value", "disabled"], le = {
251
+ }, oe = ["id", "value", "disabled"], ce = {
245
252
  inheritAttrs: !1,
246
253
  name: "Money3",
247
254
  directives: {
248
- money3: P
255
+ money3: q
249
256
  }
250
- }, oe = /* @__PURE__ */ K({
251
- ...le,
257
+ }, de = /* @__PURE__ */ z({
258
+ ...ce,
252
259
  props: {
253
260
  debug: {
254
261
  required: !1,
@@ -259,7 +266,7 @@ const B = (t, e, n) => {
259
266
  required: !1,
260
267
  type: [Number, String],
261
268
  default: () => {
262
- const t = W();
269
+ const t = G();
263
270
  return t ? t.uid : null;
264
271
  }
265
272
  },
@@ -284,28 +291,28 @@ const B = (t, e, n) => {
284
291
  type: String,
285
292
  default: () => l.decimal,
286
293
  validator(t) {
287
- return h(t, "decimal");
294
+ return b(t, "decimal");
288
295
  }
289
296
  },
290
297
  thousands: {
291
298
  type: String,
292
299
  default: () => l.thousands,
293
300
  validator(t) {
294
- return h(t, "thousands");
301
+ return b(t, "thousands");
295
302
  }
296
303
  },
297
304
  prefix: {
298
305
  type: String,
299
306
  default: () => l.prefix,
300
307
  validator(t) {
301
- return h(t, "prefix");
308
+ return b(t, "prefix");
302
309
  }
303
310
  },
304
311
  suffix: {
305
312
  type: String,
306
313
  default: () => l.suffix,
307
314
  validator(t) {
308
- return h(t, "suffix");
315
+ return b(t, "suffix");
309
316
  }
310
317
  },
311
318
  disableNegative: {
@@ -335,53 +342,57 @@ const B = (t, e, n) => {
335
342
  shouldRound: {
336
343
  type: Boolean,
337
344
  default: () => l.shouldRound
345
+ },
346
+ focusOnRight: {
347
+ type: Boolean,
348
+ default: () => l.focusOnRight
338
349
  }
339
350
  },
340
351
  emits: ["update:model-value"],
341
352
  setup(t, { emit: e }) {
342
- const n = t, { modelValue: i, modelModifiers: a, masked: s, precision: u, shouldRound: o } = Z(n);
353
+ const n = t, { modelValue: i, modelModifiers: a, masked: s, precision: u, shouldRound: o, focusOnRight: g } = J(n);
343
354
  r(n, "component setup()", n);
344
- let c = i.value;
345
- (n.disableNegative || c !== "-") && a.value && a.value.number && (o.value ? c = Number(i.value).toFixed(f(u.value)) : c = Number(i.value).toFixed(f(u.value) + 1).slice(0, -1));
346
- const m = z(k(c, n, "component setup"));
347
- r(n, "component setup() - data.formattedValue", m.value), G(i, p);
348
- function p(g) {
349
- r(n, "component watch() -> value", g);
350
- const d = k(
351
- g,
352
- N({ ...n }),
355
+ let f = i.value;
356
+ (n.disableNegative || f !== "-") && a.value && a.value.number && (o.value ? f = Number(i.value).toFixed(d(u.value)) : f = Number(i.value).toFixed(d(u.value) + 1).slice(0, -1));
357
+ const h = Q(k(f, n, "component setup"));
358
+ r(n, "component setup() - data.formattedValue", h.value), X(i, y);
359
+ function y(m) {
360
+ r(n, "component watch() -> value", m);
361
+ const c = k(
362
+ m,
363
+ x({ ...n }),
353
364
  "component watch"
354
365
  );
355
- d !== m.value && (r(n, "component watch() changed -> formatted", d), m.value = d);
366
+ c !== h.value && (r(n, "component watch() changed -> formatted", c), h.value = c);
356
367
  }
357
- let v = null;
358
- function _(g) {
359
- let d = g.target.value;
360
- r(n, "component change() -> evt.target.value", d), s.value && !a.value.number || (d = S(
361
- d,
362
- N({ ...n }),
368
+ let B = null;
369
+ function U(m) {
370
+ let c = m.target.value;
371
+ r(n, "component change() -> evt.target.value", c), s.value && !a.value.number || (c = S(
372
+ c,
373
+ x({ ...n }),
363
374
  "component change"
364
- )), d !== v && (v = d, r(n, "component change() -> update:model-value", d), e("update:model-value", d));
375
+ )), c !== B && (B = c, r(n, "component change() -> update:model-value", c), e("update:model-value", c));
365
376
  }
366
- const j = J(), q = Q(() => {
367
- const g = {
368
- ...j
377
+ const L = Y(), H = ee(() => {
378
+ const m = {
379
+ ...L
369
380
  };
370
- return delete g["onUpdate:modelValue"], g;
381
+ return delete m["onUpdate:modelValue"], m;
371
382
  });
372
- return (g, d) => {
373
- const U = X("money3");
374
- return Y((ee(), te("input", ne({
383
+ return (m, c) => {
384
+ const K = te("money3");
385
+ return ne((ie(), re("input", ae({
375
386
  id: `${t.id}`
376
- }, b(q), {
387
+ }, v(H), {
377
388
  type: "tel",
378
389
  class: "v-money3",
379
- value: m.value,
390
+ value: h.value,
380
391
  disabled: n.disabled,
381
- onChange: _
382
- }), null, 16, ue)), [
383
- [U, {
384
- precision: b(u),
392
+ onChange: U
393
+ }), null, 16, oe)), [
394
+ [K, {
395
+ precision: v(u),
385
396
  decimal: n.decimal,
386
397
  thousands: n.thousands,
387
398
  prefix: n.prefix,
@@ -392,26 +403,27 @@ const B = (t, e, n) => {
392
403
  allowBlank: n.allowBlank,
393
404
  minimumNumberOfCharacters: n.minimumNumberOfCharacters,
394
405
  debug: n.debug,
395
- modelModifiers: b(a),
396
- shouldRound: b(o)
406
+ modelModifiers: v(a),
407
+ shouldRound: v(o),
408
+ focusOnRight: v(g)
397
409
  }]
398
410
  ]);
399
411
  };
400
412
  }
401
- }), fe = {
413
+ }), ge = {
402
414
  install(t) {
403
- t.component("money3", oe), t.directive("money3", P);
415
+ t.component("money3", de), t.directive("money3", q);
404
416
  }
405
417
  };
406
418
  export {
407
- x as BigNumber,
408
- oe as Money,
409
- oe as Money3,
410
- oe as Money3Component,
411
- P as Money3Directive,
412
- P as VMoney,
413
- P as VMoney3,
414
- fe as default,
419
+ p as BigNumber,
420
+ de as Money,
421
+ de as Money3,
422
+ de as Money3Component,
423
+ q as Money3Directive,
424
+ q as VMoney,
425
+ q as VMoney3,
426
+ ge as default,
415
427
  k as format,
416
428
  S as unformat
417
429
  };
@@ -1 +1 @@
1
- (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l["v-money3"]={},l.Vue))})(this,function(l,a){"use strict";var X=Object.defineProperty;var Y=(l,a,h)=>a in l?X(l,a,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[a]=h;var R=(l,a,h)=>(Y(l,typeof a!="symbol"?a+"":a,h),h);const h=["+","-"],E=["decimal","thousands","prefix","suffix"];function g(t){return Math.max(0,Math.min(t,1e3))}function w(t,e){return t=t.padStart(e+1,"0"),e===0?t:`${t.slice(0,-e)}.${t.slice(-e)}`}function V(t){return t=t?t.toString():"",t.replace(/\D+/g,"")||"0"}function q(t,e){return t.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${e}`)}function U(t,e,n){return e?t+n+e:t}function y(t,e){return h.includes(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" as a value.`),!1):/\d/g.test(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" (any number) as a value.`),!1):!0}function L(t){for(const e of E)if(!y(t[e],e))return!1;return!0}function S(t){for(const e of E){t[e]=t[e].replace(/\d+/g,"");for(const n of h)t[e]=t[e].replaceAll(n,"")}return t}function $(t){const e=t.length,n=t.indexOf(".");return e-(n+1)}function O(t){return t.replace(/^(-?)0+(?!\.)(.+)/,"$1$2")}function F(t){return/^-?[\d]+$/g.test(t)}function I(t){return/^-?[\d]+(\.[\d]+)$/g.test(t)}function D(t,e,n){return e>t.length-1?t:t.substring(0,e)+n+t.substring(e+1)}function A(t,e){const n=e-$(t);if(n>=0)return t;let i=t.slice(0,n);const s=t.slice(n);if(i.charAt(i.length-1)==="."&&(i=i.slice(0,-1)),parseInt(s.charAt(0),10)>=5){for(let u=i.length-1;u>=0;u-=1){const o=i.charAt(u);if(o!=="."&&o!=="-"){const c=parseInt(o,10)+1;if(c<10)return D(i,u,c);i=D(i,u,"0")}}return`1${i}`}return i}function H(t,e){const n=()=>{t.setSelectionRange(e,e)};t===document.activeElement&&(n(),setTimeout(n,1))}function P(t){return new Event(t,{bubbles:!0,cancelable:!1})}function r({debug:t=!1},...e){t&&console.log(...e)}const d={debug:!1,masked:!1,prefix:"",suffix:"",thousands:",",decimal:".",precision:2,disableNegative:!1,disabled:!1,min:null,max:null,allowBlank:!1,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0};class N{constructor(e){R(this,"number",0n);R(this,"decimal",0);this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e=="bigint"?this.number=e:typeof e=="number"?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,n=!0){let i=this.toString();const s=e-this.getDecimalPrecision();return s>0?(i.includes(".")||(i+="."),i.padEnd(i.length+s,"0")):s<0?n?A(i,e):i.slice(0,s):i}toString(){let e=this.number.toString();if(this.decimal){let n=!1;return e.charAt(0)==="-"&&(e=e.substring(1),n=!0),e=e.padStart(e.length+this.decimal,"0"),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=O(e),(n?"-":"")+e}return e}lessThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n<i}biggerThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n>i}isEqual(e){const[n,i]=this.adjustComparisonNumbers(e);return n===i}setupString(e){if(e=O(e),F(e))this.number=BigInt(e);else if(I(e))this.decimal=$(e),this.number=BigInt(e.replace(".",""));else throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`)}adjustComparisonNumbers(e){let n;e.constructor.name!=="BigNumber"?n=new N(e):n=e;const i=this.getDecimalPrecision()-n.getDecimalPrecision();let s=this.getNumber(),u=n.getNumber();return i>0?u=n.getNumber()*10n**BigInt(i):i<0&&(s=this.getNumber()*10n**BigInt(i*-1)),[s,u]}}function k(t,e=d,n=""){if(r(e,"utils format() - caller",n),r(e,"utils format() - input1",t),t==null)t="";else if(typeof t=="number")e.shouldRound?t=t.toFixed(g(e.precision)):t=t.toFixed(g(e.precision)+1).slice(0,-1);else if(e.modelModifiers&&e.modelModifiers.number&&F(t))t=Number(t).toFixed(g(e.precision));else if(!e.disableNegative&&t==="-")return t;r(e,"utils format() - input2",t);const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"";let s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils format() - filtered",s),!e.precision&&e.thousands!=="."&&I(s)&&(s=A(s,0),r(e,"utils format() - !opt.precision && isValidFloat()",s));const u=V(s);r(e,"utils format() - numbers",u),r(e,"utils format() - numbersToCurrency",i+w(u,e.precision));const o=new N(i+w(u,e.precision));r(e,"utils format() - bigNumber1",o.toString()),e.max&&o.biggerThan(e.max)&&o.setNumber(e.max),e.min&&o.lessThan(e.min)&&o.setNumber(e.min);const c=o.toFixed(g(e.precision),e.shouldRound);if(r(e,"utils format() - bigNumber2",o.toFixed(g(e.precision))),/^0(\.0+)?$/g.test(c)&&e.allowBlank)return"";let[m,v]=c.split(".");const M=v!==void 0?v.length:0;m=m.padStart(e.minimumNumberOfCharacters-M,"0"),m=q(m,e.thousands);const p=e.prefix+U(m,v,e.decimal)+e.suffix;return r(e,"utils format() - output",p),p}function B(t,e=d,n=""){if(r(e,"utils unformat() - caller",n),r(e,"utils unformat() - input",t),!e.disableNegative&&t==="-")return r(e,"utils unformat() - return netagive symbol",t),t;const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"",s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils unformat() - filtered",s);const u=V(s);r(e,"utils unformat() - numbers",u);const o=new N(i+w(u,e.precision));r(e,"utils unformat() - bigNumber1",u.toString()),e.max&&o.biggerThan(e.max)&&o.setNumber(e.max),e.min&&o.lessThan(e.min)&&o.setNumber(e.min);let c=o.toFixed(g(e.precision),e.shouldRound);return e.modelModifiers&&e.modelModifiers.number&&(c=parseFloat(c)),r(e,"utils unformat() - output",c),c}const C=(t,e,n)=>{if(r(e,"directive setValue() - caller",n),!L(e)){r(e,"directive setValue() - validateRestrictedOptions() return false. Stopping here...",t.value);return}let i=t.value.length-(t.selectionEnd||0);t.value=k(t.value,e,n),i=Math.max(i,e.suffix.length),i=t.value.length-i,i=Math.max(i,e.prefix.length),H(t,i),t.dispatchEvent(P("change"))},_=(t,e)=>{const n=t.currentTarget,i=t.code==="Backspace"||t.code==="Delete",s=n.value.length-(n.selectionEnd||0)===0;if(r(e,"directive onkeydown() - el.value",n.value),r(e,"directive onkeydown() - backspacePressed",i),r(e,"directive onkeydown() - isAtEndPosition",s),e.allowBlank&&i&&s&&B(n.value,e,"directive onkeydown allowBlank")===0&&(r(e,'directive onkeydown() - set el.value = ""',n.value),n.value="",n.dispatchEvent(P("change"))),r(e,"directive onkeydown() - e.key",t.key),t.key==="+"){r(e,"directive onkeydown() - unformat el.value",n.value);let u=B(n.value,e,"directive onkeydown +");typeof u=="string"&&(u=parseFloat(u)),u<0&&(n.value=String(u*-1))}},j=(t,e)=>{const n=t.currentTarget;r(e,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=w(n.value,g(e.precision)),r(e,"directive oninput() - is 1-9",n.value)),C(n,e,"directive oninput")},x={mounted(t,e){if(!e.value)return;const n=S({...d,...e.value});if(r(n,"directive mounted() - opt",n),t.tagName.toLocaleUpperCase()!=="INPUT"){const i=t.getElementsByTagName("input");i.length!==1||(t=i[0])}t.onkeydown=i=>{_(i,n)},t.oninput=i=>{j(i,n)},r(n,"directive mounted() - el.value",t.value),C(t,n,"directive mounted")},updated(t,e){if(!e.value)return;const n=S({...d,...e.value});t.onkeydown=i=>{_(i,n)},t.oninput=i=>{j(i,n)},r(n,"directive updated() - el.value",t.value),r(n,"directive updated() - opt",n),C(t,n,"directive updated")},beforeUnmount(t){t.onkeydown=null,t.oninput=null,t.onfocus=null}},K=["id","value","disabled"],W={inheritAttrs:!1,name:"Money3",directives:{money3:x}},T=a.defineComponent({...W,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{const t=a.getCurrentInstance();return t?t.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>d.precision},decimal:{type:String,default:()=>d.decimal,validator(t){return y(t,"decimal")}},thousands:{type:String,default:()=>d.thousands,validator(t){return y(t,"thousands")}},prefix:{type:String,default:()=>d.prefix,validator(t){return y(t,"prefix")}},suffix:{type:String,default:()=>d.suffix,validator(t){return y(t,"suffix")}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>d.max},min:{type:[Number,String],default:()=>d.min},allowBlank:{type:Boolean,default:()=>d.allowBlank},minimumNumberOfCharacters:{type:Number,default:()=>d.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>d.shouldRound}},emits:["update:model-value"],setup(t,{emit:e}){const n=t,{modelValue:i,modelModifiers:s,masked:u,precision:o,shouldRound:c}=a.toRefs(n);r(n,"component setup()",n);let m=i.value;(n.disableNegative||m!=="-")&&s.value&&s.value.number&&(c.value?m=Number(i.value).toFixed(g(o.value)):m=Number(i.value).toFixed(g(o.value)+1).slice(0,-1));const v=a.ref(k(m,n,"component setup"));r(n,"component setup() - data.formattedValue",v.value),a.watch(i,M);function M(b){r(n,"component watch() -> value",b);const f=k(b,S({...n}),"component watch");f!==v.value&&(r(n,"component watch() changed -> formatted",f),v.value=f)}let p=null;function z(b){let f=b.target.value;r(n,"component change() -> evt.target.value",f),u.value&&!s.value.number||(f=B(f,S({...n}),"component change")),f!==p&&(p=f,r(n,"component change() -> update:model-value",f),e("update:model-value",f))}const G=a.useAttrs(),J=a.computed(()=>{const b={...G};return delete b["onUpdate:modelValue"],b});return(b,f)=>{const Q=a.resolveDirective("money3");return a.withDirectives((a.openBlock(),a.createElementBlock("input",a.mergeProps({id:`${t.id}`},a.unref(J),{type:"tel",class:"v-money3",value:v.value,disabled:n.disabled,onChange:z}),null,16,K)),[[Q,{precision:a.unref(o),decimal:n.decimal,thousands:n.thousands,prefix:n.prefix,suffix:n.suffix,disableNegative:n.disableNegative,min:n.min,max:n.max,allowBlank:n.allowBlank,minimumNumberOfCharacters:n.minimumNumberOfCharacters,debug:n.debug,modelModifiers:a.unref(s),shouldRound:a.unref(c)}]])}}}),Z={install(t){t.component("money3",T),t.directive("money3",x)}};l.BigNumber=N,l.Money=T,l.Money3=T,l.Money3Component=T,l.Money3Directive=x,l.VMoney=x,l.VMoney3=x,l.default=Z,l.format=k,l.unformat=B,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l["v-money3"]={},l.Vue))})(this,function(l,a){"use strict";var ee=Object.defineProperty;var te=(l,a,o)=>a in l?ee(l,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[a]=o;var C=(l,a,o)=>(te(l,typeof a!="symbol"?a+"":a,o),o);const o={debug:!1,masked:!1,prefix:"",suffix:"",thousands:",",decimal:".",precision:2,disableNegative:!1,disabled:!1,min:null,max:null,allowBlank:!1,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0,focusOnRight:!1},M=["+","-"],O=["decimal","thousands","prefix","suffix"];function m(t){return Math.max(0,Math.min(t,1e3))}function p(t,e){return t=t.padStart(e+1,"0"),e===0?t:`${t.slice(0,-e)}.${t.slice(-e)}`}function E(t){return t=t?t.toString():"",t.replace(/\D+/g,"")||"0"}function H(t,e){return t.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${e}`)}function K(t,e,n){return e?t+n+e:t}function y(t,e){return M.includes(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" as a value.`),!1):/\d/g.test(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" (any number) as a value.`),!1):!0}function W(t){for(const e of O)if(!y(t[e],e))return!1;return!0}function w(t){for(const e of O){t[e]=t[e].replace(/\d+/g,"");for(const n of M)t[e]=t[e].replaceAll(n,"")}return t}function V(t){const e=t.length,n=t.indexOf(".");return e-(n+1)}function $(t){return t.replace(/^(-?)0+(?!\.)(.+)/,"$1$2")}function F(t){return/^-?[\d]+$/g.test(t)}function I(t){return/^-?[\d]+(\.[\d]+)$/g.test(t)}function D(t,e,n){return e>t.length-1?t:t.substring(0,e)+n+t.substring(e+1)}function A(t,e){const n=e-V(t);if(n>=0)return t;let i=t.slice(0,n);const s=t.slice(n);if(i.charAt(i.length-1)==="."&&(i=i.slice(0,-1)),parseInt(s.charAt(0),10)>=5){for(let u=i.length-1;u>=0;u-=1){const c=i.charAt(u);if(c!=="."&&c!=="-"){const d=parseInt(c,10)+1;if(d<10)return D(i,u,d);i=D(i,u,"0")}}return`1${i}`}return i}function P(t,e){const n=()=>{t.setSelectionRange(e,e)};t===document.activeElement&&(n(),setTimeout(n,1))}function _(t){return new Event(t,{bubbles:!0,cancelable:!1})}function r({debug:t=!1},...e){t&&console.log(...e)}class N{constructor(e){C(this,"number",0n);C(this,"decimal",0);this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e=="bigint"?this.number=e:typeof e=="number"?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,n=!0){let i=this.toString();const s=e-this.getDecimalPrecision();return s>0?(i.includes(".")||(i+="."),i.padEnd(i.length+s,"0")):s<0?n?A(i,e):i.slice(0,s):i}toString(){let e=this.number.toString();if(this.decimal){let n=!1;return e.charAt(0)==="-"&&(e=e.substring(1),n=!0),e=e.padStart(e.length+this.decimal,"0"),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=$(e),(n?"-":"")+e}return e}lessThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n<i}biggerThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n>i}isEqual(e){const[n,i]=this.adjustComparisonNumbers(e);return n===i}setupString(e){if(e=$(e),F(e))this.number=BigInt(e);else if(I(e))this.decimal=V(e),this.number=BigInt(e.replace(".",""));else throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`)}adjustComparisonNumbers(e){let n;e.constructor.name!=="BigNumber"?n=new N(e):n=e;const i=this.getDecimalPrecision()-n.getDecimalPrecision();let s=this.getNumber(),u=n.getNumber();return i>0?u=n.getNumber()*10n**BigInt(i):i<0&&(s=this.getNumber()*10n**BigInt(i*-1)),[s,u]}}function S(t,e=o,n=""){if(r(e,"utils format() - caller",n),r(e,"utils format() - input1",t),t==null)t="";else if(typeof t=="number")e.shouldRound?t=t.toFixed(m(e.precision)):t=t.toFixed(m(e.precision)+1).slice(0,-1);else if(e.modelModifiers&&e.modelModifiers.number&&F(t))t=Number(t).toFixed(m(e.precision));else if(!e.disableNegative&&t==="-")return t;r(e,"utils format() - input2",t);const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"";let s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils format() - filtered",s),!e.precision&&e.thousands!=="."&&I(s)&&(s=A(s,0),r(e,"utils format() - !opt.precision && isValidFloat()",s));const u=E(s);r(e,"utils format() - numbers",u),r(e,"utils format() - numbersToCurrency",i+p(u,e.precision));const c=new N(i+p(u,e.precision));r(e,"utils format() - bigNumber1",c.toString()),e.max&&c.biggerThan(e.max)&&c.setNumber(e.max),e.min&&c.lessThan(e.min)&&c.setNumber(e.min);const d=c.toFixed(m(e.precision),e.shouldRound);if(r(e,"utils format() - bigNumber2",c.toFixed(m(e.precision))),/^0(\.0+)?$/g.test(d)&&e.allowBlank)return"";let[v,g]=d.split(".");const b=g!==void 0?g.length:0;v=v.padStart(e.minimumNumberOfCharacters-b,"0"),v=H(v,e.thousands);const B=e.prefix+K(v,g,e.decimal)+e.suffix;return r(e,"utils format() - output",B),B}function k(t,e=o,n=""){if(r(e,"utils unformat() - caller",n),r(e,"utils unformat() - input",t),!e.disableNegative&&t==="-")return r(e,"utils unformat() - return netagive symbol",t),t;const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"",s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils unformat() - filtered",s);const u=E(s);r(e,"utils unformat() - numbers",u);const c=new N(i+p(u,e.precision));r(e,"utils unformat() - bigNumber1",u.toString()),e.max&&c.biggerThan(e.max)&&c.setNumber(e.max),e.min&&c.lessThan(e.min)&&c.setNumber(e.min);let d=c.toFixed(m(e.precision),e.shouldRound);return e.modelModifiers&&e.modelModifiers.number&&(d=parseFloat(d)),r(e,"utils unformat() - output",d),d}const T=(t,e,n)=>{if(r(e,"directive setValue() - caller",n),!W(e)){r(e,"directive setValue() - validateRestrictedOptions() return false. Stopping here...",t.value);return}let i=t.value.length-(t.selectionEnd||0);t.value=S(t.value,e,n),i=Math.max(i,e.suffix.length),i=t.value.length-i,i=Math.max(i,e.prefix.length),P(t,i),t.dispatchEvent(_("change"))},j=(t,e)=>{const n=t.currentTarget,i=t.code==="Backspace"||t.code==="Delete",s=n.value.length-(n.selectionEnd||0)===0;if(r(e,"directive onkeydown() - el.value",n.value),r(e,"directive onkeydown() - backspacePressed",i),r(e,"directive onkeydown() - isAtEndPosition",s),e.allowBlank&&i&&s&&k(n.value,e,"directive onkeydown allowBlank")===0&&(r(e,'directive onkeydown() - set el.value = ""',n.value),n.value="",n.dispatchEvent(_("change"))),r(e,"directive onkeydown() - e.key",t.key),t.key==="+"){r(e,"directive onkeydown() - unformat el.value",n.value);let u=k(n.value,e,"directive onkeydown +");typeof u=="string"&&(u=parseFloat(u)),u<0&&(n.value=String(u*-1))}},q=(t,e)=>{const n=t.currentTarget;r(e,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=p(n.value,m(e.precision)),r(e,"directive oninput() - is 1-9",n.value)),T(n,e,"directive oninput")},U=(t,e)=>{const n=t.currentTarget;r(e,"directive onFocus()",n.value),e.focusOnRight&&P(n,n.value.length-e.suffix.length)},x={mounted(t,e){if(!e.value)return;const n=w({...o,...e.value});if(r(n,"directive mounted() - opt",n),t.tagName.toLocaleUpperCase()!=="INPUT"){const i=t.getElementsByTagName("input");i.length!==1||(t=i[0])}t.onkeydown=i=>{j(i,n)},t.oninput=i=>{q(i,n)},t.onfocus=i=>{U(i,n)},r(n,"directive mounted() - el.value",t.value),T(t,n,"directive mounted")},updated(t,e){if(!e.value)return;const n=w({...o,...e.value});t.onkeydown=i=>{j(i,n)},t.oninput=i=>{q(i,n)},t.onfocus=i=>{U(i,n)},r(n,"directive updated() - el.value",t.value),r(n,"directive updated() - opt",n),T(t,n,"directive updated")},beforeUnmount(t){t.onkeydown=null,t.oninput=null,t.onfocus=null}},Z=["id","value","disabled"],z={inheritAttrs:!1,name:"Money3",directives:{money3:x}},R=a.defineComponent({...z,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{const t=a.getCurrentInstance();return t?t.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>o.precision},decimal:{type:String,default:()=>o.decimal,validator(t){return y(t,"decimal")}},thousands:{type:String,default:()=>o.thousands,validator(t){return y(t,"thousands")}},prefix:{type:String,default:()=>o.prefix,validator(t){return y(t,"prefix")}},suffix:{type:String,default:()=>o.suffix,validator(t){return y(t,"suffix")}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>o.max},min:{type:[Number,String],default:()=>o.min},allowBlank:{type:Boolean,default:()=>o.allowBlank},minimumNumberOfCharacters:{type:Number,default:()=>o.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>o.shouldRound},focusOnRight:{type:Boolean,default:()=>o.focusOnRight}},emits:["update:model-value"],setup(t,{emit:e}){const n=t,{modelValue:i,modelModifiers:s,masked:u,precision:c,shouldRound:d,focusOnRight:v}=a.toRefs(n);r(n,"component setup()",n);let g=i.value;(n.disableNegative||g!=="-")&&s.value&&s.value.number&&(d.value?g=Number(i.value).toFixed(m(c.value)):g=Number(i.value).toFixed(m(c.value)+1).slice(0,-1));const b=a.ref(S(g,n,"component setup"));r(n,"component setup() - data.formattedValue",b.value),a.watch(i,B);function B(h){r(n,"component watch() -> value",h);const f=S(h,w({...n}),"component watch");f!==b.value&&(r(n,"component watch() changed -> formatted",f),b.value=f)}let L=null;function J(h){let f=h.target.value;r(n,"component change() -> evt.target.value",f),u.value&&!s.value.number||(f=k(f,w({...n}),"component change")),f!==L&&(L=f,r(n,"component change() -> update:model-value",f),e("update:model-value",f))}const Q=a.useAttrs(),X=a.computed(()=>{const h={...Q};return delete h["onUpdate:modelValue"],h});return(h,f)=>{const Y=a.resolveDirective("money3");return a.withDirectives((a.openBlock(),a.createElementBlock("input",a.mergeProps({id:`${t.id}`},a.unref(X),{type:"tel",class:"v-money3",value:b.value,disabled:n.disabled,onChange:J}),null,16,Z)),[[Y,{precision:a.unref(c),decimal:n.decimal,thousands:n.thousands,prefix:n.prefix,suffix:n.suffix,disableNegative:n.disableNegative,min:n.min,max:n.max,allowBlank:n.allowBlank,minimumNumberOfCharacters:n.minimumNumberOfCharacters,debug:n.debug,modelModifiers:a.unref(s),shouldRound:a.unref(d),focusOnRight:a.unref(v)}]])}}}),G={install(t){t.component("money3",R),t.directive("money3",x)}};l.BigNumber=N,l.Money=R,l.Money3=R,l.Money3Component=R,l.Money3Directive=x,l.VMoney=x,l.VMoney3=x,l.default=G,l.format=S,l.unformat=k,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v-money3",
3
- "version": "3.23.0",
3
+ "version": "3.24.0",
4
4
  "description": "Vue3 currency input/directive mask",
5
5
  "main": "./dist/v-money3.umd.js",
6
6
  "module": "./dist/v-money3.mjs",
@@ -49,29 +49,29 @@
49
49
  "vue": ">= 3.2.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@babel/plugin-transform-runtime": "7.19.1",
53
- "@babel/preset-env": "7.19.1",
54
- "@types/jest": "29.0.3",
55
- "@types/jest-environment-puppeteer": "5.0.2",
56
- "@types/puppeteer": "5.4.6",
57
- "@typescript-eslint/eslint-plugin": "5.38.1",
58
- "@typescript-eslint/parser": "5.38.1",
59
- "@vitejs/plugin-vue": "3.1.0",
60
- "@vue/compiler-sfc": "3.2.39",
61
- "@vue/test-utils": "2.0.2",
52
+ "@babel/plugin-transform-runtime": "7.21.0",
53
+ "@babel/preset-env": "7.20.2",
54
+ "@types/jest": "29.5.0",
55
+ "@types/jest-environment-puppeteer": "5.0.3",
56
+ "@types/puppeteer": "5.4.7",
57
+ "@typescript-eslint/eslint-plugin": "5.56.0",
58
+ "@typescript-eslint/parser": "5.56.0",
59
+ "@vitejs/plugin-vue": "3.2.0",
60
+ "@vue/compiler-sfc": "3.2.47",
61
+ "@vue/test-utils": "2.3.2",
62
62
  "babel-jest": "26.6.3",
63
- "eslint": "8.24.0",
63
+ "eslint": "8.36.0",
64
64
  "eslint-config-airbnb-base": "15.0.0",
65
65
  "eslint-config-airbnb-typescript": "17.0.0",
66
- "eslint-plugin-import": "2.26.0",
67
- "eslint-plugin-vue": "9.5.1",
66
+ "eslint-plugin-import": "2.27.5",
67
+ "eslint-plugin-vue": "9.9.0",
68
68
  "jest": "26.6.3",
69
- "jest-puppeteer": "6.1.1",
70
- "node": "16.17.1",
69
+ "jest-puppeteer": "6.2.0",
70
+ "node": "16.19.1",
71
71
  "ts-jest": "26.5.6",
72
- "vite": "3.1.3",
73
- "vue": "3.2.31",
72
+ "vite": "3.2.5",
73
+ "vue": "3.2.44",
74
74
  "vue-jest": "5.0.0-alpha.10",
75
- "vue-tsc": "1.0.0-beta.0"
75
+ "vue-tsc": "1.3.2"
76
76
  }
77
77
  }