@webiny/validation 5.44.1-beta.1 β†’ 5.45.0-beta.0

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.
Files changed (61) hide show
  1. package/README.md +7 -405
  2. package/index.d.ts +4 -4
  3. package/index.js +50 -68
  4. package/index.js.map +1 -1
  5. package/package.json +9 -12
  6. package/types.d.ts +1 -1
  7. package/types.js +1 -5
  8. package/types.js.map +1 -1
  9. package/validation.d.ts +2 -2
  10. package/validation.js +13 -20
  11. package/validation.js.map +1 -1
  12. package/validationError.js +1 -7
  13. package/validationError.js.map +1 -1
  14. package/validators/creditCard.js +5 -12
  15. package/validators/creditCard.js.map +1 -1
  16. package/validators/dateGte.js +3 -10
  17. package/validators/dateGte.js.map +1 -1
  18. package/validators/dateLte.js +3 -10
  19. package/validators/dateLte.js.map +1 -1
  20. package/validators/email.js +3 -12
  21. package/validators/email.js.map +1 -1
  22. package/validators/eq.js +4 -11
  23. package/validators/eq.js.map +1 -1
  24. package/validators/gt.js +3 -10
  25. package/validators/gt.js.map +1 -1
  26. package/validators/gte.js +3 -10
  27. package/validators/gte.js.map +1 -1
  28. package/validators/in.js +3 -10
  29. package/validators/in.js.map +1 -1
  30. package/validators/integer.js +5 -13
  31. package/validators/integer.js.map +1 -1
  32. package/validators/json.js +4 -12
  33. package/validators/json.js.map +1 -1
  34. package/validators/lt.js +3 -11
  35. package/validators/lt.js.map +1 -1
  36. package/validators/lte.js +3 -11
  37. package/validators/lte.js.map +1 -1
  38. package/validators/maxLength.js +12 -20
  39. package/validators/maxLength.js.map +1 -1
  40. package/validators/minLength.js +12 -20
  41. package/validators/minLength.js.map +1 -1
  42. package/validators/number.js +7 -14
  43. package/validators/number.js.map +1 -1
  44. package/validators/numeric.js +6 -13
  45. package/validators/numeric.js.map +1 -1
  46. package/validators/password.js +3 -11
  47. package/validators/password.js.map +1 -1
  48. package/validators/phone.js +3 -11
  49. package/validators/phone.js.map +1 -1
  50. package/validators/required.js +3 -11
  51. package/validators/required.js.map +1 -1
  52. package/validators/slug.js +3 -11
  53. package/validators/slug.js.map +1 -1
  54. package/validators/time/index.js +9 -17
  55. package/validators/time/index.js.map +1 -1
  56. package/validators/timeGte.js +5 -12
  57. package/validators/timeGte.js.map +1 -1
  58. package/validators/timeLte.js +5 -12
  59. package/validators/timeLte.js.map +1 -1
  60. package/validators/url.js +7 -23
  61. package/validators/url.js.map +1 -1
package/README.md CHANGED
@@ -1,409 +1,11 @@
1
- # Validation
2
- [![](https://img.shields.io/npm/dw/@webiny/validation.svg)](https://www.npmjs.com/package/@webiny/validation)
3
- [![](https://img.shields.io/npm/v/@webiny/validation.svg)](https://www.npmjs.com/package/@webiny/validation)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
1
+ # @webiny/validation
6
2
 
7
- A simple data validation library, packed with frequently used validators like `required`, `email`, `url`, `creditCard` etc.
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
8
6
 
9
- ## Documentation
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
10
8
 
11
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
+ ---
12
10
 
13
- #### Table of Contents
14
-
15
- - [Installation](#installation)
16
- - [Get Started](#get-started)
17
- - [Classes](#classes)
18
- - [Validation](#validation)
19
- - [setValidator](#setvalidator)
20
- - [getValidator](#getvalidator)
21
- - [validate](#validate)
22
- - [validateSync](#validatesync)
23
- - [Flow Types](#flow-types)
24
- - [ValidationError](#validationerror)
25
- - [creditCard](#creditcard)
26
- - [email](#email)
27
- - [eq](#eq)
28
- - [gt](#gt)
29
- - [gte](#gte)
30
- - [in](#in)
31
- - [number](#number)
32
- - [Validator](#validator)
33
- - [ValidateOptions](#validateoptions)
34
-
35
- ### Installation
36
-
37
- `yarn add @webiny/validation`
38
-
39
-
40
- ### Get Started
41
-
42
- #### Simple example
43
-
44
- Validation of data is performed asynchronously by default, like in the following example:
45
-
46
- import { validation } from '@webiny/validation';
47
-
48
- validation.validate(123, 'required,number,gt:20').then(() => {
49
- // Value is valid
50
- }).catch(e => {
51
- // Value is invalid
52
- });
53
-
54
- Validators are specified by its name and in this case, there are three - `required`, `number` and `gt`.
55
- Since value is not empty, it is a number and is greater than 20, code execution will proceed regularly.
56
- On the other hand, if one of the validator was not satisfied, an instance of `ValidationError` would be thrown.
57
-
58
- import { validation } from '@webiny/validation';
59
-
60
- validation.validate(10, 'required,number,gt:20').catch(e => {
61
- // Throws an Error with message "Value needs to be greater than 20.".
62
- });
63
-
64
- It is possible to provide as many validators as needed.
65
-
66
- #### Passing arguments
67
-
68
- As seen in previous section, validators can accept additional arguments, which are divided by colon.
69
- The following validator simply states that value must be greater than 20:
70
-
71
- gt:20
72
-
73
- Some validators may even accept more than one arguments:
74
-
75
- in:dog:cat:fish:bird
76
-
77
- There is no limit on the number of passed arguments.
78
-
79
- #### Built-in validators
80
-
81
- The following is a complete list of built-in validators, ready to be used immediately:
82
-
83
- - `creditCard`
84
- - `email`
85
- - `eq`
86
- - `gt`
87
- - `gte`
88
- - `in`
89
- - `integer`
90
- - `lt`
91
- - `lte`
92
- - `maxLength`
93
- - `minLength`
94
- - `number`
95
- - `password`
96
- - `phone`
97
- - `required`
98
- - `url`
99
-
100
- More information about each can be found in the following sections.
101
-
102
- #### Adding custom validators
103
-
104
- Apart from built-in validators, there are cases where additional validators might be needed. The following example
105
- shows how to add a custom validator:
106
-
107
- import { validation, ValidationError } from '@webiny/validation';
108
-
109
- validation.setValidator('gender', value => {
110
- if (['male', 'female'].includes(value)) {
111
- return;
112
- }
113
- throw new ValidationError('Value needs to be "male" or "female".);
114
- });
115
-
116
- // Throws an instance of ValidationError error.
117
- await validation.validate('none', 'gender');
118
-
119
- #### Synchronous validation
120
-
121
- As mentioned, validation by default is performed asynchronously.
122
- But if more suitable, it can also be performed synchronously:
123
-
124
- import { validation } from '@webiny/validation';
125
-
126
- // Throws an instance of ValidationError error.
127
- validation.validateSync('parrot', 'in:cat:dog:fish:parrot');
128
-
129
- // Success.
130
- validation.validateSync('fish', 'in:cat:dog:fish:parrot');
131
-
132
- #### Returning instead of throwing
133
-
134
- The following example shows how to force ValidationError to be returned, instead of thrown:
135
-
136
- import { validation } from '@webiny/validation';
137
- const error = await validation.validate("", "required", { throw: false });
138
-
139
- Once executed, an instance of ValidationError will be assigned to the `error` constant.
140
-
141
-
142
- ### Classes
143
-
144
-
145
-
146
-
147
- #### Validation
148
-
149
- [packages-utils/@webiny/validation/src/validation.js:23-148](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validation.js#L23-L148 "Source code on GitHub")
150
-
151
- Main class of Validation library.
152
- Exported as a singleton instance, it offers methods for sync/async data validation and overwriting or adding new validators.
153
-
154
- **Examples**
155
-
156
- ```javascript
157
- import { validation } from '@webiny/validation';
158
-
159
- // `validation` is a preconfigured instance of Validation class.
160
- // From here you can either add new validators or use it as-is.
161
- ```
162
-
163
- ##### setValidator
164
-
165
- [packages-utils/@webiny/validation/src/validation.js:40-43](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validation.js#L40-L43 "Source code on GitHub")
166
-
167
- Add new validator.
168
-
169
- **Parameters**
170
-
171
- - `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Validator name.
172
- - `callable` **[Validator](#validator)** Validator function which throws a ValidationError if validation fails.
173
-
174
- Returns **[Validation](#validation)**
175
-
176
- ##### getValidator
177
-
178
- [packages-utils/@webiny/validation/src/validation.js:50-55](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validation.js#L50-L55 "Source code on GitHub")
179
-
180
- Get validator function by name.
181
-
182
- **Parameters**
183
-
184
- - `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Validator name.
185
-
186
- Returns **[Validator](#validator)** A validator function.
187
-
188
- ##### validate
189
-
190
- [packages-utils/@webiny/validation/src/validation.js:64-92](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validation.js#L64-L92 "Source code on GitHub")
191
-
192
- Asynchronously validates value.
193
-
194
- **Parameters**
195
-
196
- - `value` **any** Value to validate.
197
- - `validators` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** A list of comma-separated validators (eg. required,number,gt:20).
198
- - `options` **[ValidateOptions](#validateoptions)** Validation options.
199
-
200
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) \| [ValidationError](#validationerror))>**
201
-
202
- ##### validateSync
203
-
204
- [packages-utils/@webiny/validation/src/validation.js:101-129](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validation.js#L101-L129 "Source code on GitHub")
205
-
206
- Synchronously validates value.
207
-
208
- **Parameters**
209
-
210
- - `value` **any** Value to validate.
211
- - `validators` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** A list of comma-separated validators (eg. required,number,gt:20).
212
- - `options` **[ValidateOptions](#validateoptions)** Validation options.
213
-
214
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) \| [ValidationError](#validationerror))>**
215
-
216
- ### Flow Types
217
-
218
-
219
-
220
-
221
- ### ValidationError
222
-
223
- [packages-utils/@webiny/validation/src/validationError.js:10-21](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validationError.js#L10-L21 "Source code on GitHub")
224
-
225
- This class is used by validators to throw an error when value validation fails.
226
-
227
- **Parameters**
228
-
229
- - `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Error message
230
- - `validator` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Validator that triggered this error
231
- - `value` **any** Value that triggered this error
232
-
233
- ### creditCard
234
-
235
- [packages-utils/@webiny/validation/src/validators/creditCard.js:17-54](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/creditCard.js#L17-L54 "Source code on GitHub")
236
-
237
- Credit card validator. This validator will check if the given value is a credit card number.
238
-
239
- **Parameters**
240
-
241
- - `value` **any** This is the value that will be validated.
242
-
243
- **Examples**
244
-
245
- ```javascript
246
- import { validation } from '@webiny/validation';
247
- validation.validate('notACreditCard', 'creditCard').then(() => {
248
- // Valid
249
- }).catch(e => {
250
- // Invalid
251
- });
252
- ```
253
-
254
- - Throws **[ValidationError](#validationerror)**
255
-
256
- ### email
257
-
258
- [packages-utils/@webiny/validation/src/validators/email.js:17-27](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/email.js#L17-L27 "Source code on GitHub")
259
-
260
- Email validator. This validator checks if the given value is a valid email address.
261
-
262
- **Parameters**
263
-
264
- - `value` **any** This is the value that will be validated.
265
-
266
- **Examples**
267
-
268
- ```javascript
269
- import { validation } from '@webiny/validation';
270
- validation.validate('email@gmail.com', 'email').then(() => {
271
- // Valid
272
- }).catch(e => {
273
- // Invalid
274
- });
275
- ```
276
-
277
- - Throws **[ValidationError](#validationerror)**
278
-
279
- ### eq
280
-
281
- [packages-utils/@webiny/validation/src/validators/eq.js:18-27](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/eq.js#L18-L27 "Source code on GitHub")
282
-
283
- Equality validator. This validator checks if the given values are equal.
284
-
285
- **Parameters**
286
-
287
- - `value` **any** This is the value that will be validated.
288
- - `params` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** This is the value to validate against. It is passed as a validator parameter: `eq:valueToCompareWith`
289
-
290
- **Examples**
291
-
292
- ```javascript
293
- import { validation } from '@webiny/validation';
294
- validation.validate('email@gmail.com', 'eq:another@gmail.com').then(() => {
295
- // Valid
296
- }).catch(e => {
297
- // Invalid
298
- });
299
- ```
300
-
301
- - Throws **[ValidationError](#validationerror)**
302
-
303
- ### gt
304
-
305
- [packages-utils/@webiny/validation/src/validators/gt.js:18-25](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/gt.js#L18-L25 "Source code on GitHub")
306
-
307
- "Greater than" validator. This validator checks if the given values is greater than the `min` value.
308
-
309
- **Parameters**
310
-
311
- - `value` **any** This is the value that will be validated.
312
- - `params` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** This is the value to validate against. It is passed as a validator parameter: `gt:valueToCompareAgainst`
313
-
314
- **Examples**
315
-
316
- ```javascript
317
- import { validation } from '@webiny/validation';
318
- validation.validate(10, 'gt:100').then(() => {
319
- // Valid
320
- }).catch(e => {
321
- // Invalid
322
- });
323
- ```
324
-
325
- - Throws **[ValidationError](#validationerror)**
326
-
327
- ### gte
328
-
329
- [packages-utils/@webiny/validation/src/validators/gte.js:18-25](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/gte.js#L18-L25 "Source code on GitHub")
330
-
331
- "Greater than or equals" validator. This validator checks if the given values is greater than or equal to the `min` value.
332
-
333
- **Parameters**
334
-
335
- - `value` **any** This is the value that will be validated.
336
- - `min` **any** This is the value to validate against. It is passed as a validator parameter: `gte:valueToCompareAgainst`
337
-
338
- **Examples**
339
-
340
- ```javascript
341
- import { validation } from '@webiny/validation';
342
- validation.validate(10, 'gte:100').then(() => {
343
- // Valid
344
- }).catch(e => {
345
- // Invalid
346
- });
347
- ```
348
-
349
- - Throws **[ValidationError](#validationerror)**
350
-
351
- ### in
352
-
353
- [packages-utils/@webiny/validation/src/validators/in.js:18-27](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/in.js#L18-L27 "Source code on GitHub")
354
-
355
- "In array" validator. This validator checks if the given values is greater than or equal to the `min` value.
356
-
357
- **Parameters**
358
-
359
- - `value` **any** This is the value that will be validated.
360
- - `params` **any** This is the array of values to search in. It is passed as a validator parameter: `in:1:2:3`. Array values are separated by `:`.
361
-
362
- **Examples**
363
-
364
- ```javascript
365
- import { validation } from '@webiny/validation';
366
- validation.validate(10, 'in:10:20:30').then(() => {
367
- // Valid
368
- }).catch(e => {
369
- // Invalid
370
- });
371
- ```
372
-
373
- - Throws **[ValidationError](#validationerror)**
374
-
375
- ### number
376
-
377
- [packages-utils/@webiny/validation/src/validators/number.js:11-19](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/src/validators/number.js#L11-L19 "Source code on GitHub")
378
-
379
- This validator checks of the given value is a number
380
-
381
- **Parameters**
382
-
383
- - `value` **any**
384
-
385
- Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
386
-
387
- ### Validator
388
-
389
- [packages-utils/@webiny/validation/types.js:9-9](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/types.js#L9-L9 "Source code on GitHub")
390
-
391
- This type defines the validator function.
392
-
393
- **Parameters**
394
-
395
- - `value` **any** This is the value being validated.
396
- - `parameters` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (Optional) This represents an array validator parameters.
397
-
398
-
399
- - Throws **[ValidationError](#validationerror)**
400
-
401
- ### ValidateOptions
402
-
403
- [packages-utils/@webiny/validation/types.js:17-19](https://github.com/webiny/webiny-js/blob/d48d320d653854e2ae18bc85dde4cb083d93d593/packages-utils/@webiny/validation/types.js#L17-L19 "Source code on GitHub")
404
-
405
- This is an object containing validation options.
406
-
407
- **Properties**
408
-
409
- - `throw` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Should validation throw on failure? Default: true.
11
+ _This README file is automatically generated during the publish process._
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Validation from "./validation";
2
- import ValidationError from "./validationError";
3
- declare const validation: Validation;
4
- export { validation, Validation, ValidationError };
1
+ import Validation from "./validation.js";
2
+ import ValidationError from "./validationError.js";
3
+ export declare const validation: Validation;
4
+ export { Validation, ValidationError };
package/index.js CHANGED
@@ -1,70 +1,52 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- Object.defineProperty(exports, "Validation", {
8
- enumerable: true,
9
- get: function () {
10
- return _validation.default;
11
- }
12
- });
13
- Object.defineProperty(exports, "ValidationError", {
14
- enumerable: true,
15
- get: function () {
16
- return _validationError.default;
17
- }
18
- });
19
- exports.validation = void 0;
20
- var _validation = _interopRequireDefault(require("./validation"));
21
- var _validationError = _interopRequireDefault(require("./validationError"));
22
- var _creditCard = _interopRequireDefault(require("./validators/creditCard"));
23
- var _email = _interopRequireDefault(require("./validators/email"));
24
- var _eq = _interopRequireDefault(require("./validators/eq"));
25
- var _gt = _interopRequireDefault(require("./validators/gt"));
26
- var _gte = _interopRequireDefault(require("./validators/gte"));
27
- var _in = _interopRequireDefault(require("./validators/in"));
28
- var _integer = _interopRequireDefault(require("./validators/integer"));
29
- var _json = _interopRequireDefault(require("./validators/json"));
30
- var _lt = _interopRequireDefault(require("./validators/lt"));
31
- var _lte = _interopRequireDefault(require("./validators/lte"));
32
- var _maxLength = _interopRequireDefault(require("./validators/maxLength"));
33
- var _minLength = _interopRequireDefault(require("./validators/minLength"));
34
- var _number = _interopRequireDefault(require("./validators/number"));
35
- var _numeric = _interopRequireDefault(require("./validators/numeric"));
36
- var _password = _interopRequireDefault(require("./validators/password"));
37
- var _phone = _interopRequireDefault(require("./validators/phone"));
38
- var _required = _interopRequireDefault(require("./validators/required"));
39
- var _url = _interopRequireDefault(require("./validators/url"));
40
- var _dateGte = _interopRequireDefault(require("./validators/dateGte"));
41
- var _dateLte = _interopRequireDefault(require("./validators/dateLte"));
42
- var _timeGte = _interopRequireDefault(require("./validators/timeGte"));
43
- var _timeLte = _interopRequireDefault(require("./validators/timeLte"));
44
- var _slug = _interopRequireDefault(require("./validators/slug"));
45
- const validation = exports.validation = new _validation.default();
46
- validation.setValidator("creditCard", _creditCard.default);
47
- validation.setValidator("email", _email.default);
48
- validation.setValidator("eq", _eq.default);
49
- validation.setValidator("gt", _gt.default);
50
- validation.setValidator("gte", _gte.default);
51
- validation.setValidator("in", _in.default);
52
- validation.setValidator("integer", _integer.default);
53
- validation.setValidator("json", _json.default);
54
- validation.setValidator("lt", _lt.default);
55
- validation.setValidator("lte", _lte.default);
56
- validation.setValidator("maxLength", _maxLength.default);
57
- validation.setValidator("minLength", _minLength.default);
58
- validation.setValidator("number", _number.default);
59
- validation.setValidator("numeric", _numeric.default);
60
- validation.setValidator("password", _password.default);
61
- validation.setValidator("phone", _phone.default);
62
- validation.setValidator("required", _required.default);
63
- validation.setValidator("url", _url.default);
64
- validation.setValidator("dateGte", _dateGte.default);
65
- validation.setValidator("dateLte", _dateLte.default);
66
- validation.setValidator("timeGte", _timeGte.default);
67
- validation.setValidator("timeLte", _timeLte.default);
68
- validation.setValidator("slug", _slug.default);
1
+ import Validation from "./validation.js";
2
+ import ValidationError from "./validationError.js";
3
+ import creditCard from "./validators/creditCard.js";
4
+ import email from "./validators/email.js";
5
+ import eq from "./validators/eq.js";
6
+ import gt from "./validators/gt.js";
7
+ import gte from "./validators/gte.js";
8
+ import isIn from "./validators/in.js";
9
+ import integer from "./validators/integer.js";
10
+ import json from "./validators/json.js";
11
+ import lt from "./validators/lt.js";
12
+ import lte from "./validators/lte.js";
13
+ import maxLength from "./validators/maxLength.js";
14
+ import minLength from "./validators/minLength.js";
15
+ import number from "./validators/number.js";
16
+ import numeric from "./validators/numeric.js";
17
+ import password from "./validators/password.js";
18
+ import phone from "./validators/phone.js";
19
+ import required from "./validators/required.js";
20
+ import url from "./validators/url.js";
21
+ import dateGte from "./validators/dateGte.js";
22
+ import dateLte from "./validators/dateLte.js";
23
+ import timeGte from "./validators/timeGte.js";
24
+ import timeLte from "./validators/timeLte.js";
25
+ import slug from "./validators/slug.js";
26
+ export const validation = new Validation();
27
+ validation.setValidator("creditCard", creditCard);
28
+ validation.setValidator("email", email);
29
+ validation.setValidator("eq", eq);
30
+ validation.setValidator("gt", gt);
31
+ validation.setValidator("gte", gte);
32
+ validation.setValidator("in", isIn);
33
+ validation.setValidator("integer", integer);
34
+ validation.setValidator("json", json);
35
+ validation.setValidator("lt", lt);
36
+ validation.setValidator("lte", lte);
37
+ validation.setValidator("maxLength", maxLength);
38
+ validation.setValidator("minLength", minLength);
39
+ validation.setValidator("number", number);
40
+ validation.setValidator("numeric", numeric);
41
+ validation.setValidator("password", password);
42
+ validation.setValidator("phone", phone);
43
+ validation.setValidator("required", required);
44
+ validation.setValidator("url", url);
45
+ validation.setValidator("dateGte", dateGte);
46
+ validation.setValidator("dateLte", dateLte);
47
+ validation.setValidator("timeGte", timeGte);
48
+ validation.setValidator("timeLte", timeLte);
49
+ validation.setValidator("slug", slug);
50
+ export { Validation, ValidationError };
69
51
 
70
52
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_validation","_interopRequireDefault","require","_validationError","_creditCard","_email","_eq","_gt","_gte","_in","_integer","_json","_lt","_lte","_maxLength","_minLength","_number","_numeric","_password","_phone","_required","_url","_dateGte","_dateLte","_timeGte","_timeLte","_slug","validation","exports","Validation","setValidator","creditCard","email","eq","gt","gte","isIn","integer","json","lt","lte","maxLength","minLength","number","numeric","password","phone","required","url","dateGte","dateLte","timeGte","timeLte","slug"],"sources":["index.ts"],"sourcesContent":["import Validation from \"./validation\";\nimport ValidationError from \"./validationError\";\nimport creditCard from \"./validators/creditCard\";\nimport email from \"./validators/email\";\nimport eq from \"./validators/eq\";\nimport gt from \"./validators/gt\";\nimport gte from \"./validators/gte\";\nimport isIn from \"./validators/in\";\nimport integer from \"./validators/integer\";\nimport json from \"./validators/json\";\nimport lt from \"./validators/lt\";\nimport lte from \"./validators/lte\";\nimport maxLength from \"./validators/maxLength\";\nimport minLength from \"./validators/minLength\";\nimport number from \"./validators/number\";\nimport numeric from \"./validators/numeric\";\nimport password from \"./validators/password\";\nimport phone from \"./validators/phone\";\nimport required from \"./validators/required\";\nimport url from \"./validators/url\";\nimport dateGte from \"./validators/dateGte\";\nimport dateLte from \"./validators/dateLte\";\nimport timeGte from \"./validators/timeGte\";\nimport timeLte from \"./validators/timeLte\";\nimport slug from \"./validators/slug\";\n\nconst validation = new Validation();\nvalidation.setValidator(\"creditCard\", creditCard);\nvalidation.setValidator(\"email\", email);\nvalidation.setValidator(\"eq\", eq);\nvalidation.setValidator(\"gt\", gt);\nvalidation.setValidator(\"gte\", gte);\nvalidation.setValidator(\"in\", isIn);\nvalidation.setValidator(\"integer\", integer);\nvalidation.setValidator(\"json\", json);\nvalidation.setValidator(\"lt\", lt);\nvalidation.setValidator(\"lte\", lte);\nvalidation.setValidator(\"maxLength\", maxLength);\nvalidation.setValidator(\"minLength\", minLength);\nvalidation.setValidator(\"number\", number);\nvalidation.setValidator(\"numeric\", numeric);\nvalidation.setValidator(\"password\", password);\nvalidation.setValidator(\"phone\", phone);\nvalidation.setValidator(\"required\", required);\nvalidation.setValidator(\"url\", url);\nvalidation.setValidator(\"dateGte\", dateGte);\nvalidation.setValidator(\"dateLte\", dateLte);\nvalidation.setValidator(\"timeGte\", timeGte);\nvalidation.setValidator(\"timeLte\", timeLte);\nvalidation.setValidator(\"slug\", slug);\n\nexport { validation, Validation, ValidationError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,GAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,GAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,IAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,GAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,QAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,KAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,GAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,IAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,UAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,UAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,OAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,QAAA,GAAAhB,sBAAA,CAAAC,OAAA;AACA,IAAAgB,SAAA,GAAAjB,sBAAA,CAAAC,OAAA;AACA,IAAAiB,MAAA,GAAAlB,sBAAA,CAAAC,OAAA;AACA,IAA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G,YAAY,CAAC,UAAU,EAAEe,iBAAQ,CAAC;AAC7ClB,UAAU,CAACG,YAAY,CAAC,OAAO,EAAEgB,cAAK,CAAC;AACvCnB,UAAU,CAACG,YAAY,CAAC,UAAU,EAAEiB,iBAAQ,CAAC;AAC7CpB,UAAU,CAACG,YAAY,CAAC,KAAK,EAAEkB,YAAG,CAAC;AACnCrB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEmB,gBAAO,CAAC;AAC3CtB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEoB,gBAAO,CAAC;AAC3CvB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEqB,gBAAO,CAAC;AAC3CxB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEsB,gBAAO,CAAC;AAC3CzB,UAAU,CAACG,YAAY,CAAC,MAAM,EAAEuB,aAAI,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Validation","ValidationError","creditCard","email","eq","gt","gte","isIn","integer","json","lt","lte","maxLength","minLength","number","numeric","password","phone","required","url","dateGte","dateLte","timeGte","timeLte","slug","validation","setValidator"],"sources":["index.ts"],"sourcesContent":["import Validation from \"./validation.js\";\nimport ValidationError from \"./validationError.js\";\nimport creditCard from \"./validators/creditCard.js\";\nimport email from \"./validators/email.js\";\nimport eq from \"./validators/eq.js\";\nimport gt from \"./validators/gt.js\";\nimport gte from \"./validators/gte.js\";\nimport isIn from \"./validators/in.js\";\nimport integer from \"./validators/integer.js\";\nimport json from \"./validators/json.js\";\nimport lt from \"./validators/lt.js\";\nimport lte from \"./validators/lte.js\";\nimport maxLength from \"./validators/maxLength.js\";\nimport minLength from \"./validators/minLength.js\";\nimport number from \"./validators/number.js\";\nimport numeric from \"./validators/numeric.js\";\nimport password from \"./validators/password.js\";\nimport phone from \"./validators/phone.js\";\nimport required from \"./validators/required.js\";\nimport url from \"./validators/url.js\";\nimport dateGte from \"./validators/dateGte.js\";\nimport dateLte from \"./validators/dateLte.js\";\nimport timeGte from \"./validators/timeGte.js\";\nimport timeLte from \"./validators/timeLte.js\";\nimport slug from \"./validators/slug.js\";\n\nexport const validation = new Validation();\n\nvalidation.setValidator(\"creditCard\", creditCard);\nvalidation.setValidator(\"email\", email);\nvalidation.setValidator(\"eq\", eq);\nvalidation.setValidator(\"gt\", gt);\nvalidation.setValidator(\"gte\", gte);\nvalidation.setValidator(\"in\", isIn);\nvalidation.setValidator(\"integer\", integer);\nvalidation.setValidator(\"json\", json);\nvalidation.setValidator(\"lt\", lt);\nvalidation.setValidator(\"lte\", lte);\nvalidation.setValidator(\"maxLength\", maxLength);\nvalidation.setValidator(\"minLength\", minLength);\nvalidation.setValidator(\"number\", number);\nvalidation.setValidator(\"numeric\", numeric);\nvalidation.setValidator(\"password\", password);\nvalidation.setValidator(\"phone\", phone);\nvalidation.setValidator(\"required\", required);\nvalidation.setValidator(\"url\", url);\nvalidation.setValidator(\"dateGte\", dateGte);\nvalidation.setValidator(\"dateLte\", dateLte);\nvalidation.setValidator(\"timeGte\", timeGte);\nvalidation.setValidator(\"timeLte\", timeLte);\nvalidation.setValidator(\"slug\", slug);\n\nexport { Validation, ValidationError };\n"],"mappings":"AAAA,OAAOA,UAAU;AACjB,OAAOC,eAAe;AACtB,OAAOC,UAAU;AACjB,OAAOC,KAAK;AACZ,OAAOC,EAAE;AACT,OAAOC,EAAE;AACT,OAAOC,GAAG;AACV,OAAOC,IAAI;AACX,OAAOC,OAAO;AACd,OAAOC,IAAI;AACX,OAAOC,EAAE;AACT,OAAOC,GAAG;AACV,OAAOC,SAAS;AAChB,OAAOC,SAAS;AAChB,OAAOC,MAAM;AACb,OAAOC,OAAO;AACd,OAAOC,QAAQ;AACf,OAAOC,KAAK;AACZ,OAAOC,QAAQ;AACf,OAAOC,GAAG;AACV,OAAOC,OAAO;AACd,OAAOC,OAAO;AACd,OAAOC,OAAO;AACd,OAAOC,OAAO;AACd,OAAOC,IAAI;AAEX,OAAO,MAAMC,UAAU,GAAG,IAAIzB,UAAU,CAAC,CAAC;AAE1C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AACC,YAAY,CAAC,SAAS,EAAEH,OAAO,CAAC;AAC3CE,UAAU,CAACC,YAAY,CAAC,MAAM,EAAEF,IAAI,CAAC;AAErC,SAASxB,UAAU,EAAEC,eAAe","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@webiny/validation",
3
- "version": "5.44.1-beta.1",
3
+ "version": "5.45.0-beta.0",
4
+ "type": "module",
4
5
  "main": "index.js",
5
6
  "repository": {
6
7
  "type": "git",
@@ -15,22 +16,18 @@
15
16
  "license": "MIT",
16
17
  "dependencies": {
17
18
  "isnumeric": "0.3.3",
18
- "lodash": "4.17.21"
19
+ "lodash": "4.17.23"
19
20
  },
20
21
  "devDependencies": {
21
- "@types/lodash": "4.17.13",
22
- "@webiny/project-utils": "5.44.1-beta.1",
23
- "jest": "29.7.0",
24
- "rimraf": "6.0.1",
25
- "typescript": "5.3.3"
22
+ "@types/lodash": "4.17.23",
23
+ "@webiny/build-tools": "5.45.0-beta.0",
24
+ "rimraf": "6.1.3",
25
+ "typescript": "5.9.3",
26
+ "vitest": "4.0.18"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public",
29
30
  "directory": "dist"
30
31
  },
31
- "scripts": {
32
- "build": "node ../cli/bin.js run build",
33
- "watch": "node ../cli/bin.js run watch"
34
- },
35
- "gitHead": "ff5f085c417040291d39fdbe5153067f3a23ed86"
32
+ "gitHead": "b85c33cfbe7c02c130445c918d913ef4b2c09cb2"
36
33
  }
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import ValidationError from "./validationError";
1
+ import type ValidationError from "./validationError.js";
2
2
  type ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;
3
3
  /**
4
4
  * @typedef Validator
package/types.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
6
2
 
7
3
  //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\ntype ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;\n/**\n * @typedef Validator\n * @name Validator\n * @description This type defines the validator function.\n * @param {any} value This is the value being validated.\n * @param {Array<string>} parameters (Optional) This represents an array validator parameters.\n * @throws {ValidationError}\n */\nexport interface Validator {\n (value: any, params?: string[]): ValidatorResult;\n validatorName?: string;\n}\n\n/**\n * @typedef ValidateOptions\n * @name ValidateOptions\n * @description This is an object containing validation options.\n * @property {boolean} throw Should validation throw on failure? Default: true.\n */\nexport interface ValidateOptions {\n throw?: boolean;\n}\n\n/**\n * @private\n * @typedef ParsedValidators\n * @name ParsedValidators\n * @description An object containing validators with parameters: `{ [string]: Array<string> }`.\n */\nexport interface ParsedValidators {\n [key: string]: Array<string>;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type ValidationError from \"~/validationError.js\";\n\ntype ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;\n/**\n * @typedef Validator\n * @name Validator\n * @description This type defines the validator function.\n * @param {any} value This is the value being validated.\n * @param {Array<string>} parameters (Optional) This represents an array validator parameters.\n * @throws {ValidationError}\n */\nexport interface Validator {\n (value: any, params?: string[]): ValidatorResult;\n validatorName?: string;\n}\n\n/**\n * @typedef ValidateOptions\n * @name ValidateOptions\n * @description This is an object containing validation options.\n * @property {boolean} throw Should validation throw on failure? Default: true.\n */\nexport interface ValidateOptions {\n throw?: boolean;\n}\n\n/**\n * @private\n * @typedef ParsedValidators\n * @name ParsedValidators\n * @description An object containing validators with parameters: `{ [string]: Array<string> }`.\n */\nexport interface ParsedValidators {\n [key: string]: Array<string>;\n}\n"],"mappings":"","ignoreList":[]}