v-money3 3.21.0 → 3.22.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
@@ -261,7 +261,7 @@ A console warn with more information will be shown!
261
261
  Use it directly in the browser!
262
262
 
263
263
  ```html
264
- <script src="https://unpkg.com/v-money3@3.21.0/dist/v-money3.umd.js"></script>
264
+ <script src="https://unpkg.com/v-money3@3.22.1/dist/v-money3.umd.js"></script>
265
265
  ```
266
266
 
267
267
  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.
@@ -12,6 +12,6 @@ export default class BigNumber {
12
12
  biggerThan(thatBigNumber: NumberParam | BigNumber): boolean;
13
13
  isEqual(thatBigNumber: NumberParam | BigNumber): boolean;
14
14
  setupString(number: string): void;
15
- adjustComparisonNumbers(thatNumberParam: NumberParam | BigNumber): BigInt[];
15
+ adjustComparisonNumbers(thatNumberParam: NumberParam | BigNumber): bigint[];
16
16
  }
17
17
  export {};
@@ -0,0 +1,417 @@
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) {
7
+ return Math.max(0, Math.min(t, 1e3));
8
+ }
9
+ function y(t, e) {
10
+ return t = t.padStart(e + 1, "0"), e === 0 ? t : `${t.slice(0, -e)}.${t.slice(-e)}`;
11
+ }
12
+ function V(t) {
13
+ return t = t ? t.toString() : "", t.replace(/\D+/g, "") || "0";
14
+ }
15
+ function ie(t, e) {
16
+ return t.replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${e}`);
17
+ }
18
+ function re(t, e, n) {
19
+ return e ? t + n + e : t;
20
+ }
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;
23
+ }
24
+ function ae(t) {
25
+ for (const e of $)
26
+ if (!h(t[e], e))
27
+ return !1;
28
+ return !0;
29
+ }
30
+ function N(t) {
31
+ for (const e of $) {
32
+ t[e] = t[e].replace(/\d+/g, "");
33
+ for (const n of M)
34
+ t[e] = t[e].replaceAll(n, "");
35
+ }
36
+ return t;
37
+ }
38
+ function F(t) {
39
+ const e = t.length, n = t.indexOf(".");
40
+ return e - (n + 1);
41
+ }
42
+ function C(t) {
43
+ return t.replace(/^(-?)0+(?!\.)(.+)/, "$1$2");
44
+ }
45
+ function I(t) {
46
+ return /^-?[\d]+$/g.test(t);
47
+ }
48
+ function O(t) {
49
+ return /^-?[\d]+(\.[\d]+)$/g.test(t);
50
+ }
51
+ function R(t, e, n) {
52
+ return e > t.length - 1 ? t : t.substring(0, e) + n + t.substring(e + 1);
53
+ }
54
+ function A(t, e) {
55
+ const n = e - F(t);
56
+ if (n >= 0)
57
+ return t;
58
+ let i = t.slice(0, n);
59
+ const a = t.slice(n);
60
+ if (i.charAt(i.length - 1) === "." && (i = i.slice(0, -1)), parseInt(a.charAt(0), 10) >= 5) {
61
+ for (let s = i.length - 1; s >= 0; s -= 1) {
62
+ const u = i.charAt(s);
63
+ if (u !== "." && u !== "-") {
64
+ const o = parseInt(u, 10) + 1;
65
+ if (o < 10)
66
+ return R(i, s, o);
67
+ i = R(i, s, "0");
68
+ }
69
+ }
70
+ return `1${i}`;
71
+ }
72
+ return i;
73
+ }
74
+ function se(t, e) {
75
+ const n = () => {
76
+ t.setSelectionRange(e, e);
77
+ };
78
+ t === document.activeElement && (n(), setTimeout(n, 1));
79
+ }
80
+ function D(t) {
81
+ return new Event(t, { bubbles: !0, cancelable: !1 });
82
+ }
83
+ function r({ debug: t = !1 }, ...e) {
84
+ t && console.log(...e);
85
+ }
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 {
106
+ constructor(e) {
107
+ w(this, "number", 0n);
108
+ w(this, "decimal", 0);
109
+ this.setNumber(e);
110
+ }
111
+ getNumber() {
112
+ return this.number;
113
+ }
114
+ getDecimalPrecision() {
115
+ return this.decimal;
116
+ }
117
+ setNumber(e) {
118
+ this.decimal = 0, typeof e == "bigint" ? this.number = e : typeof e == "number" ? this.setupString(e.toString()) : this.setupString(e);
119
+ }
120
+ toFixed(e = 0, n = !0) {
121
+ let i = this.toString();
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;
124
+ }
125
+ toString() {
126
+ let e = this.number.toString();
127
+ if (this.decimal) {
128
+ let n = !1;
129
+ 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 = C(e), (n ? "-" : "") + e;
130
+ }
131
+ return e;
132
+ }
133
+ lessThan(e) {
134
+ const [n, i] = this.adjustComparisonNumbers(e);
135
+ return n < i;
136
+ }
137
+ biggerThan(e) {
138
+ const [n, i] = this.adjustComparisonNumbers(e);
139
+ return n > i;
140
+ }
141
+ isEqual(e) {
142
+ const [n, i] = this.adjustComparisonNumbers(e);
143
+ return n === i;
144
+ }
145
+ setupString(e) {
146
+ if (e = C(e), I(e))
147
+ this.number = BigInt(e);
148
+ else if (O(e))
149
+ this.decimal = F(e), this.number = BigInt(e.replace(".", ""));
150
+ else
151
+ throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`);
152
+ }
153
+ adjustComparisonNumbers(e) {
154
+ let n;
155
+ e.constructor.name !== "BigNumber" ? n = new x(e) : n = e;
156
+ const i = this.getDecimalPrecision() - n.getDecimalPrecision();
157
+ let a = this.getNumber(), s = n.getNumber();
158
+ return i > 0 ? s = n.getNumber() * 10n ** BigInt(i) : i < 0 && (a = this.getNumber() * 10n ** BigInt(i * -1)), [a, s];
159
+ }
160
+ }
161
+ function k(t, e = l, n = "") {
162
+ if (r(e, "utils format() - caller", n), r(e, "utils format() - input1", t), t == null)
163
+ t = "";
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));
168
+ else if (!e.disableNegative && t === "-")
169
+ return t;
170
+ r(e, "utils format() - input2", t);
171
+ const i = e.disableNegative ? "" : t.indexOf("-") >= 0 ? "-" : "";
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));
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)
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;
186
+ }
187
+ function S(t, e = l, n = "") {
188
+ if (r(e, "utils unformat() - caller", n), r(e, "utils unformat() - input", t), !e.disableNegative && t === "-")
189
+ return r(e, "utils unformat() - return netagive symbol", t), t;
190
+ const i = e.disableNegative ? "" : t.indexOf("-") >= 0 ? "-" : "", a = t.replace(e.prefix, "").replace(e.suffix, "");
191
+ r(e, "utils unformat() - filtered", a);
192
+ const s = V(a);
193
+ r(e, "utils unformat() - numbers", s);
194
+ const u = new x(i + y(s, e.precision));
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);
197
+ return e.modelModifiers && e.modelModifiers.number && (o = parseFloat(o)), r(e, "utils unformat() - output", o), o;
198
+ }
199
+ const B = (t, e, n) => {
200
+ if (r(e, "directive setValue() - caller", n), !ae(e)) {
201
+ r(e, "directive setValue() - validateRestrictedOptions() return false. Stopping here...", t.value);
202
+ return;
203
+ }
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"));
206
+ }, T = (t, e) => {
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 === "+") {
209
+ r(e, "directive onkeydown() - unformat el.value", n.value);
210
+ let s = S(n.value, e, "directive onkeydown +");
211
+ typeof s == "string" && (s = parseFloat(s)), s < 0 && (n.value = String(s * -1));
212
+ }
213
+ }, E = (t, e) => {
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 = {
217
+ mounted(t, e) {
218
+ if (!e.value)
219
+ return;
220
+ const n = N({ ...l, ...e.value });
221
+ if (r(n, "directive mounted() - opt", n), t.tagName.toLocaleUpperCase() !== "INPUT") {
222
+ const i = t.getElementsByTagName("input");
223
+ i.length !== 1 || (t = i[0]);
224
+ }
225
+ t.onkeydown = (i) => {
226
+ T(i, n);
227
+ }, t.oninput = (i) => {
228
+ E(i, n);
229
+ }, r(n, "directive mounted() - el.value", t.value), B(t, n, "directive mounted");
230
+ },
231
+ updated(t, e) {
232
+ if (!e.value)
233
+ return;
234
+ const n = N({ ...l, ...e.value });
235
+ t.onkeydown = (i) => {
236
+ T(i, n);
237
+ }, t.oninput = (i) => {
238
+ E(i, n);
239
+ }, r(n, "directive updated() - el.value", t.value), r(n, "directive updated() - opt", n), B(t, n, "directive updated");
240
+ },
241
+ beforeUnmount(t) {
242
+ t.onkeydown = null, t.oninput = null, t.onfocus = null;
243
+ }
244
+ }, ue = ["id", "value", "disabled"], le = {
245
+ inheritAttrs: !1,
246
+ name: "Money3",
247
+ directives: {
248
+ money3: P
249
+ }
250
+ }, oe = /* @__PURE__ */ K({
251
+ ...le,
252
+ props: {
253
+ debug: {
254
+ required: !1,
255
+ type: Boolean,
256
+ default: !1
257
+ },
258
+ id: {
259
+ required: !1,
260
+ type: [Number, String],
261
+ default: () => {
262
+ const t = W();
263
+ return t ? t.uid : null;
264
+ }
265
+ },
266
+ modelValue: {
267
+ required: !0,
268
+ type: [Number, String]
269
+ },
270
+ modelModifiers: {
271
+ required: !1,
272
+ type: Object,
273
+ default: () => ({ number: !1 })
274
+ },
275
+ masked: {
276
+ type: Boolean,
277
+ default: !1
278
+ },
279
+ precision: {
280
+ type: Number,
281
+ default: () => l.precision
282
+ },
283
+ decimal: {
284
+ type: String,
285
+ default: () => l.decimal,
286
+ validator(t) {
287
+ return h(t, "decimal");
288
+ }
289
+ },
290
+ thousands: {
291
+ type: String,
292
+ default: () => l.thousands,
293
+ validator(t) {
294
+ return h(t, "thousands");
295
+ }
296
+ },
297
+ prefix: {
298
+ type: String,
299
+ default: () => l.prefix,
300
+ validator(t) {
301
+ return h(t, "prefix");
302
+ }
303
+ },
304
+ suffix: {
305
+ type: String,
306
+ default: () => l.suffix,
307
+ validator(t) {
308
+ return h(t, "suffix");
309
+ }
310
+ },
311
+ disableNegative: {
312
+ type: Boolean,
313
+ default: !1
314
+ },
315
+ disabled: {
316
+ type: Boolean,
317
+ default: !1
318
+ },
319
+ max: {
320
+ type: [Number, String],
321
+ default: () => l.max
322
+ },
323
+ min: {
324
+ type: [Number, String],
325
+ default: () => l.min
326
+ },
327
+ allowBlank: {
328
+ type: Boolean,
329
+ default: () => l.allowBlank
330
+ },
331
+ minimumNumberOfCharacters: {
332
+ type: Number,
333
+ default: () => l.minimumNumberOfCharacters
334
+ },
335
+ shouldRound: {
336
+ type: Boolean,
337
+ default: () => l.shouldRound
338
+ }
339
+ },
340
+ emits: ["update:model-value"],
341
+ setup(t, { emit: e }) {
342
+ const n = t, { modelValue: i, modelModifiers: a, masked: s, precision: u, shouldRound: o } = Z(n);
343
+ 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 }),
353
+ "component watch"
354
+ );
355
+ d !== m.value && (r(n, "component watch() changed -> formatted", d), m.value = d);
356
+ }
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 }),
363
+ "component change"
364
+ )), d !== v && (v = d, r(n, "component change() -> update:model-value", d), e("update:model-value", d));
365
+ }
366
+ const j = J(), q = Q(() => {
367
+ const g = {
368
+ ...j
369
+ };
370
+ return delete g["onUpdate:modelValue"], g;
371
+ });
372
+ return (g, d) => {
373
+ const U = X("money3");
374
+ return Y((ee(), te("input", ne({
375
+ id: `${t.id}`
376
+ }, b(q), {
377
+ type: "tel",
378
+ class: "v-money3",
379
+ value: m.value,
380
+ disabled: n.disabled,
381
+ onChange: _
382
+ }), null, 16, ue)), [
383
+ [U, {
384
+ precision: b(u),
385
+ decimal: n.decimal,
386
+ thousands: n.thousands,
387
+ prefix: n.prefix,
388
+ suffix: n.suffix,
389
+ disableNegative: n.disableNegative,
390
+ min: n.min,
391
+ max: n.max,
392
+ allowBlank: n.allowBlank,
393
+ minimumNumberOfCharacters: n.minimumNumberOfCharacters,
394
+ debug: n.debug,
395
+ modelModifiers: b(a),
396
+ shouldRound: b(o)
397
+ }]
398
+ ]);
399
+ };
400
+ }
401
+ }), fe = {
402
+ install(t) {
403
+ t.component("money3", oe), t.directive("money3", P);
404
+ }
405
+ };
406
+ 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,
415
+ k as format,
416
+ S as unformat
417
+ };
@@ -1 +1 @@
1
- var X=Object.defineProperty;var Y=(l,a,g)=>a in l?X(l,a,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[a]=g;var R=(l,a,g)=>(Y(l,typeof a!="symbol"?a+"":a,g),g);(function(l,a){typeof exports=="object"&&typeof module!="undefined"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(l=typeof globalThis!="undefined"?globalThis:l||self,a(l["v-money3"]={},l.Vue))})(this,function(l,a){"use strict";const g=["+","-"],E=["decimal","thousands","prefix","suffix"];function m(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 g.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 g)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 u=t.slice(n);if(i.charAt(i.length-1)==="."&&(i=i.slice(0,-1)),parseInt(u.charAt(0),10)>=5){for(let s=i.length-1;s>=0;s-=1){const o=i.charAt(s);if(o!=="."&&o!=="-"){const c=parseInt(o,10)+1;if(c<10)return D(i,s,c);i=D(i,s,"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)}var 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 u=e-this.getDecimalPrecision();return u>0?(i.includes(".")||(i+="."),i.padEnd(i.length+u,"0")):u<0?n?A(i,e):i.slice(0,u):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 u=this.getNumber(),s=n.getNumber();return i>0?s=n.getNumber()*10n**BigInt(i):i<0&&(u=this.getNumber()*10n**BigInt(i*-1)),[u,s]}}function k(t,e=d,n=""){r(e,"utils format() - caller",n),r(e,"utils format() - input1",t),t==null?t="":typeof t=="number"?e.shouldRound?t=t.toFixed(m(e.precision)):t=t.toFixed(m(e.precision)+1).slice(0,-1):e.modelModifiers&&e.modelModifiers.number&&F(t)&&(t=Number(t).toFixed(m(e.precision))),r(e,"utils format() - input2",t);const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"";let u=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils format() - filtered",u),!e.precision&&e.thousands!=="."&&I(u)&&(u=A(u,0),r(e,"utils format() - !opt.precision && isValidFloat()",u));const s=V(u);r(e,"utils format() - numbers",s),r(e,"utils format() - numbersToCurrency",i+w(s,e.precision));const o=new N(i+w(s,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(m(e.precision),e.shouldRound);if(r(e,"utils format() - bigNumber2",o.toFixed(m(e.precision))),/^0(\.0+)?$/g.test(c)&&e.allowBlank)return"";let[h,v]=c.split(".");const M=v!==void 0?v.length:0;h=h.padStart(e.minimumNumberOfCharacters-M,"0"),h=q(h,e.thousands);const x=e.prefix+U(h,v,e.decimal)+e.suffix;return r(e,"utils format() - output",x),x}function B(t,e=d,n=""){r(e,"utils unformat() - caller",n),r(e,"utils unformat() - input",t);const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"",u=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils unformat() - filtered",u);const s=V(u);r(e,"utils unformat() - numbers",s);const o=new N(i+w(s,e.precision));r(e,"utils unformat() - bigNumber1",s.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(m(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",u=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",u),e.allowBlank&&i&&u&&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 s=B(n.value,e,"directive onkeydown +");typeof s=="string"&&(s=parseFloat(s)),s<0&&(n.value=String(s*-1))}},j=(t,e)=>{const n=t.currentTarget;r(e,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=w(n.value,m(e.precision)),r(e,"directive oninput() - is 1-9",n.value)),C(n,e,"directive oninput")};var p={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}};const K=["id","value","disabled"],W={inheritAttrs:!1,name:"Money3",directives:{money3:p}},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:u,masked:s,precision:o,shouldRound:c}=a.toRefs(n);r(n,"component setup()",n);let h=i.value;u.value&&u.value.number&&(c.value?h=Number(i.value).toFixed(m(o.value)):h=Number(i.value).toFixed(m(o.value)+1).slice(0,-1));const v=a.ref(k(h,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 x=null;function z(b){let f=b.target?.value;r(n,"component change() -> evt.target.value",f),s.value&&!u.value.number||(f=B(f,S({...n}),"component change")),f!==x&&(x=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(u),shouldRound:a.unref(c)}]])}}});var Z={install(t){t.component("money3",T),t.directive("money3",p)}};l.BigNumber=N,l.Money=T,l.Money3=T,l.Money3Component=T,l.Money3Directive=p,l.VMoney=p,l.VMoney3=p,l.default=Z,l.format=k,l.unformat=B,Object.defineProperty(l,"__esModule",{value:!0}),l[Symbol.toStringTag]="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 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"}})});
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "v-money3",
3
- "version": "3.21.0",
3
+ "version": "3.22.1",
4
4
  "description": "Vue3 currency input/directive mask",
5
5
  "main": "./dist/v-money3.umd.js",
6
- "module": "./dist/v-money3.es.js",
6
+ "module": "./dist/v-money3.mjs",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./dist/v-money3.es.js",
9
+ "import": "./dist/v-money3.mjs",
10
10
  "require": "./dist/v-money3.umd.js"
11
11
  }
12
12
  },
@@ -16,10 +16,13 @@
16
16
  "dts": "vue-tsc --declaration --emitDeclarationOnly --declarationDir ./dist --removeComments false",
17
17
  "serve": "./node_modules/node/bin/node ./node_modules/vite/bin/vite.js --host=localhost --port=3000 --open --force",
18
18
  "build": "./node_modules/node/bin/node ./node_modules/vite/bin/vite.js build; npm run dts",
19
- "test": "./node_modules/node/bin/node ./node_modules/jest/bin/jest.js",
19
+ "test": "npm run test-with-jsdom; npm run test-with-puppeteer;",
20
+ "test-with-puppeteer": "./node_modules/node/bin/node ./node_modules/jest/bin/jest.js --config=jest.config.js --env=puppeteer tests/env/puppeteer/",
21
+ "test-with-jsdom": "./node_modules/node/bin/node ./node_modules/jest/bin/jest.js --config=jest.config.js --env=jsdom tests/env/jsdom/",
20
22
  "lock": "npm i --package-lock-only",
21
23
  "pack": "npm run build; npm pack;",
22
- "prepublish": "npm run build"
24
+ "prepublish": "npm run build",
25
+ "update": "export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true; npm update --verbose;"
23
26
  },
24
27
  "files": [
25
28
  "dist"
@@ -46,29 +49,29 @@
46
49
  "vue": ">= 3.2.0"
47
50
  },
48
51
  "devDependencies": {
49
- "@babel/plugin-transform-runtime": "^7.15.0",
50
- "@babel/preset-env": "^7.15.6",
51
- "@types/jest": "27.0.2",
52
- "@types/jest-environment-puppeteer": "4.4.1",
53
- "@types/puppeteer": "5.4.4",
54
- "@typescript-eslint/eslint-plugin": "^4.31.2",
55
- "@typescript-eslint/parser": "^4.31.2",
56
- "@vitejs/plugin-vue": "^1.10.2",
57
- "@vue/compiler-sfc": "^3.2.27",
58
- "@vue/test-utils": "^2.0.0-rc.18",
59
- "babel-jest": "^26.6.3",
60
- "eslint": "^7.32.0",
61
- "eslint-config-airbnb-base": "^14.2.1",
62
- "eslint-config-airbnb-typescript": "^14.0.0",
63
- "eslint-plugin-import": "^2.24.2",
64
- "eslint-plugin-vue": "^7.18.0",
65
- "jest": "^26.6.3",
66
- "jest-puppeteer": "^6.0.3",
67
- "node": "^16.13.2",
68
- "ts-jest": "^26.5.6",
69
- "vite": "^2.7.13",
70
- "vue": "^3.2.27",
71
- "vue-jest": "^5.0.0-alpha.10",
72
- "vue-tsc": "^0.30.6"
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",
62
+ "babel-jest": "26.6.3",
63
+ "eslint": "8.24.0",
64
+ "eslint-config-airbnb-base": "15.0.0",
65
+ "eslint-config-airbnb-typescript": "17.0.0",
66
+ "eslint-plugin-import": "2.26.0",
67
+ "eslint-plugin-vue": "9.5.1",
68
+ "jest": "26.6.3",
69
+ "jest-puppeteer": "6.1.1",
70
+ "node": "16.17.1",
71
+ "ts-jest": "26.5.6",
72
+ "vite": "3.1.3",
73
+ "vue": "3.2.31",
74
+ "vue-jest": "5.0.0-alpha.10",
75
+ "vue-tsc": "1.0.0-beta.0"
73
76
  }
74
77
  }
@@ -1,581 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import { defineComponent, getCurrentInstance, toRefs, ref, watch, useAttrs, computed, resolveDirective, withDirectives, openBlock, createElementBlock, mergeProps, unref } from "vue";
8
- const RESTRICTED_CHARACTERS = ["+", "-"];
9
- const RESTRICTED_OPTIONS = ["decimal", "thousands", "prefix", "suffix"];
10
- function fixed(precision) {
11
- return Math.max(0, Math.min(precision, 1e3));
12
- }
13
- function numbersToCurrency(numbers, precision) {
14
- numbers = numbers.padStart(precision + 1, "0");
15
- return precision === 0 ? numbers : `${numbers.slice(0, -precision)}.${numbers.slice(-precision)}`;
16
- }
17
- function onlyNumbers(input) {
18
- input = input ? input.toString() : "";
19
- return input.replace(/\D+/g, "") || "0";
20
- }
21
- function addThousandSeparator(integer, separator) {
22
- return integer.replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${separator}`);
23
- }
24
- function joinIntegerAndDecimal(integer, decimal, separator) {
25
- return decimal ? integer + separator + decimal : integer;
26
- }
27
- function validateRestrictedInput(value, caller) {
28
- if (RESTRICTED_CHARACTERS.includes(value)) {
29
- console.warn(`v-money3 "${caller}" property don't accept "${value}" as a value.`);
30
- return false;
31
- }
32
- if (/\d/g.test(value)) {
33
- console.warn(`v-money3 "${caller}" property don't accept "${value}" (any number) as a value.`);
34
- return false;
35
- }
36
- return true;
37
- }
38
- function validateRestrictedOptions(opt) {
39
- for (const target of RESTRICTED_OPTIONS) {
40
- const isValid = validateRestrictedInput(opt[target], target);
41
- if (!isValid) {
42
- return false;
43
- }
44
- }
45
- return true;
46
- }
47
- function filterOptRestrictions(opt) {
48
- for (const option of RESTRICTED_OPTIONS) {
49
- opt[option] = opt[option].replace(/\d+/g, "");
50
- for (const character of RESTRICTED_CHARACTERS) {
51
- opt[option] = opt[option].replaceAll(character, "");
52
- }
53
- }
54
- return opt;
55
- }
56
- function guessFloatPrecision(string) {
57
- const total = string.length;
58
- const index2 = string.indexOf(".");
59
- return total - (index2 + 1);
60
- }
61
- function removeLeadingZeros(string) {
62
- return string.replace(/^(-?)0+(?!\.)(.+)/, "$1$2");
63
- }
64
- function isValidInteger(str) {
65
- return /^-?[\d]+$/g.test(str);
66
- }
67
- function isValidFloat(str) {
68
- return /^-?[\d]+(\.[\d]+)$/g.test(str);
69
- }
70
- function replaceAt(str, index2, chr) {
71
- if (index2 > str.length - 1)
72
- return str;
73
- return str.substring(0, index2) + chr + str.substring(index2 + 1);
74
- }
75
- function round(string, precision) {
76
- const diff = precision - guessFloatPrecision(string);
77
- if (diff >= 0) {
78
- return string;
79
- }
80
- let firstPiece = string.slice(0, diff);
81
- const lastPiece = string.slice(diff);
82
- if (firstPiece.charAt(firstPiece.length - 1) === ".") {
83
- firstPiece = firstPiece.slice(0, -1);
84
- }
85
- if (parseInt(lastPiece.charAt(0), 10) >= 5) {
86
- for (let i = firstPiece.length - 1; i >= 0; i -= 1) {
87
- const char = firstPiece.charAt(i);
88
- if (char !== "." && char !== "-") {
89
- const newValue = parseInt(char, 10) + 1;
90
- if (newValue < 10) {
91
- return replaceAt(firstPiece, i, newValue);
92
- }
93
- firstPiece = replaceAt(firstPiece, i, "0");
94
- }
95
- }
96
- return `1${firstPiece}`;
97
- }
98
- return firstPiece;
99
- }
100
- function setCursor(el, position) {
101
- const setSelectionRange = () => {
102
- el.setSelectionRange(position, position);
103
- };
104
- if (el === document.activeElement) {
105
- setSelectionRange();
106
- setTimeout(setSelectionRange, 1);
107
- }
108
- }
109
- function event(name) {
110
- return new Event(name, { bubbles: true, cancelable: false });
111
- }
112
- function debug({ debug: debug2 = false }, ...args) {
113
- if (debug2)
114
- console.log(...args);
115
- }
116
- var defaults = {
117
- debug: false,
118
- masked: false,
119
- prefix: "",
120
- suffix: "",
121
- thousands: ",",
122
- decimal: ".",
123
- precision: 2,
124
- disableNegative: false,
125
- disabled: false,
126
- min: null,
127
- max: null,
128
- allowBlank: false,
129
- minimumNumberOfCharacters: 0,
130
- modelModifiers: {
131
- number: false
132
- },
133
- shouldRound: true
134
- };
135
- class BigNumber {
136
- constructor(number) {
137
- __publicField(this, "number", 0n);
138
- __publicField(this, "decimal", 0);
139
- this.setNumber(number);
140
- }
141
- getNumber() {
142
- return this.number;
143
- }
144
- getDecimalPrecision() {
145
- return this.decimal;
146
- }
147
- setNumber(number) {
148
- this.decimal = 0;
149
- if (typeof number === "bigint") {
150
- this.number = number;
151
- } else if (typeof number === "number") {
152
- this.setupString(number.toString());
153
- } else {
154
- this.setupString(number);
155
- }
156
- }
157
- toFixed(precision = 0, shouldRound = true) {
158
- let string = this.toString();
159
- const diff = precision - this.getDecimalPrecision();
160
- if (diff > 0) {
161
- if (!string.includes(".")) {
162
- string += ".";
163
- }
164
- return string.padEnd(string.length + diff, "0");
165
- }
166
- if (diff < 0) {
167
- if (shouldRound) {
168
- return round(string, precision);
169
- }
170
- return string.slice(0, diff);
171
- }
172
- return string;
173
- }
174
- toString() {
175
- let string = this.number.toString();
176
- if (this.decimal) {
177
- let isNegative = false;
178
- if (string.charAt(0) === "-") {
179
- string = string.substring(1);
180
- isNegative = true;
181
- }
182
- string = string.padStart(string.length + this.decimal, "0");
183
- string = `${string.slice(0, -this.decimal)}.${string.slice(-this.decimal)}`;
184
- string = removeLeadingZeros(string);
185
- return (isNegative ? "-" : "") + string;
186
- }
187
- return string;
188
- }
189
- lessThan(thatBigNumber) {
190
- const [thisNumber, thatNumber] = this.adjustComparisonNumbers(thatBigNumber);
191
- return thisNumber < thatNumber;
192
- }
193
- biggerThan(thatBigNumber) {
194
- const [thisNumber, thatNumber] = this.adjustComparisonNumbers(thatBigNumber);
195
- return thisNumber > thatNumber;
196
- }
197
- isEqual(thatBigNumber) {
198
- const [thisNumber, thatNumber] = this.adjustComparisonNumbers(thatBigNumber);
199
- return thisNumber === thatNumber;
200
- }
201
- setupString(number) {
202
- number = removeLeadingZeros(number);
203
- if (isValidInteger(number)) {
204
- this.number = BigInt(number);
205
- } else if (isValidFloat(number)) {
206
- this.decimal = guessFloatPrecision(number);
207
- this.number = BigInt(number.replace(".", ""));
208
- } else {
209
- throw new Error(`BigNumber has received and invalid format for the constructor: ${number}`);
210
- }
211
- }
212
- adjustComparisonNumbers(thatNumberParam) {
213
- let thatNumber;
214
- if (thatNumberParam.constructor.name !== "BigNumber") {
215
- thatNumber = new BigNumber(thatNumberParam);
216
- } else {
217
- thatNumber = thatNumberParam;
218
- }
219
- const diff = this.getDecimalPrecision() - thatNumber.getDecimalPrecision();
220
- let thisNum = this.getNumber();
221
- let thatNum = thatNumber.getNumber();
222
- if (diff > 0) {
223
- thatNum = thatNumber.getNumber() * 10n ** BigInt(diff);
224
- } else if (diff < 0) {
225
- thisNum = this.getNumber() * 10n ** BigInt(diff * -1);
226
- }
227
- return [thisNum, thatNum];
228
- }
229
- }
230
- function format(input, opt = defaults, caller = "") {
231
- debug(opt, "utils format() - caller", caller);
232
- debug(opt, "utils format() - input1", input);
233
- if (input === null || input === void 0) {
234
- input = "";
235
- } else if (typeof input === "number") {
236
- if (opt.shouldRound) {
237
- input = input.toFixed(fixed(opt.precision));
238
- } else {
239
- input = input.toFixed(fixed(opt.precision) + 1).slice(0, -1);
240
- }
241
- } else if (opt.modelModifiers && opt.modelModifiers.number && isValidInteger(input)) {
242
- input = Number(input).toFixed(fixed(opt.precision));
243
- }
244
- debug(opt, "utils format() - input2", input);
245
- const negative = opt.disableNegative ? "" : input.indexOf("-") >= 0 ? "-" : "";
246
- let filtered = input.replace(opt.prefix, "").replace(opt.suffix, "");
247
- debug(opt, "utils format() - filtered", filtered);
248
- if (!opt.precision && opt.thousands !== "." && isValidFloat(filtered)) {
249
- filtered = round(filtered, 0);
250
- debug(opt, "utils format() - !opt.precision && isValidFloat()", filtered);
251
- }
252
- const numbers = onlyNumbers(filtered);
253
- debug(opt, "utils format() - numbers", numbers);
254
- debug(opt, "utils format() - numbersToCurrency", negative + numbersToCurrency(numbers, opt.precision));
255
- const bigNumber = new BigNumber(negative + numbersToCurrency(numbers, opt.precision));
256
- debug(opt, "utils format() - bigNumber1", bigNumber.toString());
257
- if (opt.max) {
258
- if (bigNumber.biggerThan(opt.max)) {
259
- bigNumber.setNumber(opt.max);
260
- }
261
- }
262
- if (opt.min) {
263
- if (bigNumber.lessThan(opt.min)) {
264
- bigNumber.setNumber(opt.min);
265
- }
266
- }
267
- const currency = bigNumber.toFixed(fixed(opt.precision), opt.shouldRound);
268
- debug(opt, "utils format() - bigNumber2", bigNumber.toFixed(fixed(opt.precision)));
269
- if (/^0(\.0+)?$/g.test(currency) && opt.allowBlank) {
270
- return "";
271
- }
272
- let [integer, decimal] = currency.split(".");
273
- const decimalLength = decimal !== void 0 ? decimal.length : 0;
274
- integer = integer.padStart(opt.minimumNumberOfCharacters - decimalLength, "0");
275
- integer = addThousandSeparator(integer, opt.thousands);
276
- const output = opt.prefix + joinIntegerAndDecimal(integer, decimal, opt.decimal) + opt.suffix;
277
- debug(opt, "utils format() - output", output);
278
- return output;
279
- }
280
- function unformat(input, opt = defaults, caller = "") {
281
- debug(opt, "utils unformat() - caller", caller);
282
- debug(opt, "utils unformat() - input", input);
283
- const negative = opt.disableNegative ? "" : input.indexOf("-") >= 0 ? "-" : "";
284
- const filtered = input.replace(opt.prefix, "").replace(opt.suffix, "");
285
- debug(opt, "utils unformat() - filtered", filtered);
286
- const numbers = onlyNumbers(filtered);
287
- debug(opt, "utils unformat() - numbers", numbers);
288
- const bigNumber = new BigNumber(negative + numbersToCurrency(numbers, opt.precision));
289
- debug(opt, "utils unformat() - bigNumber1", numbers.toString());
290
- if (opt.max) {
291
- if (bigNumber.biggerThan(opt.max)) {
292
- bigNumber.setNumber(opt.max);
293
- }
294
- }
295
- if (opt.min) {
296
- if (bigNumber.lessThan(opt.min)) {
297
- bigNumber.setNumber(opt.min);
298
- }
299
- }
300
- let output = bigNumber.toFixed(fixed(opt.precision), opt.shouldRound);
301
- if (opt.modelModifiers && opt.modelModifiers.number) {
302
- output = parseFloat(output);
303
- }
304
- debug(opt, "utils unformat() - output", output);
305
- return output;
306
- }
307
- const setValue = (el, opt, caller) => {
308
- debug(opt, "directive setValue() - caller", caller);
309
- if (!validateRestrictedOptions(opt)) {
310
- debug(opt, "directive setValue() - validateRestrictedOptions() return false. Stopping here...", el.value);
311
- return;
312
- }
313
- let positionFromEnd = el.value.length - (el.selectionEnd || 0);
314
- el.value = format(el.value, opt, caller);
315
- positionFromEnd = Math.max(positionFromEnd, opt.suffix.length);
316
- positionFromEnd = el.value.length - positionFromEnd;
317
- positionFromEnd = Math.max(positionFromEnd, opt.prefix.length);
318
- setCursor(el, positionFromEnd);
319
- el.dispatchEvent(event("change"));
320
- };
321
- const onKeyDown = (e, opt) => {
322
- const el = e.currentTarget;
323
- const backspacePressed = e.code === "Backspace" || e.code === "Delete";
324
- const isAtEndPosition = el.value.length - (el.selectionEnd || 0) === 0;
325
- debug(opt, "directive onkeydown() - el.value", el.value);
326
- debug(opt, "directive onkeydown() - backspacePressed", backspacePressed);
327
- debug(opt, "directive onkeydown() - isAtEndPosition", isAtEndPosition);
328
- if (opt.allowBlank && backspacePressed && isAtEndPosition && unformat(el.value, opt, "directive onkeydown allowBlank") === 0) {
329
- debug(opt, 'directive onkeydown() - set el.value = ""', el.value);
330
- el.value = "";
331
- el.dispatchEvent(event("change"));
332
- }
333
- debug(opt, "directive onkeydown() - e.key", e.key);
334
- if (e.key === "+") {
335
- debug(opt, "directive onkeydown() - unformat el.value", el.value);
336
- let number = unformat(el.value, opt, "directive onkeydown +");
337
- if (typeof number === "string") {
338
- number = parseFloat(number);
339
- }
340
- if (number < 0) {
341
- el.value = String(number * -1);
342
- }
343
- }
344
- };
345
- const onInput = (e, opt) => {
346
- const el = e.currentTarget;
347
- debug(opt, "directive oninput()", el.value);
348
- if (/^[1-9]$/.test(el.value)) {
349
- el.value = numbersToCurrency(el.value, fixed(opt.precision));
350
- debug(opt, "directive oninput() - is 1-9", el.value);
351
- }
352
- setValue(el, opt, "directive oninput");
353
- };
354
- var Money3Directive = {
355
- mounted(el, binding) {
356
- if (!binding.value) {
357
- return;
358
- }
359
- const opt = filterOptRestrictions({ ...defaults, ...binding.value });
360
- debug(opt, "directive mounted() - opt", opt);
361
- if (el.tagName.toLocaleUpperCase() !== "INPUT") {
362
- const els = el.getElementsByTagName("input");
363
- if (els.length !== 1)
364
- ;
365
- else {
366
- el = els[0];
367
- }
368
- }
369
- el.onkeydown = (e) => {
370
- onKeyDown(e, opt);
371
- };
372
- el.oninput = (e) => {
373
- onInput(e, opt);
374
- };
375
- debug(opt, "directive mounted() - el.value", el.value);
376
- setValue(el, opt, "directive mounted");
377
- },
378
- updated(el, binding) {
379
- if (!binding.value) {
380
- return;
381
- }
382
- const opt = filterOptRestrictions({ ...defaults, ...binding.value });
383
- el.onkeydown = (e) => {
384
- onKeyDown(e, opt);
385
- };
386
- el.oninput = (e) => {
387
- onInput(e, opt);
388
- };
389
- debug(opt, "directive updated() - el.value", el.value);
390
- debug(opt, "directive updated() - opt", opt);
391
- setValue(el, opt, "directive updated");
392
- },
393
- beforeUnmount(el) {
394
- el.onkeydown = null;
395
- el.oninput = null;
396
- el.onfocus = null;
397
- }
398
- };
399
- const _hoisted_1 = ["id", "value", "disabled"];
400
- const __default__ = {
401
- inheritAttrs: false,
402
- name: "Money3",
403
- directives: {
404
- money3: Money3Directive
405
- }
406
- };
407
- const _sfc_main = /* @__PURE__ */ defineComponent({
408
- ...__default__,
409
- props: {
410
- debug: {
411
- required: false,
412
- type: Boolean,
413
- default: false
414
- },
415
- id: {
416
- required: false,
417
- type: [Number, String],
418
- default: () => {
419
- const instante = getCurrentInstance();
420
- if (instante) {
421
- return instante.uid;
422
- }
423
- return null;
424
- }
425
- },
426
- modelValue: {
427
- required: true,
428
- type: [Number, String]
429
- },
430
- modelModifiers: {
431
- required: false,
432
- type: Object,
433
- default: () => ({ number: false })
434
- },
435
- masked: {
436
- type: Boolean,
437
- default: false
438
- },
439
- precision: {
440
- type: Number,
441
- default: () => defaults.precision
442
- },
443
- decimal: {
444
- type: String,
445
- default: () => defaults.decimal,
446
- validator(value) {
447
- return validateRestrictedInput(value, "decimal");
448
- }
449
- },
450
- thousands: {
451
- type: String,
452
- default: () => defaults.thousands,
453
- validator(value) {
454
- return validateRestrictedInput(value, "thousands");
455
- }
456
- },
457
- prefix: {
458
- type: String,
459
- default: () => defaults.prefix,
460
- validator(value) {
461
- return validateRestrictedInput(value, "prefix");
462
- }
463
- },
464
- suffix: {
465
- type: String,
466
- default: () => defaults.suffix,
467
- validator(value) {
468
- return validateRestrictedInput(value, "suffix");
469
- }
470
- },
471
- disableNegative: {
472
- type: Boolean,
473
- default: false
474
- },
475
- disabled: {
476
- type: Boolean,
477
- default: false
478
- },
479
- max: {
480
- type: [Number, String],
481
- default: () => defaults.max
482
- },
483
- min: {
484
- type: [Number, String],
485
- default: () => defaults.min
486
- },
487
- allowBlank: {
488
- type: Boolean,
489
- default: () => defaults.allowBlank
490
- },
491
- minimumNumberOfCharacters: {
492
- type: Number,
493
- default: () => defaults.minimumNumberOfCharacters
494
- },
495
- shouldRound: {
496
- type: Boolean,
497
- default: () => defaults.shouldRound
498
- }
499
- },
500
- emits: ["update:model-value"],
501
- setup(__props, { emit }) {
502
- const props = __props;
503
- const { modelValue, modelModifiers, masked, precision, shouldRound } = toRefs(props);
504
- debug(props, "component setup()", props);
505
- let value = modelValue.value;
506
- if (modelModifiers.value && modelModifiers.value.number) {
507
- if (shouldRound.value) {
508
- value = Number(modelValue.value).toFixed(fixed(precision.value));
509
- } else {
510
- value = Number(modelValue.value).toFixed(fixed(precision.value) + 1).slice(0, -1);
511
- }
512
- }
513
- const formattedValue = ref(format(value, props, "component setup"));
514
- debug(props, "component setup() - data.formattedValue", formattedValue.value);
515
- watch(modelValue, modelValueWatcher);
516
- function modelValueWatcher(value2) {
517
- debug(props, "component watch() -> value", value2);
518
- const formatted = format(value2, filterOptRestrictions({ ...props }), "component watch");
519
- if (formatted !== formattedValue.value) {
520
- debug(props, "component watch() changed -> formatted", formatted);
521
- formattedValue.value = formatted;
522
- }
523
- }
524
- let lastValue = null;
525
- function change(evt) {
526
- let value2 = evt.target?.value;
527
- debug(props, "component change() -> evt.target.value", value2);
528
- if (!(masked.value && !modelModifiers.value.number)) {
529
- value2 = unformat(value2, filterOptRestrictions({ ...props }), "component change");
530
- }
531
- if (value2 !== lastValue) {
532
- lastValue = value2;
533
- debug(props, "component change() -> update:model-value", value2);
534
- emit("update:model-value", value2);
535
- }
536
- }
537
- const attrs = useAttrs();
538
- const listeners = computed(() => {
539
- const payload = {
540
- ...attrs
541
- };
542
- delete payload["onUpdate:modelValue"];
543
- return payload;
544
- });
545
- return (_ctx, _cache) => {
546
- const _directive_money3 = resolveDirective("money3");
547
- return withDirectives((openBlock(), createElementBlock("input", mergeProps({
548
- id: `${__props.id}`
549
- }, unref(listeners), {
550
- type: "tel",
551
- class: "v-money3",
552
- value: formattedValue.value,
553
- disabled: props.disabled,
554
- onChange: change
555
- }), null, 16, _hoisted_1)), [
556
- [_directive_money3, {
557
- precision: unref(precision),
558
- decimal: props.decimal,
559
- thousands: props.thousands,
560
- prefix: props.prefix,
561
- suffix: props.suffix,
562
- disableNegative: props.disableNegative,
563
- min: props.min,
564
- max: props.max,
565
- allowBlank: props.allowBlank,
566
- minimumNumberOfCharacters: props.minimumNumberOfCharacters,
567
- debug: props.debug,
568
- modelModifiers: unref(modelModifiers),
569
- shouldRound: unref(shouldRound)
570
- }]
571
- ]);
572
- };
573
- }
574
- });
575
- var index = {
576
- install(app) {
577
- app.component("money3", _sfc_main);
578
- app.directive("money3", Money3Directive);
579
- }
580
- };
581
- export { BigNumber, _sfc_main as Money, _sfc_main as Money3, _sfc_main as Money3Component, Money3Directive, Money3Directive as VMoney, Money3Directive as VMoney3, index as default, format, unformat };