Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min and max value options #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Expand Up @@ -10,6 +10,7 @@
- Component or Directive flavors
- Accept copy/paste
- Editable
- Min / Max Limits

For other types of mask, use [vue-the-mask](https://vuejs-tips.github.io/vue-the-mask)

Expand Down Expand Up @@ -49,7 +50,9 @@ Vue.use(money, {precision: 4})
prefix: 'R$ ',
suffix: ' #',
precision: 2,
masked: false
masked: false,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
}
}
Expand Down Expand Up @@ -79,7 +82,9 @@ Must use `vmodel.lazy` to bind works properly.
prefix: 'R$ ',
suffix: ' #',
precision: 2,
masked: false /* doesn't work with directive */
masked: false /* doesn't work with directive */,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
}
},
Expand All @@ -91,14 +96,17 @@ Must use `vmodel.lazy` to bind works properly.

## Properties

| property | Required | Type | Default | Description |
|-----------|----------|---------|---------|---------------------------------------------------------|
| precision | **true** | Number | 2 | How many decimal places |
| decimal | false | String | "." | Decimal separator |
| thousands | false | String | "," | Thousands separator |
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
| suffix | false | String | "" | Percentage for example: " %" |
| masked | false | Boolean | false | If the component output should include the mask or not |
| property | Required | Type | Default | Description |
|-----------|----------|---------|-------------------------|---------------------------------------------------------|
| precision | **true** | Number | 2 | How many decimal places |
| precision | **true** | Number | 2 | How many decimal places |
| decimal | false | String | "." | Decimal separator |
| thousands | false | String | "," | Thousands separator |
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
| suffix | false | String | "" | Percentage for example: " %" |
| masked | false | Boolean | false | If the component output should include the mask or not |
| min | false | Number | Number.MIN_SAFE_INTEGER | The min value allowed |
| max | false | Number | Number.MAX_SAFE_INTEGER | The max value allowed |

### References

Expand Down
8 changes: 8 additions & 0 deletions src/component.vue
Expand Up @@ -35,6 +35,14 @@ export default {
type: String,
default: () => defaults.thousands
},
max: {
codymoorhouse marked this conversation as resolved.
Show resolved Hide resolved
type: Number,
default: () => defaults.max
},
min: {
type: Number,
default: () => defaults.min
},
prefix: {
type: String,
default: () => defaults.prefix
Expand Down
4 changes: 3 additions & 1 deletion src/options.js
Expand Up @@ -3,5 +3,7 @@ export default {
suffix: '',
thousands: ',',
decimal: '.',
precision: 2
precision: 2,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
5 changes: 5 additions & 0 deletions src/utils.js
Expand Up @@ -2,6 +2,11 @@ import defaults from './options'

function format (input, opt = defaults) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codymoorhouse
Input var can be a string. If decimal is ',' then input can be like '10,000'

if (typeof input === 'number') {
if (input > opt.max) {
input = opt.max
} else if (input < opt.min) {
input = opt.min
}
input = input.toFixed(fixed(opt.precision))
}
var negative = input.indexOf('-') >= 0 ? '-' : ''
Expand Down