Skip to content

Commit 26fa8d3

Browse files
authored
Merge pull request #8 from codermarcos/bugfix/#5
Fixed bugs #5
2 parents 10f69ba + d8da6f9 commit 26fa8d3

28 files changed

+12614
-4527
lines changed

.babelrc

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"presets": ["env"]
2+
"presets": [
3+
[
4+
"es2015",
5+
{
6+
"modules": false
7+
}
8+
]
9+
]
310
}

.eslintrc.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
"extends": ["eslint:recommended"],
1111
"parserOptions": {
1212
"ecmaFeatures": {
13-
"experimentalObjectRestSpread": true,
1413
"jsx": true
1514
},
1615
"sourceType": "module"
1716
},
1817
"rules": {
1918
"indent": [
2019
"error",
21-
2
20+
2,
21+
{
22+
"SwitchCase": 1
23+
}
2224
],
2325
"linebreak-style": [
2426
"error",

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
.editorconfig
2424
.eslintrc.json
2525
.travis.yml
26+
rollup.config.js
27+
LICENSE
2628
vscode
2729
tests
2830
coverage
2931
examples
32+
docs
33+
src
3034
angularX
3135
javascript
3236
react

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![NPM](https://nodei.co/npm/simple-mask-money.png?downloads=true&downloadRank=true)](https://nodei.co/npm/simple-mask-money/)
1010

11-
Simple money mask developed with pure JavaScript. [Try **live demo**](http://simple-mask-money.codermarcos.com/)
11+
Simple money mask developed with pure JavaScript. To run on **Client Side** and **Server Side**. [Try **live demo**](http://simple-mask-money.codermarcos.com/)
1212

1313
## Getting Started
1414

@@ -23,7 +23,7 @@ First, install it.
2323
* [React](examples/react#readme)
2424
* [Vue](examples/vue#readme)
2525

26-
Then, use it as follows:
26+
Then, follow the example to use in your browser:
2727

2828
```html
2929
<body>
@@ -36,7 +36,7 @@ Then, use it as follows:
3636
<script>
3737
3838
// configuration
39-
let args = {
39+
const args = {
4040
prefix: '',
4141
suffix: '',
4242
fixed: true,
@@ -46,7 +46,7 @@ Then, use it as follows:
4646
};
4747
4848
// select the element
49-
let input = SimpleMaskMoney.setMask('#myInput', args);
49+
const input = SimpleMaskMoney.setMask('#myInput', args);
5050
5151
// This method return value of your input in format number to save in your database
5252
input.formatToNumber();

build/webpack.common.js

-37
This file was deleted.

build/webpack.dev.js

-9
This file was deleted.

build/webpack.prod.js

-9
This file was deleted.

docs/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Documentation SimpleMaskMoney
2+
3+
The ```SimpleMaskMoney``` class hosts three methods for formatting the values and one property to configure the formatting.
4+
5+
## SimpleMaskMoney.args
6+
7+
**.args** is the property, of type object that sets the formatting:
8+
9+
```javascript
10+
// Default args
11+
SimpleMaskMoney.args = {
12+
prefix: '',
13+
suffix: '',
14+
fixed: true,
15+
fractionDigits: 2,
16+
decimalSeparator: ',',
17+
thousandsSeparator: '.'
18+
};
19+
```
20+
21+
The **args** they are:
22+
23+
- **prefix**: string > *This string always precedes its value*
24+
- **suffix**: string > *This string always procedes its value*
25+
- **fixed**: boolean > *This boolean define if your value can be empty or always should have value*
26+
- **fractionDigits**: number > *This number define the quantity of decimals digits*
27+
- **decimalSeparator**: string > *This string define the separator of decimals digits*
28+
- **thousandsSeparator**: string > *This string define the separator of thousands digits*
29+
30+
## SimpleMaskMoney.format(...)
31+
32+
**.format(...)** have one argument, the ```value``` that will be formatted to your settings:
33+
34+
```javascript
35+
// With default args
36+
SimpleMaskMoney.format('123456789'); // 1.234.567,89
37+
```
38+
39+
## SimpleMaskMoney.formatToNumber(...)
40+
41+
**.formatToNumber(...)** have one argument, the ```value``` that will be formatted to number:
42+
43+
```javascript
44+
// With default args
45+
SimpleMaskMoney.format('$ 1.234.567,89'); // 1234567.89
46+
```
47+
48+
## SimpleMaskMoney.setMask(...)
49+
50+
**.setMask(...)** have two arguments, the ```input``` or ```input selector``` and ```args```.
51+
This method get the input and implements the mask with this args:
52+
53+
```html
54+
<!-- With default args -->
55+
<input type="text" inputmode="numeric" id="#myInput">
56+
```
57+
58+
Use the query selector
59+
60+
```javascript
61+
// With default args
62+
SimpleMaskMoney.setMask('#myInput', args); // 1.234.567,89
63+
```
64+
65+
Or if you prefer pass the input element
66+
67+
```javascript
68+
const element = document.getElementById('#myInput');
69+
70+
SimpleMaskMoney.setMask(element, args); // 1.234.567,89
71+
```

examples/angular/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AppComponent implements AfterViewInit {
2929

3030
ngAfterViewInit() {
3131
// configuration
32-
const options = {
32+
const args = {
3333
prefix: '',
3434
suffix: '',
3535
fixed: true,
@@ -39,7 +39,7 @@ export class AppComponent implements AfterViewInit {
3939
};
4040

4141
// set mask on your input you can pass a querySelector or your input element and options
42-
SimpleMaskMoney.setMask('#myInput', options);
42+
SimpleMaskMoney.setMask('#myInput', args);
4343
}
4444

4545
// Your send method

0 commit comments

Comments
 (0)