v-money3 3.20.1 → 3.22.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 +1 -1
- package/dist/BigNumber.d.ts +17 -0
- package/dist/Utils.d.ts +20 -0
- package/dist/component.vue.d.ts +179 -0
- package/dist/directive.d.ts +7 -0
- package/dist/format.d.ts +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/options.d.ts +20 -0
- package/dist/unformat.d.ts +2 -0
- package/dist/v-money3.mjs +417 -0
- package/dist/v-money3.umd.js +1 -1
- package/package.json +33 -27
- package/dist/v-money3.es.js +0 -1
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.
|
|
264
|
+
<script src="https://unpkg.com/v-money3@3.22.0/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.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare type NumberParam = bigint | number | string;
|
|
2
|
+
export default class BigNumber {
|
|
3
|
+
private number;
|
|
4
|
+
private decimal;
|
|
5
|
+
constructor(number: NumberParam);
|
|
6
|
+
getNumber(): bigint;
|
|
7
|
+
getDecimalPrecision(): number;
|
|
8
|
+
setNumber(number: NumberParam): void;
|
|
9
|
+
toFixed(precision?: number, shouldRound?: boolean): string;
|
|
10
|
+
toString(): string;
|
|
11
|
+
lessThan(thatBigNumber: NumberParam | BigNumber): boolean;
|
|
12
|
+
biggerThan(thatBigNumber: NumberParam | BigNumber): boolean;
|
|
13
|
+
isEqual(thatBigNumber: NumberParam | BigNumber): boolean;
|
|
14
|
+
setupString(number: string): void;
|
|
15
|
+
adjustComparisonNumbers(thatNumberParam: NumberParam | BigNumber): bigint[];
|
|
16
|
+
}
|
|
17
|
+
export {};
|
package/dist/Utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VMoneyOptions } from './options';
|
|
2
|
+
export declare const RESTRICTED_CHARACTERS: string[];
|
|
3
|
+
export declare const RESTRICTED_OPTIONS: string[];
|
|
4
|
+
export declare function fixed(precision: number): number;
|
|
5
|
+
export declare function numbersToCurrency(numbers: string, precision: number): string;
|
|
6
|
+
export declare function onlyNumbers(input: number | string): string;
|
|
7
|
+
export declare function addThousandSeparator(integer: string, separator: string): string;
|
|
8
|
+
export declare function joinIntegerAndDecimal(integer: string, decimal: string, separator: string): string;
|
|
9
|
+
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;
|
|
12
|
+
export declare function guessFloatPrecision(string: string): number;
|
|
13
|
+
export declare function removeLeadingZeros(string: string): string;
|
|
14
|
+
export declare function isValidInteger(str: string): boolean;
|
|
15
|
+
export declare function isValidFloat(str: string): boolean;
|
|
16
|
+
export declare function replaceAt(str: string, index: number, chr: string | number): string;
|
|
17
|
+
export declare function round(string: string, precision: number): string;
|
|
18
|
+
export declare function setCursor(el: HTMLInputElement, position: number): void;
|
|
19
|
+
export declare function event(name: string): Event;
|
|
20
|
+
export declare function debug({ debug }: VMoneyOptions, ...args: any): void;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{
|
|
2
|
+
debug: {
|
|
3
|
+
required: false;
|
|
4
|
+
type: BooleanConstructor;
|
|
5
|
+
default: boolean;
|
|
6
|
+
};
|
|
7
|
+
id: {
|
|
8
|
+
required: false;
|
|
9
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
10
|
+
default: () => number | null;
|
|
11
|
+
};
|
|
12
|
+
modelValue: {
|
|
13
|
+
required: true;
|
|
14
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
15
|
+
};
|
|
16
|
+
modelModifiers: {
|
|
17
|
+
required: false;
|
|
18
|
+
type: ObjectConstructor;
|
|
19
|
+
default: () => {
|
|
20
|
+
number: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
masked: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
default: boolean;
|
|
26
|
+
};
|
|
27
|
+
precision: {
|
|
28
|
+
type: NumberConstructor;
|
|
29
|
+
default: () => number;
|
|
30
|
+
};
|
|
31
|
+
decimal: {
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
default: () => string;
|
|
34
|
+
validator(value: string): boolean;
|
|
35
|
+
};
|
|
36
|
+
thousands: {
|
|
37
|
+
type: StringConstructor;
|
|
38
|
+
default: () => string;
|
|
39
|
+
validator(value: string): boolean;
|
|
40
|
+
};
|
|
41
|
+
prefix: {
|
|
42
|
+
type: StringConstructor;
|
|
43
|
+
default: () => string;
|
|
44
|
+
validator(value: string): boolean;
|
|
45
|
+
};
|
|
46
|
+
suffix: {
|
|
47
|
+
type: StringConstructor;
|
|
48
|
+
default: () => string;
|
|
49
|
+
validator(value: string): boolean;
|
|
50
|
+
};
|
|
51
|
+
disableNegative: {
|
|
52
|
+
type: BooleanConstructor;
|
|
53
|
+
default: boolean;
|
|
54
|
+
};
|
|
55
|
+
disabled: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
default: boolean;
|
|
58
|
+
};
|
|
59
|
+
max: {
|
|
60
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
61
|
+
default: () => string | number | null;
|
|
62
|
+
};
|
|
63
|
+
min: {
|
|
64
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
65
|
+
default: () => string | number | null;
|
|
66
|
+
};
|
|
67
|
+
allowBlank: {
|
|
68
|
+
type: BooleanConstructor;
|
|
69
|
+
default: () => boolean;
|
|
70
|
+
};
|
|
71
|
+
minimumNumberOfCharacters: {
|
|
72
|
+
type: NumberConstructor;
|
|
73
|
+
default: () => number;
|
|
74
|
+
};
|
|
75
|
+
shouldRound: {
|
|
76
|
+
type: BooleanConstructor;
|
|
77
|
+
default: () => boolean;
|
|
78
|
+
};
|
|
79
|
+
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
80
|
+
"update:model-value": (value: string | number) => void;
|
|
81
|
+
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
82
|
+
debug: {
|
|
83
|
+
required: false;
|
|
84
|
+
type: BooleanConstructor;
|
|
85
|
+
default: boolean;
|
|
86
|
+
};
|
|
87
|
+
id: {
|
|
88
|
+
required: false;
|
|
89
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
90
|
+
default: () => number | null;
|
|
91
|
+
};
|
|
92
|
+
modelValue: {
|
|
93
|
+
required: true;
|
|
94
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
95
|
+
};
|
|
96
|
+
modelModifiers: {
|
|
97
|
+
required: false;
|
|
98
|
+
type: ObjectConstructor;
|
|
99
|
+
default: () => {
|
|
100
|
+
number: boolean;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
masked: {
|
|
104
|
+
type: BooleanConstructor;
|
|
105
|
+
default: boolean;
|
|
106
|
+
};
|
|
107
|
+
precision: {
|
|
108
|
+
type: NumberConstructor;
|
|
109
|
+
default: () => number;
|
|
110
|
+
};
|
|
111
|
+
decimal: {
|
|
112
|
+
type: StringConstructor;
|
|
113
|
+
default: () => string;
|
|
114
|
+
validator(value: string): boolean;
|
|
115
|
+
};
|
|
116
|
+
thousands: {
|
|
117
|
+
type: StringConstructor;
|
|
118
|
+
default: () => string;
|
|
119
|
+
validator(value: string): boolean;
|
|
120
|
+
};
|
|
121
|
+
prefix: {
|
|
122
|
+
type: StringConstructor;
|
|
123
|
+
default: () => string;
|
|
124
|
+
validator(value: string): boolean;
|
|
125
|
+
};
|
|
126
|
+
suffix: {
|
|
127
|
+
type: StringConstructor;
|
|
128
|
+
default: () => string;
|
|
129
|
+
validator(value: string): boolean;
|
|
130
|
+
};
|
|
131
|
+
disableNegative: {
|
|
132
|
+
type: BooleanConstructor;
|
|
133
|
+
default: boolean;
|
|
134
|
+
};
|
|
135
|
+
disabled: {
|
|
136
|
+
type: BooleanConstructor;
|
|
137
|
+
default: boolean;
|
|
138
|
+
};
|
|
139
|
+
max: {
|
|
140
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
141
|
+
default: () => string | number | null;
|
|
142
|
+
};
|
|
143
|
+
min: {
|
|
144
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
145
|
+
default: () => string | number | null;
|
|
146
|
+
};
|
|
147
|
+
allowBlank: {
|
|
148
|
+
type: BooleanConstructor;
|
|
149
|
+
default: () => boolean;
|
|
150
|
+
};
|
|
151
|
+
minimumNumberOfCharacters: {
|
|
152
|
+
type: NumberConstructor;
|
|
153
|
+
default: () => number;
|
|
154
|
+
};
|
|
155
|
+
shouldRound: {
|
|
156
|
+
type: BooleanConstructor;
|
|
157
|
+
default: () => boolean;
|
|
158
|
+
};
|
|
159
|
+
}>> & {
|
|
160
|
+
"onUpdate:model-value"?: ((value: string | number) => any) | undefined;
|
|
161
|
+
}, {
|
|
162
|
+
debug: boolean;
|
|
163
|
+
masked: boolean;
|
|
164
|
+
prefix: string;
|
|
165
|
+
suffix: string;
|
|
166
|
+
thousands: string;
|
|
167
|
+
decimal: string;
|
|
168
|
+
precision: number;
|
|
169
|
+
disableNegative: boolean;
|
|
170
|
+
disabled: boolean;
|
|
171
|
+
min: string | number;
|
|
172
|
+
max: string | number;
|
|
173
|
+
allowBlank: boolean;
|
|
174
|
+
minimumNumberOfCharacters: number;
|
|
175
|
+
modelModifiers: Record<string, any>;
|
|
176
|
+
shouldRound: boolean;
|
|
177
|
+
id: string | number;
|
|
178
|
+
}>;
|
|
179
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DirectiveBinding } from 'vue';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
mounted(el: HTMLInputElement, binding: DirectiveBinding): void;
|
|
4
|
+
updated(el: HTMLInputElement, binding: DirectiveBinding): void;
|
|
5
|
+
beforeUnmount(el: HTMLInputElement): void;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
package/dist/format.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import Money3Component from './component.vue';
|
|
3
|
+
import Money3Directive from './directive';
|
|
4
|
+
import format from './format';
|
|
5
|
+
import { VMoneyOptions } from './options';
|
|
6
|
+
import unformat from './unformat';
|
|
7
|
+
import BigNumber from './BigNumber';
|
|
8
|
+
declare const _default: {
|
|
9
|
+
install(app: App): void;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
export type { VMoneyOptions, };
|
|
13
|
+
export { Money3Component, Money3Directive, format, unformat, BigNumber, Money3Component as Money3, Money3Directive as VMoney3, Money3Component as Money, Money3Directive as VMoney, };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface VMoneyOptions {
|
|
2
|
+
debug: boolean;
|
|
3
|
+
masked: boolean;
|
|
4
|
+
prefix: string;
|
|
5
|
+
suffix: string;
|
|
6
|
+
thousands: string;
|
|
7
|
+
decimal: string;
|
|
8
|
+
precision: number;
|
|
9
|
+
disableNegative: boolean;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
min: number | string | null;
|
|
12
|
+
max: number | string | null;
|
|
13
|
+
allowBlank: boolean;
|
|
14
|
+
minimumNumberOfCharacters: number;
|
|
15
|
+
modelModifiers: any;
|
|
16
|
+
shouldRound: boolean;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
declare const _default: VMoneyOptions;
|
|
20
|
+
export default _default;
|
|
@@ -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
|
+
};
|
package/dist/v-money3.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty,__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__publicField=(e,t,n)=>(__defNormalProp(e,"symbol"!=typeof t?t+"":t,n),n);!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["v-money3"]={},e.Vue)}(this,(function(e,t){"use strict";var n={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};const i=["+","-"],r=["decimal","thousands","prefix","suffix"];function o(e){return Math.max(0,Math.min(e,1e3))}function u(e,t){return e=e.padStart(t+1,"0"),0===t?e:`${e.slice(0,-t)}.${e.slice(-t)}`}function a(e){return(e=e?e.toString():"").replace(/\D+/g,"")||"0"}function l(e,t){return i.includes(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`),!1):!/\d/g.test(e)||(console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`),!1)}function s(e){for(const t of r){e[t]=e[t].replace(/\d+/g,"");for(const n of i)e[t]=e[t].replaceAll(n,"")}return e}function d(e){return e.length-(e.indexOf(".")+1)}function c(e){return e.replace(/^(-?)0+(?!\.)(.+)/,"$1$2")}function m(e){return/^-?[\d]+$/g.test(e)}function f(e){return/^-?[\d]+(\.[\d]+)$/g.test(e)}function p(e,t,n){return t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1)}function v(e,t){const n=t-d(e);if(n>=0)return e;let i=e.slice(0,n);const r=e.slice(n);if("."===i.charAt(i.length-1)&&(i=i.slice(0,-1)),parseInt(r.charAt(0),10)>=5){for(let e=i.length-1;e>=0;e-=1){const t=i.charAt(e);if("."!==t&&"-"!==t){const n=parseInt(t,10)+1;if(n<10)return p(i,e,n);i=p(i,e,"0")}}return`1${i}`}return i}function g(e){return new Event(e,{bubbles:!0,cancelable:!1})}function b({debug:e=!1},...t){e&&console.log(...t)}class h{constructor(e){__publicField(this,"number",0n),__publicField(this,"decimal",0),this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,"bigint"==typeof e?this.number=e:"number"==typeof e?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,t=!0){let n=this.toString();const i=e-this.getDecimalPrecision();return i>0?(n.includes(".")||(n+="."),n.padEnd(n.length+i,"0")):i<0?t?v(n,e):n.slice(0,i):n}toString(){let e=this.number.toString();if(this.decimal){let t=!1;return"-"===e.charAt(0)&&(e=e.substring(1),t=!0),e=e.padStart(e.length+this.decimal,"0"),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=c(e),(t?"-":"")+e}return e}lessThan(e){const[t,n]=this.adjustComparisonNumbers(e);return t<n}biggerThan(e){const[t,n]=this.adjustComparisonNumbers(e);return t>n}isEqual(e){const[t,n]=this.adjustComparisonNumbers(e);return t===n}setupString(e){if(m(e=c(e)))this.number=BigInt(e);else{if(!f(e))throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`);this.decimal=d(e),this.number=BigInt(e.replace(".",""))}}adjustComparisonNumbers(e){let t;t="BigNumber"!==e.constructor.name?new h(e):e;const n=this.getDecimalPrecision()-t.getDecimalPrecision();let i=this.getNumber(),r=t.getNumber();return n>0?r=t.getNumber()*10n**BigInt(n):n<0&&(i=this.getNumber()*10n**BigInt(-1*n)),[i,r]}}function y(e,t=n,i=""){b(t,"utils format() - caller",i),b(t,"utils format() - input1",e),null==e?e="":"number"==typeof e?e=t.shouldRound?e.toFixed(o(t.precision)):e.toFixed(o(t.precision)+1).slice(0,-1):t.modelModifiers&&t.modelModifiers.number&&m(e)&&(e=Number(e).toFixed(o(t.precision))),b(t,"utils format() - input2",e);const r=t.disableNegative?"":e.indexOf("-")>=0?"-":"";let l=e.replace(t.prefix,"").replace(t.suffix,"");b(t,"utils format() - filtered",l),!t.precision&&"."!==t.thousands&&f(l)&&(l=v(l,0),b(t,"utils format() - !opt.precision && isValidFloat()",l));const s=a(l);b(t,"utils format() - numbers",s),b(t,"utils format() - numbersToCurrency",r+u(s,t.precision));const d=new h(r+u(s,t.precision));b(t,"utils format() - bigNumber1",d.toString()),t.max&&d.biggerThan(t.max)&&d.setNumber(t.max),t.min&&d.lessThan(t.min)&&d.setNumber(t.min);const c=d.toFixed(o(t.precision),t.shouldRound);if(b(t,"utils format() - bigNumber2",d.toFixed(o(t.precision))),/^0(\.0+)?$/g.test(c)&&t.allowBlank)return"";let[p,g]=c.split(".");const y=void 0!==g?g.length:0;p=p.padStart(t.minimumNumberOfCharacters-y,"0"),p=function(e,t){return e.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${t}`)}(p,t.thousands);const x=t.prefix+function(e,t,n){return t?e+n+t:e}(p,g,t.decimal)+t.suffix;return b(t,"utils format() - output",x),x}function x(e,t=n,i=""){b(t,"utils unformat() - caller",i),b(t,"utils unformat() - input",e);const r=t.disableNegative?"":e.indexOf("-")>=0?"-":"",l=e.replace(t.prefix,"").replace(t.suffix,"");b(t,"utils unformat() - filtered",l);const s=a(l);b(t,"utils unformat() - numbers",s);const d=new h(r+u(s,t.precision));b(t,"utils unformat() - bigNumber1",s.toString()),t.max&&d.biggerThan(t.max)&&d.setNumber(t.max),t.min&&d.lessThan(t.min)&&d.setNumber(t.min);let c=d.toFixed(o(t.precision),t.shouldRound);return t.modelModifiers&&t.modelModifiers.number&&(c=parseFloat(c)),b(t,"utils unformat() - output",c),c}const N=(e,t,n)=>{if(b(t,"directive setValue() - caller",n),!function(e){for(const t of r)if(!l(e[t],t))return!1;return!0}(t))return void b(t,"directive setValue() - validateRestrictedOptions() return false. Stopping here...",e.value);let i=e.value.length-(e.selectionEnd||0);e.value=y(e.value,t,n),i=Math.max(i,t.suffix.length),i=e.value.length-i,i=Math.max(i,t.prefix.length),function(e,t){const n=()=>{e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}(e,i),e.dispatchEvent(g("change"))},w=(e,t)=>{const n=e.currentTarget,i="Backspace"===e.code||"Delete"===e.code,r=n.value.length-(n.selectionEnd||0)==0;if(b(t,"directive onkeydown() - el.value",n.value),b(t,"directive onkeydown() - backspacePressed",i),b(t,"directive onkeydown() - isAtEndPosition",r),t.allowBlank&&i&&r&&0===x(n.value,t,"directive onkeydown allowBlank")&&(b(t,'directive onkeydown() - set el.value = ""',n.value),n.value="",n.dispatchEvent(g("change"))),b(t,"directive onkeydown() - e.key",e.key),"+"===e.key){b(t,"directive onkeydown() - unformat el.value",n.value);let e=x(n.value,t,"directive onkeydown +");"string"==typeof e&&(e=parseFloat(e)),e<0&&(n.value=String(-1*e))}},k=(e,t)=>{const n=e.currentTarget;b(t,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=u(n.value,o(t.precision)),b(t,"directive oninput() - is 1-9",n.value)),N(n,t,"directive oninput")};var S={mounted(e,t){if(!t.value)return;const i=s({...n,...t.value});if(b(i,"directive mounted() - opt",i),"INPUT"!==e.tagName.toLocaleUpperCase()){const t=e.getElementsByTagName("input");1!==t.length||(e=t[0])}e.onkeydown=e=>{w(e,i)},e.oninput=e=>{k(e,i)},b(i,"directive mounted() - el.value",e.value),N(e,i,"directive mounted")},updated(e,t){if(!t.value)return;const i=s({...n,...t.value});e.onkeydown=e=>{w(e,i)},e.oninput=e=>{k(e,i)},b(i,"directive updated() - el.value",e.value),b(i,"directive updated() - opt",i),N(e,i,"directive updated")},beforeUnmount(e){e.onkeydown=null,e.oninput=null,e.onfocus=null}};const B=["id","value","disabled"];const M={inheritAttrs:!1,name:"Money3",directives:{money3:S}},$=t.defineComponent({...M,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{const e=t.getCurrentInstance();return e?e.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:()=>n.precision},decimal:{type:String,default:()=>n.decimal,validator:e=>l(e,"decimal")},thousands:{type:String,default:()=>n.thousands,validator:e=>l(e,"thousands")},prefix:{type:String,default:()=>n.prefix,validator:e=>l(e,"prefix")},suffix:{type:String,default:()=>n.suffix,validator:e=>l(e,"suffix")},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>n.max},min:{type:[Number,String],default:()=>n.min},allowBlank:{type:Boolean,default:()=>n.allowBlank},minimumNumberOfCharacters:{type:Number,default:()=>n.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>n.shouldRound}},emits:["update:model-value"],setup:function(e,{emit:n}){const i=e,{modelValue:r,modelModifiers:u,masked:a,precision:l,shouldRound:d}=t.toRefs(i);b(i,"component setup()",i);let c=r.value;u.value&&u.value.number&&(c=d.value?Number(r.value).toFixed(o(l.value)):Number(r.value).toFixed(o(l.value)+1).slice(0,-1));const m=t.ref(y(c,i,"component setup"));b(i,"component setup() - data.formattedValue",m.value),t.watch(r,(function(e){b(i,"component watch() -> value",e);const t=y(e,s({...i}),"component watch");t!==m.value&&(b(i,"component watch() changed -> formatted",t),m.value=t)}));let f=null;function p(e){let t;b(i,"component change() -> evt.target.value",e.target.value),t=a.value&&!u.value.number?e.target.value:x(e.target.value,s({...i}),"component change"),t!==f&&(f=t,b(i,"component change() -> update:model-value",t),n("update:model-value",t))}const v=t.useAttrs(),g=t.computed((()=>{const e={...v};return delete e["onUpdate:modelValue"],e}));return(e,n)=>{const r=t.resolveDirective("money3");return t.withDirectives((t.openBlock(),t.createElementBlock("input",t.mergeProps({id:i.id},t.unref(g),{type:"tel",class:"v-money3",value:m.value,disabled:i.disabled,onChange:p}),null,16,B)),[[r,{precision:t.unref(l),decimal:i.decimal,thousands:i.thousands,prefix:i.prefix,suffix:i.suffix,disableNegative:i.disableNegative,min:i.min,max:i.max,allowBlank:i.allowBlank,minimumNumberOfCharacters:i.minimumNumberOfCharacters,debug:i.debug,modelModifiers:t.unref(u),shouldRound:t.unref(d)}]])}}});var C={install(e){e.component("money3",$),e.directive("money3",S)}};e.BigNumber=h,e.Money=$,e.Money3=$,e.Money3Component=$,e.Money3Directive=S,e.VMoney=S,e.VMoney3=S,e.default=C,e.format=y,e.unformat=x,Object.defineProperty(e,"__esModule",{value:!0}),e[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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v-money3",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "Vue3 currency input/directive mask",
|
|
5
5
|
"main": "./dist/v-money3.umd.js",
|
|
6
6
|
"module": "./dist/v-money3.es.js",
|
|
@@ -10,14 +10,19 @@
|
|
|
10
10
|
"require": "./dist/v-money3.umd.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
+
"typings": "./dist/index.d.ts",
|
|
13
14
|
"scripts": {
|
|
14
15
|
"lint": "./node_modules/node/bin/node ./node_modules/eslint/bin/eslint.js --ext .ts,.vue ./src",
|
|
16
|
+
"dts": "vue-tsc --declaration --emitDeclarationOnly --declarationDir ./dist --removeComments false",
|
|
15
17
|
"serve": "./node_modules/node/bin/node ./node_modules/vite/bin/vite.js --host=localhost --port=3000 --open --force",
|
|
16
|
-
"build": "./node_modules/node/bin/node ./node_modules/vite/bin/vite.js build",
|
|
17
|
-
"test": "
|
|
18
|
+
"build": "./node_modules/node/bin/node ./node_modules/vite/bin/vite.js build; npm run dts",
|
|
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/",
|
|
18
22
|
"lock": "npm i --package-lock-only",
|
|
19
23
|
"pack": "npm run build; npm pack;",
|
|
20
|
-
"prepublish": "npm run build"
|
|
24
|
+
"prepublish": "npm run build",
|
|
25
|
+
"update": "export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true; npm update --verbose;"
|
|
21
26
|
},
|
|
22
27
|
"files": [
|
|
23
28
|
"dist"
|
|
@@ -44,28 +49,29 @@
|
|
|
44
49
|
"vue": ">= 3.2.0"
|
|
45
50
|
},
|
|
46
51
|
"devDependencies": {
|
|
47
|
-
"@babel/plugin-transform-runtime": "
|
|
48
|
-
"@babel/preset-env": "
|
|
49
|
-
"@types/jest": "
|
|
50
|
-
"@types/jest-environment-puppeteer": "
|
|
51
|
-
"@types/puppeteer": "5.4.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "
|
|
53
|
-
"@typescript-eslint/parser": "
|
|
54
|
-
"@vitejs/plugin-vue": "
|
|
55
|
-
"@vue/compiler-sfc": "
|
|
56
|
-
"@vue/test-utils": "
|
|
57
|
-
"babel-jest": "
|
|
58
|
-
"eslint": "
|
|
59
|
-
"eslint-config-airbnb-base": "
|
|
60
|
-
"eslint-config-airbnb-typescript": "
|
|
61
|
-
"eslint-plugin-import": "
|
|
62
|
-
"eslint-plugin-vue": "
|
|
63
|
-
"jest": "
|
|
64
|
-
"jest-puppeteer": "
|
|
65
|
-
"node": "
|
|
66
|
-
"ts-jest": "
|
|
67
|
-
"vite": "
|
|
68
|
-
"vue": "
|
|
69
|
-
"vue-jest": "
|
|
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"
|
|
70
76
|
}
|
|
71
77
|
}
|
package/dist/v-money3.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,n,i)=>(((t,n,i)=>{n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i})(t,"symbol"!=typeof n?n+"":n,i),i);import{defineComponent as n,getCurrentInstance as i,toRefs as r,ref as u,watch as o,useAttrs as a,computed as l,resolveDirective as s,withDirectives as d,openBlock as c,createElementBlock as m,mergeProps as f,unref as p}from"vue";var v={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};const g=["+","-"],b=["decimal","thousands","prefix","suffix"];function h(e){return Math.max(0,Math.min(e,1e3))}function y(e,t){return e=e.padStart(t+1,"0"),0===t?e:`${e.slice(0,-t)}.${e.slice(-t)}`}function x(e){return(e=e?e.toString():"").replace(/\D+/g,"")||"0"}function N(e,t){return g.includes(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`),!1):!/\d/g.test(e)||(console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`),!1)}function w(e){for(const t of b){e[t]=e[t].replace(/\d+/g,"");for(const n of g)e[t]=e[t].replaceAll(n,"")}return e}function k(e){return e.length-(e.indexOf(".")+1)}function S(e){return e.replace(/^(-?)0+(?!\.)(.+)/,"$1$2")}function B(e){return/^-?[\d]+$/g.test(e)}function M(e){return/^-?[\d]+(\.[\d]+)$/g.test(e)}function $(e,t,n){return t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1)}function C(e,t){const n=t-k(e);if(n>=0)return e;let i=e.slice(0,n);const r=e.slice(n);if("."===i.charAt(i.length-1)&&(i=i.slice(0,-1)),parseInt(r.charAt(0),10)>=5){for(let e=i.length-1;e>=0;e-=1){const t=i.charAt(e);if("."!==t&&"-"!==t){const n=parseInt(t,10)+1;if(n<10)return $(i,e,n);i=$(i,e,"0")}}return`1${i}`}return i}function F(e){return new Event(e,{bubbles:!0,cancelable:!1})}function O({debug:e=!1},...t){e&&console.log(...t)}class T{constructor(e){t(this,"number",0n),t(this,"decimal",0),this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,"bigint"==typeof e?this.number=e:"number"==typeof e?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,t=!0){let n=this.toString();const i=e-this.getDecimalPrecision();return i>0?(n.includes(".")||(n+="."),n.padEnd(n.length+i,"0")):i<0?t?C(n,e):n.slice(0,i):n}toString(){let e=this.number.toString();if(this.decimal){let t=!1;return"-"===e.charAt(0)&&(e=e.substring(1),t=!0),e=e.padStart(e.length+this.decimal,"0"),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=S(e),(t?"-":"")+e}return e}lessThan(e){const[t,n]=this.adjustComparisonNumbers(e);return t<n}biggerThan(e){const[t,n]=this.adjustComparisonNumbers(e);return t>n}isEqual(e){const[t,n]=this.adjustComparisonNumbers(e);return t===n}setupString(e){if(B(e=S(e)))this.number=BigInt(e);else{if(!M(e))throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`);this.decimal=k(e),this.number=BigInt(e.replace(".",""))}}adjustComparisonNumbers(e){let t;t="BigNumber"!==e.constructor.name?new T(e):e;const n=this.getDecimalPrecision()-t.getDecimalPrecision();let i=this.getNumber(),r=t.getNumber();return n>0?r=t.getNumber()*10n**BigInt(n):n<0&&(i=this.getNumber()*10n**BigInt(-1*n)),[i,r]}}function E(e,t=v,n=""){O(t,"utils format() - caller",n),O(t,"utils format() - input1",e),null==e?e="":"number"==typeof e?e=t.shouldRound?e.toFixed(h(t.precision)):e.toFixed(h(t.precision)+1).slice(0,-1):t.modelModifiers&&t.modelModifiers.number&&B(e)&&(e=Number(e).toFixed(h(t.precision))),O(t,"utils format() - input2",e);const i=t.disableNegative?"":e.indexOf("-")>=0?"-":"";let r=e.replace(t.prefix,"").replace(t.suffix,"");O(t,"utils format() - filtered",r),!t.precision&&"."!==t.thousands&&M(r)&&(r=C(r,0),O(t,"utils format() - !opt.precision && isValidFloat()",r));const u=x(r);O(t,"utils format() - numbers",u),O(t,"utils format() - numbersToCurrency",i+y(u,t.precision));const o=new T(i+y(u,t.precision));O(t,"utils format() - bigNumber1",o.toString()),t.max&&o.biggerThan(t.max)&&o.setNumber(t.max),t.min&&o.lessThan(t.min)&&o.setNumber(t.min);const a=o.toFixed(h(t.precision),t.shouldRound);if(O(t,"utils format() - bigNumber2",o.toFixed(h(t.precision))),/^0(\.0+)?$/g.test(a)&&t.allowBlank)return"";let[l,s]=a.split(".");const d=void 0!==s?s.length:0;l=l.padStart(t.minimumNumberOfCharacters-d,"0"),l=function(e,t){return e.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${t}`)}(l,t.thousands);const c=t.prefix+function(e,t,n){return t?e+n+t:e}(l,s,t.decimal)+t.suffix;return O(t,"utils format() - output",c),c}function R(e,t=v,n=""){O(t,"utils unformat() - caller",n),O(t,"utils unformat() - input",e);const i=t.disableNegative?"":e.indexOf("-")>=0?"-":"",r=e.replace(t.prefix,"").replace(t.suffix,"");O(t,"utils unformat() - filtered",r);const u=x(r);O(t,"utils unformat() - numbers",u);const o=new T(i+y(u,t.precision));O(t,"utils unformat() - bigNumber1",u.toString()),t.max&&o.biggerThan(t.max)&&o.setNumber(t.max),t.min&&o.lessThan(t.min)&&o.setNumber(t.min);let a=o.toFixed(h(t.precision),t.shouldRound);return t.modelModifiers&&t.modelModifiers.number&&(a=parseFloat(a)),O(t,"utils unformat() - output",a),a}const V=(e,t,n)=>{if(O(t,"directive setValue() - caller",n),!function(e){for(const t of b)if(!N(e[t],t))return!1;return!0}(t))return void O(t,"directive setValue() - validateRestrictedOptions() return false. Stopping here...",e.value);let i=e.value.length-(e.selectionEnd||0);e.value=E(e.value,t,n),i=Math.max(i,t.suffix.length),i=e.value.length-i,i=Math.max(i,t.prefix.length),function(e,t){const n=()=>{e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}(e,i),e.dispatchEvent(F("change"))},P=(e,t)=>{const n=e.currentTarget,i="Backspace"===e.code||"Delete"===e.code,r=n.value.length-(n.selectionEnd||0)==0;if(O(t,"directive onkeydown() - el.value",n.value),O(t,"directive onkeydown() - backspacePressed",i),O(t,"directive onkeydown() - isAtEndPosition",r),t.allowBlank&&i&&r&&0===R(n.value,t,"directive onkeydown allowBlank")&&(O(t,'directive onkeydown() - set el.value = ""',n.value),n.value="",n.dispatchEvent(F("change"))),O(t,"directive onkeydown() - e.key",e.key),"+"===e.key){O(t,"directive onkeydown() - unformat el.value",n.value);let e=R(n.value,t,"directive onkeydown +");"string"==typeof e&&(e=parseFloat(e)),e<0&&(n.value=String(-1*e))}},A=(e,t)=>{const n=e.currentTarget;O(t,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=y(n.value,h(t.precision)),O(t,"directive oninput() - is 1-9",n.value)),V(n,t,"directive oninput")};var I={mounted(e,t){if(!t.value)return;const n=w({...v,...t.value});if(O(n,"directive mounted() - opt",n),"INPUT"!==e.tagName.toLocaleUpperCase()){const t=e.getElementsByTagName("input");1!==t.length||(e=t[0])}e.onkeydown=e=>{P(e,n)},e.oninput=e=>{A(e,n)},O(n,"directive mounted() - el.value",e.value),V(e,n,"directive mounted")},updated(e,t){if(!t.value)return;const n=w({...v,...t.value});e.onkeydown=e=>{P(e,n)},e.oninput=e=>{A(e,n)},O(n,"directive updated() - el.value",e.value),O(n,"directive updated() - opt",n),V(e,n,"directive updated")},beforeUnmount(e){e.onkeydown=null,e.oninput=null,e.onfocus=null}};const j=["id","value","disabled"];const D=n({...{inheritAttrs:!1,name:"Money3",directives:{money3:I}},props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{const e=i();return e?e.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:()=>v.precision},decimal:{type:String,default:()=>v.decimal,validator:e=>N(e,"decimal")},thousands:{type:String,default:()=>v.thousands,validator:e=>N(e,"thousands")},prefix:{type:String,default:()=>v.prefix,validator:e=>N(e,"prefix")},suffix:{type:String,default:()=>v.suffix,validator:e=>N(e,"suffix")},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>v.max},min:{type:[Number,String],default:()=>v.min},allowBlank:{type:Boolean,default:()=>v.allowBlank},minimumNumberOfCharacters:{type:Number,default:()=>v.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>v.shouldRound}},emits:["update:model-value"],setup:function(e,{emit:t}){const n=e,{modelValue:i,modelModifiers:v,masked:g,precision:b,shouldRound:y}=r(n);O(n,"component setup()",n);let x=i.value;v.value&&v.value.number&&(x=y.value?Number(i.value).toFixed(h(b.value)):Number(i.value).toFixed(h(b.value)+1).slice(0,-1));const N=u(E(x,n,"component setup"));O(n,"component setup() - data.formattedValue",N.value),o(i,(function(e){O(n,"component watch() -> value",e);const t=E(e,w({...n}),"component watch");t!==N.value&&(O(n,"component watch() changed -> formatted",t),N.value=t)}));let k=null;function S(e){let i;O(n,"component change() -> evt.target.value",e.target.value),i=g.value&&!v.value.number?e.target.value:R(e.target.value,w({...n}),"component change"),i!==k&&(k=i,O(n,"component change() -> update:model-value",i),t("update:model-value",i))}const B=a(),M=l((()=>{const e={...B};return delete e["onUpdate:modelValue"],e}));return(e,t)=>{const i=s("money3");return d((c(),m("input",f({id:n.id},p(M),{type:"tel",class:"v-money3",value:N.value,disabled:n.disabled,onChange:S}),null,16,j)),[[i,{precision:p(b),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:p(v),shouldRound:p(y)}]])}}});var q={install(e){e.component("money3",D),e.directive("money3",I)}};export{T as BigNumber,D as Money,D as Money3,D as Money3Component,I as Money3Directive,I as VMoney,I as VMoney3,q as default,E as format,R as unformat};
|