From 45102ede7c7326b43daeed0b10e6a459881003b6 Mon Sep 17 00:00:00 2001 From: Cody Moorhouse Date: Tue, 31 Oct 2017 11:10:27 -0600 Subject: [PATCH 1/4] Add min and max value options --- README.md | 28 ++++++++++++++++++---------- src/component.vue | 8 ++++++++ src/options.js | 4 +++- src/utils.js | 5 +++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6d89762..1752b6c 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: -1000000000, + max: 1000000000, } } } @@ -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: -1000000000, + max: 1000000000 } } }, @@ -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 | -1000000000 | The min value allowed | +| max | false | Number | 1000000000 | The max value allowed | ### References diff --git a/src/component.vue b/src/component.vue index cfb5cbc..50faa49 100644 --- a/src/component.vue +++ b/src/component.vue @@ -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/options.js b/src/options.js index 2fabe99..e9da7ad 100644 --- a/src/options.js +++ b/src/options.js @@ -3,5 +3,7 @@ export default { suffix: '', thousands: ',', decimal: '.', - precision: 2 + precision: 2, + min: -1000000000, + max: 1000000000 } 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 ? '-' : '' From 18aee458907d616607d0cb979ec99202ef55dac1 Mon Sep 17 00:00:00 2001 From: Cody Moorhouse Date: Tue, 2 Jan 2018 09:10:40 -0700 Subject: [PATCH 2/4] Change defaults to max and min safe integers --- README.md | 30 +++++++++++++++--------------- src/options.js | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1752b6c..d788b7d 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ Vue.use(money, {precision: 4}) suffix: ' #', precision: 2, masked: false, - min: -1000000000, - max: 1000000000, + min: Number.MIN_SAFE_INTEGER, + max: Number.MAX_SAFE_INTEGER } } } @@ -83,8 +83,8 @@ Must use `vmodel.lazy` to bind works properly. suffix: ' #', precision: 2, masked: false /* doesn't work with directive */, - min: -1000000000, - max: 1000000000 + min: Number.MIN_SAFE_INTEGER, + max: Number.MAX_SAFE_INTEGER } } }, @@ -96,17 +96,17 @@ Must use `vmodel.lazy` to bind works properly. ## Properties -| 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 | -1000000000 | The min value allowed | -| max | false | Number | 1000000000 | The max value allowed | +| 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/options.js b/src/options.js index e9da7ad..003ac35 100644 --- a/src/options.js +++ b/src/options.js @@ -4,6 +4,6 @@ export default { thousands: ',', decimal: '.', precision: 2, - min: -1000000000, - max: 1000000000 + min: Number.MIN_SAFE_INTEGER, + max: Number.MAX_SAFE_INTEGER } From bf98aa26dfdaa8599ee4bc5d0b8932fadabca44e Mon Sep 17 00:00:00 2001 From: Cody Moorhouse Date: Thu, 18 Jan 2018 09:09:05 -0700 Subject: [PATCH 3/4] Add missing min max to component (as per user quaks) --- src/component.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component.vue b/src/component.vue index 50faa49..e9bf256 100644 --- a/src/component.vue +++ b/src/component.vue @@ -2,7 +2,7 @@ From 4e615a945b05e53e91ba6bb7d0b2ffccb823a0b1 Mon Sep 17 00:00:00 2001 From: Cody Moorhouse Date: Thu, 9 May 2019 11:33:08 -0600 Subject: [PATCH 4/4] Add min and max to the vue generated docs --- src/docs/docs.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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} } } }