|
1 |
| -<h1 align="center">SimpleMaskMoney</h1> |
2 |
| - |
3 |
| -<p align="center"> |
4 |
| - <a class="badge-align" href="https://nodei.co/npm/simple-mask-money/"> |
5 |
| - <img src="https://nodei.co/npm/simple-mask-money.png?downloads=true&downloadRank=true" alt="NPM"></a> |
6 |
| -</p> |
7 |
| - |
8 |
| -<p align="center"> |
9 |
| - <a class="badge-align" href="https://travis-ci.org/codermarcos/simple-mask-money"><img src="https://travis-ci.org/codermarcos/simple-mask-money.svg?branch=master" alt="build Status"/></a> |
10 |
| - |
11 |
| - <a class="badge-align" href="https://badge.fury.io/js/simple-mask-money"> |
12 |
| - <img src="https://badge.fury.io/js/simple-mask-money.svg" alt="npm version"></a> |
13 |
| - |
14 |
| - <a class="badge-align" href="https://www.npmjs.com/package/simple-mask-money"> |
15 |
| - <img src="https://img.shields.io/npm/dm/simple-mask-money.svg" alt="npm Downloads"></a> |
16 |
| - |
17 |
| - <a class="badge-align" href="https://www.codacy.com/app/codermarcos/simple-mask-money?utm_source=github.com&utm_medium=referral&utm_content=codermarcos/simple-mask-money&utm_campaign=Badge_Grade"> |
18 |
| - <img src="https://api.codacy.com/project/badge/Grade/ee8f87689ae749b1822499995ef8d1d2" alt="Codacy Badge"></a> |
19 |
| - |
20 |
| - <a class="badge-align" href="https://opensource.org/licenses/Apache-2.0"> |
21 |
| - <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a> |
22 |
| -</p> |
23 |
| - |
24 |
| -<p align="center"> |
25 |
| - Simple money mask developed with pure JavaScript. To run on <b>Client Side</b> and <b>Server Side</b>. |
26 |
| - <a href="https://codermarcos.github.io/simple-mask-money/">Try <b>live demo</b></a> |
27 |
| -</p> |
28 |
| - |
29 |
| -## Getting Started |
30 |
| - |
31 |
| -First, install it. |
32 |
| - |
33 |
| -```shell |
34 |
| - npm i simple-mask-money --save |
35 |
| -``` |
36 |
| - |
37 |
| -Or use direct of github release |
38 |
| - |
39 |
| -```html |
40 |
| -<script src="https://github.com/codermarcos/simple-mask-money/releases/download/<RELEASE_VERSION_HERE>/simple-mask-money.js"></script> |
41 |
| -``` |
42 |
| - |
43 |
| -> remember change **<RELEASE_VERSION_HERE>** by the [last version](https://github.com/codermarcos/simple-mask-money/releases/latest) |
44 |
| -
|
45 |
| -Read the [docs](docs/#readme) or chose your implementation: |
46 |
| - |
47 |
| -* [Javascript](examples/javascript/#readme) |
48 |
| -* [Angular](examples/angular#readme) |
49 |
| -* [React](examples/react#readme) |
50 |
| -* [Node](examples/node#readme) |
51 |
| -* [Vue](examples/vue#readme) |
52 |
| - |
53 |
| -Then, follow the example to use in your browser: |
54 |
| - |
55 |
| -```html |
56 |
| - <body> |
57 |
| - <!-- |
58 |
| - Put inputmode numeric to mobile show only numbers |
59 |
| - --> |
60 |
| - <input id="myInput" inputmode="numeric" value="0,00"> |
61 |
| - |
62 |
| - <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> |
63 |
| - <script> |
64 |
| -
|
65 |
| - // configuration |
66 |
| - const args = { |
67 |
| - allowNegative: false, |
68 |
| - negativeSignAfter: false, |
69 |
| - prefix: '', |
70 |
| - suffix: '', |
71 |
| - fixed: true, |
72 |
| - fractionDigits: 2, |
73 |
| - decimalSeparator: ',', |
74 |
| - thousandsSeparator: '.', |
75 |
| - cursor: 'move' |
76 |
| - }; |
77 |
| -
|
78 |
| - // select the element |
79 |
| - const input = SimpleMaskMoney.setMask('#myInput', args); |
80 |
| -
|
81 |
| - // This method return value of your input in format number to save in your database |
82 |
| - input.formatToNumber(); |
83 |
| -
|
84 |
| - </script> |
85 |
| - </body> |
86 |
| -``` |
87 |
| - |
88 |
| -Or if you prefer use the methods in your events |
89 |
| - |
90 |
| -```html |
91 |
| - <body> |
92 |
| - <!-- |
93 |
| - Put inputmode numeric to mobile show only numbers |
94 |
| - --> |
95 |
| - <input inputmode="numeric" value="0,00"> |
96 |
| - |
97 |
| - <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> |
98 |
| - <script> |
99 |
| - // select the element |
100 |
| - let input = document.getElementsByTagName('input')[0]; |
101 |
| -
|
102 |
| - // configuration |
103 |
| - SimpleMaskMoney.args = { |
104 |
| - allowNegative: false, |
105 |
| - negativeSignAfter: false, |
106 |
| - prefix: '', |
107 |
| - suffix: '', |
108 |
| - fixed: true, |
109 |
| - fractionDigits: 2, |
110 |
| - decimalSeparator: ',', |
111 |
| - thousandsSeparator: '.', |
112 |
| - cursor: 'move' |
113 |
| - }; |
114 |
| -
|
115 |
| - input.oninput = () => { |
116 |
| - input.value = SimpleMaskMoney.format(input.value); |
117 |
| - } |
118 |
| -
|
119 |
| - // Your send method |
120 |
| - input.onkeyup = (e) => { |
121 |
| - if (e.key !== "Enter") return; |
122 |
| - // This method return value of your input in format number to save in your database |
123 |
| - SimpleMaskMoney.formatToNumber(input.value); |
124 |
| - } |
125 |
| - </script> |
126 |
| - </body> |
127 |
| -``` |
| 1 | +<h1 align="center">SimpleMaskMoney</h1> |
| 2 | +<h3 align="center"><b>WARNING</b></h3> |
| 3 | +<h5 align="center"> |
| 4 | + if you are having problems check the version you are using. |
| 5 | + <a href="docs/#2.x.x"> |
| 6 | + The docs to old (2.x.x) version stay <b>here</b> |
| 7 | + </a> |
| 8 | +</h5> |
| 9 | +<p align="center"> |
| 10 | + <a class="badge-align" href="https://nodei.co/npm/simple-mask-money/"> |
| 11 | + <img src="https://nodei.co/npm/simple-mask-money.png?downloads=true&downloadRank=true" alt="NPM"></a> |
| 12 | +</p> |
| 13 | + |
| 14 | +<p align="center"> |
| 15 | + <a class="badge-align" href="https://travis-ci.org/codermarcos/simple-mask-money"><img src="https://travis-ci.org/codermarcos/simple-mask-money.svg?branch=master" alt="build Status"/></a> |
| 16 | + |
| 17 | + <a class="badge-align" href="https://badge.fury.io/js/simple-mask-money"> |
| 18 | + <img src="https://badge.fury.io/js/simple-mask-money.svg" alt="npm version"></a> |
| 19 | + |
| 20 | + <a class="badge-align" href="https://www.npmjs.com/package/simple-mask-money"> |
| 21 | + <img src="https://img.shields.io/npm/dm/simple-mask-money.svg" alt="npm Downloads"></a> |
| 22 | + |
| 23 | + <a class="badge-align" href="https://www.codacy.com/app/codermarcos/simple-mask-money?utm_source=github.com&utm_medium=referral&utm_content=codermarcos/simple-mask-money&utm_campaign=Badge_Grade"> |
| 24 | + <img src="https://api.codacy.com/project/badge/Grade/ee8f87689ae749b1822499995ef8d1d2" alt="Codacy Badge"></a> |
| 25 | + |
| 26 | + <a class="badge-align" href="https://opensource.org/licenses/Apache-2.0"> |
| 27 | + <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a> |
| 28 | +</p> |
| 29 | + |
| 30 | +<p align="center"> |
| 31 | + Simple money mask developed with pure JavaScript. To run on <b>Client Side</b> and <b>Server Side</b>. |
| 32 | + <a href="https://codermarcos.github.io/simple-mask-money/">Try <b>live demo</b></a> |
| 33 | +</p> |
| 34 | + |
| 35 | +## Getting Started |
| 36 | + |
| 37 | +First, install it. |
| 38 | + |
| 39 | +```shell |
| 40 | + npm i simple-mask-money --save |
| 41 | +``` |
| 42 | + |
| 43 | +Or use direct of github release |
| 44 | + |
| 45 | +```html |
| 46 | +<script src="https://github.com/codermarcos/simple-mask-money/releases/download/<RELEASE_VERSION_HERE>/simple-mask-money.js"></script> |
| 47 | +``` |
| 48 | + |
| 49 | +> remember change **<RELEASE_VERSION_HERE>** by the [last version](https://github.com/codermarcos/simple-mask-money/releases/latest) |
| 50 | +
|
| 51 | +Read the [docs](docs/#readme) or chose your implementation: |
| 52 | + |
| 53 | +* [Javascript](examples/3.x.x/javascript/#readme) |
| 54 | +* [Angular](examples/3.x.x/angular#readme) |
| 55 | +* [React](examples/3.x.x/react#readme) |
| 56 | +* [Node](examples/3.x.x/node#readme) |
| 57 | +* [Vue](examples/3.x.x/vue#readme) |
| 58 | + |
| 59 | +Then, follow the example to use in your browser: |
| 60 | + |
| 61 | +```html |
| 62 | + <body> |
| 63 | + <!-- |
| 64 | + Put inputmode numeric to mobile show only numbers |
| 65 | + --> |
| 66 | + <input id="myInput" inputmode="numeric" value="0,00"> |
| 67 | + |
| 68 | + <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> |
| 69 | + <script> |
| 70 | +
|
| 71 | + // configuration |
| 72 | + const args = { |
| 73 | + afterFormat(e) { console.log('afterFormat', e); }, |
| 74 | + allowNegative: false, |
| 75 | + beforeFormat(e) { console.log('beforeFormat', e); }, |
| 76 | + negativeSignAfter: false, |
| 77 | + prefix: '', |
| 78 | + suffix: '', |
| 79 | + fixed: true, |
| 80 | + fractionDigits: 2, |
| 81 | + decimalSeparator: ',', |
| 82 | + thousandsSeparator: '.', |
| 83 | + cursor: 'move' |
| 84 | + }; |
| 85 | +
|
| 86 | + // select the element |
| 87 | + const input = SimpleMaskMoney.setMask('#myInput', args); |
| 88 | +
|
| 89 | + // This method return value of your input in format number to save in your database |
| 90 | + input.formatToNumber(); |
| 91 | +
|
| 92 | + </script> |
| 93 | + </body> |
| 94 | +``` |
| 95 | + |
| 96 | +Or if you prefer use the methods in your events |
| 97 | + |
| 98 | +```html |
| 99 | + <body> |
| 100 | + <!-- |
| 101 | + Put inputmode numeric to mobile show only numbers |
| 102 | + --> |
| 103 | + <input inputmode="numeric" value="0,00"> |
| 104 | + |
| 105 | + <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> |
| 106 | + <script> |
| 107 | + // select the element |
| 108 | + let input = document.getElementsByTagName('input')[0]; |
| 109 | +
|
| 110 | + // configuration |
| 111 | + SimpleMaskMoney.args = { |
| 112 | + afterFormat(e) { console.log('afterFormat', e); }, |
| 113 | + allowNegative: false, |
| 114 | + beforeFormat(e) { console.log('beforeFormat', e); }, |
| 115 | + negativeSignAfter: false, |
| 116 | + prefix: '', |
| 117 | + suffix: '', |
| 118 | + fixed: true, |
| 119 | + fractionDigits: 2, |
| 120 | + decimalSeparator: ',', |
| 121 | + thousandsSeparator: '.', |
| 122 | + cursor: 'move' |
| 123 | + }; |
| 124 | +
|
| 125 | + input.oninput = () => { |
| 126 | + input.value = SimpleMaskMoney.format(input.value); |
| 127 | + } |
| 128 | +
|
| 129 | + // Your send method |
| 130 | + input.onkeyup = (e) => { |
| 131 | + if (e.key !== "Enter") return; |
| 132 | + // This method return value of your input in format number to save in your database |
| 133 | + SimpleMaskMoney.formatToNumber(input.value); |
| 134 | + } |
| 135 | + </script> |
| 136 | + </body> |
| 137 | +``` |
0 commit comments