diff --git a/README.md b/README.md index 6d89762..d788b7d 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 } } } @@ -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 } } }, @@ -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 diff --git a/src/component.vue b/src/component.vue index cfb5cbc..e9bf256 100644 --- a/src/component.vue +++ b/src/component.vue @@ -2,7 +2,7 @@ @@ -35,6 +35,14 @@ export default { type: String, default: () => defaults.thousands }, + max: { + type: Number, + default: () => defaults.max + }, + min: { + type: Number, + default: () => defaults.min + }, prefix: { type: String, default: () => defaults.prefix diff --git a/src/docs/docs.vue b/src/docs/docs.vue index 2f0df75..4b97c27 100644 --- a/src/docs/docs.vue +++ b/src/docs/docs.vue @@ -83,6 +83,18 @@ +
+ +
+
+ +
+
+ +
+
+ +

@@ -113,7 +125,7 @@ export default { price: 1234.5, priceDirective: 5432.1, priceVuetify: 6789.10, - config: {decimal: ',', thousands: '.', prefix: 'R$ ', suffix: ' #', precision: 2, masked: false} + config: {decimal: ',', thousands: '.', prefix: 'R$ ', suffix: ' #', precision: 2, masked: false, max: 100000, min: -100000} } } } diff --git a/src/options.js b/src/options.js index 2fabe99..003ac35 100644 --- a/src/options.js +++ b/src/options.js @@ -3,5 +3,7 @@ export default { suffix: '', thousands: ',', decimal: '.', - precision: 2 + precision: 2, + min: Number.MIN_SAFE_INTEGER, + max: Number.MAX_SAFE_INTEGER } diff --git a/src/utils.js b/src/utils.js index 5541ea2..d9d3747 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,6 +2,11 @@ import defaults from './options' function format (input, opt = defaults) { 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 ? '-' : ''