Repository: baianat/vee-validate
Pull request #1629 (2018-10-04 04:34:50)

Add missing ts definition for validator verify method
Corresponding to `verify (value: any, rules: string | MapObject)`.
`MapObject -> Object` typing references existing methods,
e.g. dictionary parameter in `static localize` method.

codecov[bot]: # [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=h1) Report
> Merging [#1629](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=desc) into [master](https://codecov.io/gh/baianat/vee-validate/commit/bc02f6826aadc2ee405eb3cb1be1d0e01445253a?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/baianat/vee-validate/pull/1629/graphs/tree.svg?width=650&token=XFzlvHKFP5&height=150&src=pr)](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1629   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files          51       51           
  Lines        1760     1760           
  Branches      581      581           
=======================================
  Hits         1741     1741           
  Misses         19       19
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=footer). Last update [bc02f68...b018b46](https://codecov.io/gh/baianat/vee-validate/pull/1629?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs/api/mixin.md b/docs/api/mixin.md
index ee381c2e..1d352e0e 100644
--- a/docs/api/mixin.md
+++ b/docs/api/mixin.md
@@ -7,5 +7,5 @@ VeeValidate injects a mixin that augments your Vue instances with the following
 - `fields` An object containing state flags for the validated fields.
 
 ::: tip
-  You can choose to not automatically inject those properties in your instances by setting the `inject` [config option](/configuration.md) to false, but you will need to manage providing the `$validator` instance yourself so that the directive can work, refer to the [component injections](/concepts.md#component-injections) section.
+  You can choose to not automatically inject those properties in your instances by setting the `inject` [config option](/configuration.md) to false, but you will need to manage providing the `$validator` instance yourself so that the directive can work, refer to the [component injections](/concepts/injections.md#component-injections) section.
 :::
diff --git a/locale/lv.js b/locale/lv.js
index b7497a20..a812c194 100644
--- a/locale/lv.js
+++ b/locale/lv.js
@@ -2,7 +2,7 @@ import { formatFileSize, isDefinedGlobally } from './utils';
 
 const messages = {
   _default: (field) => `Laukā ${field} ievadītā vērtība nav korekta.`,
-  after: (field, [target, inclusion]) => `Lauka ${field} vērtībai jāatrodas pēc ${inclusion ? 'vai jābūt vienādai ar ' : ''}${target}.`,
+  after: (field, [target, inclusion]) => `Lauka ${field} vērtībai jābūt lielākai par ${inclusion ? 'vai vienādai ar ' : ''}${target}.`,
   alpha_dash: (field) => `Laukā ${field} var ievadīt tikai burtus, ciparus, domuzīmes un pasvītras.`,
   alpha_num: (field) => `Laukā ${field} var ievadīt tikai burtus un ciparus.`,
   alpha_spaces: (field) => `Laukā ${field} var ievadīt tikai burtus un atstarpes.`,
@@ -16,12 +16,12 @@ const messages = {
   decimal: (field, [decimals = '*'] = []) => `Laukā ${field} var ievadīt ciparus un drīkst izmantot ${!decimals || decimals === '*' ? '' : decimals} decimālpunktus.`,
   digits: (field, [length]) => `Lauka ${field} vērtību veido precīzs ${length} ciparu skaits`,
   dimensions: (field, [width, height]) => `Lauka  ${field} izmērs ir ${width} pikseļu  platumā un ${height} pikseļu augstumā.`,
-  email: (field) => `Kā lauka ${field} vērtību izmanto spēkā esošu epastu.`,
-  ext: (field) => `Kā lauka ${field} vērtību izmanto failu.`,
-  image: (field) => `Kā lauka ${field} vērtību izmanto attēlu.`,
+  email: (field) => `Lauka ${field} vērtībai jābūt derīgai e-pasta adresei.`,
+  ext: (field) => `Lauka ${field} vērtībai jābūt failam.`,
+  image: (field) => `Lauka ${field} vērtībai jābūt attēlam.`,
   included: (field) => `Lauka ${field} vērtībai jābūt derīgai.`,
-  integer: (field) => `Kā lauka ${field} vērtību izmanto veselu skaitli.`,
-  ip: (field) => `Kā lauka ${field} vērtību izmanto IP adresi.`,
+  integer: (field) => `Lauka ${field} vērtībai jābūt veselam skaitlim.`,
+  ip: (field) => `Kā ${field} vērtībai jābūt IP adresei.`,
   length: (field, [length, max]) => {
     if (max) {
       return `Lauka ${field} garumam jābūt intervālā starp ${length} un ${max}.`;
@@ -31,7 +31,7 @@ const messages = {
   },
   max: (field, [length]) => `Laukā ${field} nevar ievadīt vairāk nekā ${length} rakstzīmes.`,
   max_value: (field, [max]) => `Lauka ${field} vērtībai jābūt ${max} vai mazākai.`,
-  mimes: (field) => `Kā lauka ${field} vērtību izmanto faila tipu.`,
+  mimes: (field) => `Lauka ${field} vērtībai jābūt failam.`,
   min: (field, [length]) => `Laukā ${field} jāievada vismaz ${length} rakstzīmes.`,
   min_value: (field, [min]) => `Laukā ${field} izmanto minimālo vērtību ${min} vai lielāku.`,
   excluded: (field) => `Laukā ${field} jāievada derīga vērtība.`,
diff --git a/locale/zh_CN.js b/locale/zh_CN.js
index e5a9aced..41b7ded0 100644
--- a/locale/zh_CN.js
+++ b/locale/zh_CN.js
@@ -1,6 +1,7 @@
 import { formatFileSize, isDefinedGlobally } from './utils';
 
 const messages = {
+  _default: (field) => `${field}的值无效`,
   after: (field, [target]) => `${field}必须在${target}之后`,
   alpha_dash: (field) => `${field}能够包含字母数字字符、破折号和下划线`,
   alpha_num: (field) => `${field}只能包含字母数字字符`,
@@ -9,6 +10,7 @@ const messages = {
   before: (field, [target]) => `${field}必须在${target}之前`,
   between: (field, [min, max]) => `${field}必须在${min}与${max}之间`,
   confirmed: (field, [confirmedField]) => `${field}不能和${confirmedField}匹配`,
+  credit_card: (field) => `${field}的格式错误`,
   date_between: (field, [min, max]) => `${field}必须在${min}和${max}之间`,
   date_format: (field, [format]) => `${field}必须符合${format}格式`,
   decimal: (field, [decimals = '*'] = []) => `${field}必须是数字，且能够保留${decimals === '*' ? '' : decimals}位小数`,
@@ -18,6 +20,7 @@ const messages = {
   ext: (field) => `${field}不是一个有效的文件`,
   image: (field) => `${field}不是一张有效的图片`,
   included: (field) => `${field}不是一个有效值`,
+  integer: (field) => `${field}必须是整数`,
   ip: (field) => `${field}不是一个有效的地址`,
   length: (field, [length, max]) => {
     if (max) {
diff --git a/locale/zh_TW.js b/locale/zh_TW.js
index 14539e6f..e3395713 100644
--- a/locale/zh_TW.js
+++ b/locale/zh_TW.js
@@ -1,6 +1,7 @@
 import { formatFileSize, isDefinedGlobally } from './utils';
 
 const messages = {
+  _default: (field) => `${field} 無效。`,
   after: (field, [target]) => `${field} 必須要晚於 ${target}。`,
   alpha_dash: (field) => `${field} 只能以字母、數字及斜線組成。`,
   alpha_num: (field) => `${field} 只能以字母及數字組成。`,
@@ -19,7 +20,15 @@ const messages = {
   ext: (field) => `${field} 必須是有效的檔案。`,
   image: (field) => `${field} 必須是一張圖片。`,
   included: (field) => `所選擇的 ${field} 選項無效。`,
+  integer: (field) => `${field} 必須是整數。`,
   ip: (field) => `${field} 必須是一個有效的 IP 位址。`,
+  length: (field, [length, max]) => {
+    if (max) {
+      return `${field} 的長度必須在 ${length} 到 ${max} 之間。`;
+    }
+
+    return `${field} 的長度必須為 ${length}。`;
+  },
   max: (field, [length]) => `${field} 不能大於 ${length} 個字元。`,
   max_value: (field, [max]) => `${field} 不得大於 ${max}。`,
   mimes: (field) => `${field} 必須是有效的檔案類型.`,
diff --git a/src/rules/decimal.js b/src/rules/decimal.js
index 52df591a..0faa58e9 100644
--- a/src/rules/decimal.js
+++ b/src/rules/decimal.js
@@ -4,7 +4,7 @@ const validate = (value, { decimals = '*', separator = '.' } = {}) => {
   }
 
   if (value === null || value === undefined || value === '') {
-    return true;
+    return false;
   }
 
   // if is 0.
@@ -13,7 +13,7 @@ const validate = (value, { decimals = '*', separator = '.' } = {}) => {
   }
 
   const regexPart = decimals === '*' ? '+' : `{1,${decimals}}`;
-  const regex = new RegExp(`^-?\\d*(\\${separator}\\d${regexPart})?$`);
+  const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?$`);
 
   if (! regex.test(value)) {
     return false;
diff --git a/types/vee-validate.d.ts b/types/vee-validate.d.ts
index 23dba726..07ea1076 100644
--- a/types/vee-validate.d.ts
+++ b/types/vee-validate.d.ts
@@ -121,6 +121,11 @@ export interface FieldMatchOptions {
     name?: string;
 }
 
+export interface VerifyResult {
+    valid: boolean;
+    errors: string[];
+}
+
 export class Validator {
     errors: ErrorBag;
     fields: FieldBag;
@@ -150,6 +155,7 @@ export class Validator {
     validate(name: string, value?: any, scope?: string, silent?: boolean): Promise<any>;
     validateAll(values?: Object, scope?: string, silent?: boolean): Promise<any>;
     validateScopes(silent?: boolean): Promise<any>;
+    verify(value: any, rules: string|Object): Promise<VerifyResult>;
     static create(validations: Object, options: any): Validator;
     static extend(name: string, validator: Object|Function, options?:ExtendOptions): void;
     static remove(name: string): void;


Test patch:
diff --git a/tests/unit/rules/decimal.js b/tests/unit/rules/decimal.js
index a130571f..99177dc4 100644
--- a/tests/unit/rules/decimal.js
+++ b/tests/unit/rules/decimal.js
@@ -3,7 +3,6 @@ import { validate } from '@/rules/decimal';
 test('validates numerics with decmial numbers', () => {
   const params = { decimals: 2 };
 
-  expect(validate('')).toBe(true);
   expect(validate('11.223123818')).toBe(true);
   expect(validate(['11.223123818', '13.1231'])).toBe(true);
   expect(validate('11.223123818', {})).toBe(true);
@@ -15,12 +14,19 @@ test('validates numerics with decmial numbers', () => {
   expect(validate('11', params)).toBe(true);
   expect(validate('.11')).toBe(true);
   expect(validate('1', { decimails: 0 })).toBe(true);
+  expect(validate('+1')).toBe(true);
+  expect(validate('+1.2')).toBe(true);
 
+  expect(validate('')).toBe(false);
+  expect(validate(null)).toBe(false);
+  expect(validate(undefined)).toBe(false);
   expect(validate('11.234', params)).toBe(false);
   expect(validate('1-', params)).toBe(false);
   expect(validate('1-1', params)).toBe(false);
   expect(validate('1-1.22', params)).toBe(false);
   expect(validate(['1-2.223123818', '1-3.1231'])).toBe(false);
+  expect(validate('1+1')).toBe(false);
+  expect(validate('1+')).toBe(false);
   expect(validate('a')).toBe(false);
   expect(validate('1.11', { decimals: 0 })).toBe(false);
 });