quival 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,7 +60,7 @@ const rules = {
60
60
  username: ['required', 'ascii', 'min:3'],
61
61
  name: ['required', 'min:3'],
62
62
  email: ['required', 'email'],
63
- phone_number: ['required', 'phone_number'],
63
+ phone_number: ['required', 'phone_number', 'min:7'],
64
64
  'letters.*': ['distinct:ignore_case'],
65
65
  items: ['array', 'size:5'],
66
66
  'items.*': ['required', 'string'],
@@ -91,12 +91,12 @@ validator
91
91
  .then(() => {
92
92
  console.log('Successful!');
93
93
  })
94
- .catch((messages) => {
95
- if (messages instanceof Error) {
96
- throw messages;
94
+ .catch((errorBag) => {
95
+ if (errorBag instanceof Error) {
96
+ throw errorBag;
97
97
  }
98
98
 
99
- console.log(messages);
99
+ console.log(errorBag.messages());
100
100
  });
101
101
  ```
102
102
 
@@ -114,7 +114,8 @@ The produced error messages for the code snippet above.
114
114
  "The email field must be a valid email address."
115
115
  ],
116
116
  "phone_number": [
117
- "The phone number field must be a valid phone number."
117
+ "The phone number field must be a valid phone number.",
118
+ "The phone number field must be at least 7 characters."
118
119
  ],
119
120
  "letters.0": [
120
121
  "The letters.0 field has a duplicate value."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quival",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Data validation à la Laravel Validation",
5
5
  "author": "Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>",
6
6
  "license": "MIT",
@@ -21,7 +21,10 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "eslint": "^8.39.0",
24
+ "mocha": "^10.2.0",
24
25
  "prettier": "^2.8.8"
25
26
  },
26
- "scripts": {}
27
+ "scripts": {
28
+ "test": "mocha"
29
+ }
27
30
  }
package/src/Checkers.js CHANGED
@@ -675,7 +675,7 @@ export default class Checkers {
675
675
  async checkImage(attribute, value, parameters) {
676
676
  let result = this.checkMimes(attribute, value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
677
677
 
678
- if (!result || !FileReader) {
678
+ if (!result || typeof FileReader === 'undefined') {
679
679
  return result;
680
680
  }
681
681
 
package/src/Lang.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { flattenObject, isPlainObject } from './helpers.js';
2
2
 
3
3
  export default class Lang {
4
- static #locale = 'en';
5
- static #messages = { en: {} };
4
+ static #locale;
5
+ static #messages = {};
6
6
 
7
7
  static locale(locale) {
8
8
  this.#locale = locale;
@@ -13,7 +13,11 @@ export default class Lang {
13
13
  }
14
14
 
15
15
  static get(path) {
16
- return this.#messages[this.#locale][path] ?? '';
16
+ if (this.#messages[this.#locale] && this.#messages[this.#locale][path]) {
17
+ return this.#messages[this.#locale][path];
18
+ }
19
+
20
+ return;
17
21
  }
18
22
 
19
23
  static has(path) {
package/src/Validator.js CHANGED
@@ -106,6 +106,8 @@ export default class Validator {
106
106
  for (const [rule, replacer] of Object.entries(Validator.#customReplacers)) {
107
107
  this.#replacers[toCamelCase('replace_' + rule)] = replacer;
108
108
  }
109
+
110
+ this.#errors = new ErrorBag();
109
111
  }
110
112
 
111
113
  setProperties(data = {}, rules = {}, messages = {}, attributes = {}, values = {}) {