uview-pro 0.0.1

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 (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
@@ -0,0 +1,1356 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function(target) {
3
+ for (var i = 1; i < arguments.length; i++) {
4
+ var source = arguments[i];
5
+
6
+ for (var key in source) {
7
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
8
+ target[key] = source[key];
9
+ }
10
+ }
11
+ }
12
+
13
+ return target;
14
+ };
15
+
16
+ return _extends.apply(this, arguments);
17
+ }
18
+
19
+ /* eslint no-console:0 */
20
+ var formatRegExp = /%[sdj%]/g;
21
+ var warning = function warning() {}; // don't print warning message when in production env or node runtime
22
+
23
+ if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production' && typeof window !==
24
+ 'undefined' && typeof document !== 'undefined') {
25
+ warning = function warning(type, errors) {
26
+ if (typeof console !== 'undefined' && console.warn) {
27
+ if (errors.every(function(e) {
28
+ return typeof e === 'string';
29
+ })) {
30
+ console.warn(type, errors);
31
+ }
32
+ }
33
+ };
34
+ }
35
+
36
+ function convertFieldsError(errors) {
37
+ if (!errors || !errors.length) return null;
38
+ var fields = {};
39
+ errors.forEach(function(error) {
40
+ var field = error.field;
41
+ fields[field] = fields[field] || [];
42
+ fields[field].push(error);
43
+ });
44
+ return fields;
45
+ }
46
+
47
+ function format() {
48
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
49
+ args[_key] = arguments[_key];
50
+ }
51
+
52
+ var i = 1;
53
+ var f = args[0];
54
+ var len = args.length;
55
+
56
+ if (typeof f === 'function') {
57
+ return f.apply(null, args.slice(1));
58
+ }
59
+
60
+ if (typeof f === 'string') {
61
+ var str = String(f).replace(formatRegExp, function(x) {
62
+ if (x === '%%') {
63
+ return '%';
64
+ }
65
+
66
+ if (i >= len) {
67
+ return x;
68
+ }
69
+
70
+ switch (x) {
71
+ case '%s':
72
+ return String(args[i++]);
73
+
74
+ case '%d':
75
+ return Number(args[i++]);
76
+
77
+ case '%j':
78
+ try {
79
+ return JSON.stringify(args[i++]);
80
+ } catch (_) {
81
+ return '[Circular]';
82
+ }
83
+
84
+ break;
85
+
86
+ default:
87
+ return x;
88
+ }
89
+ });
90
+
91
+ for (var arg = args[i]; i < len; arg = args[++i]) {
92
+ str += " " + arg;
93
+ }
94
+
95
+ return str;
96
+ }
97
+
98
+ return f;
99
+ }
100
+
101
+ function isNativeStringType(type) {
102
+ return type === 'string' || type === 'url' || type === 'hex' || type === 'email' || type === 'pattern';
103
+ }
104
+
105
+ function isEmptyValue(value, type) {
106
+ if (value === undefined || value === null) {
107
+ return true;
108
+ }
109
+
110
+ if (type === 'array' && Array.isArray(value) && !value.length) {
111
+ return true;
112
+ }
113
+
114
+ if (isNativeStringType(type) && typeof value === 'string' && !value) {
115
+ return true;
116
+ }
117
+
118
+ return false;
119
+ }
120
+
121
+ function asyncParallelArray(arr, func, callback) {
122
+ var results = [];
123
+ var total = 0;
124
+ var arrLength = arr.length;
125
+
126
+ function count(errors) {
127
+ results.push.apply(results, errors);
128
+ total++;
129
+
130
+ if (total === arrLength) {
131
+ callback(results);
132
+ }
133
+ }
134
+
135
+ arr.forEach(function(a) {
136
+ func(a, count);
137
+ });
138
+ }
139
+
140
+ function asyncSerialArray(arr, func, callback) {
141
+ var index = 0;
142
+ var arrLength = arr.length;
143
+
144
+ function next(errors) {
145
+ if (errors && errors.length) {
146
+ callback(errors);
147
+ return;
148
+ }
149
+
150
+ var original = index;
151
+ index = index + 1;
152
+
153
+ if (original < arrLength) {
154
+ func(arr[original], next);
155
+ } else {
156
+ callback([]);
157
+ }
158
+ }
159
+
160
+ next([]);
161
+ }
162
+
163
+ function flattenObjArr(objArr) {
164
+ var ret = [];
165
+ Object.keys(objArr).forEach(function(k) {
166
+ ret.push.apply(ret, objArr[k]);
167
+ });
168
+ return ret;
169
+ }
170
+
171
+ function asyncMap(objArr, option, func, callback) {
172
+ if (option.first) {
173
+ var _pending = new Promise(function(resolve, reject) {
174
+ var next = function next(errors) {
175
+ callback(errors);
176
+ return errors.length ? reject({
177
+ errors: errors,
178
+ fields: convertFieldsError(errors)
179
+ }) : resolve();
180
+ };
181
+
182
+ var flattenArr = flattenObjArr(objArr);
183
+ asyncSerialArray(flattenArr, func, next);
184
+ });
185
+
186
+ _pending["catch"](function(e) {
187
+ return e;
188
+ });
189
+
190
+ return _pending;
191
+ }
192
+
193
+ var firstFields = option.firstFields || [];
194
+
195
+ if (firstFields === true) {
196
+ firstFields = Object.keys(objArr);
197
+ }
198
+
199
+ var objArrKeys = Object.keys(objArr);
200
+ var objArrLength = objArrKeys.length;
201
+ var total = 0;
202
+ var results = [];
203
+ var pending = new Promise(function(resolve, reject) {
204
+ var next = function next(errors) {
205
+ results.push.apply(results, errors);
206
+ total++;
207
+
208
+ if (total === objArrLength) {
209
+ callback(results);
210
+ return results.length ? reject({
211
+ errors: results,
212
+ fields: convertFieldsError(results)
213
+ }) : resolve();
214
+ }
215
+ };
216
+
217
+ if (!objArrKeys.length) {
218
+ callback(results);
219
+ resolve();
220
+ }
221
+
222
+ objArrKeys.forEach(function(key) {
223
+ var arr = objArr[key];
224
+
225
+ if (firstFields.indexOf(key) !== -1) {
226
+ asyncSerialArray(arr, func, next);
227
+ } else {
228
+ asyncParallelArray(arr, func, next);
229
+ }
230
+ });
231
+ });
232
+ pending["catch"](function(e) {
233
+ return e;
234
+ });
235
+ return pending;
236
+ }
237
+
238
+ function complementError(rule) {
239
+ return function(oe) {
240
+ if (oe && oe.message) {
241
+ oe.field = oe.field || rule.fullField;
242
+ return oe;
243
+ }
244
+
245
+ return {
246
+ message: typeof oe === 'function' ? oe() : oe,
247
+ field: oe.field || rule.fullField
248
+ };
249
+ };
250
+ }
251
+
252
+ function deepMerge(target, source) {
253
+ if (source) {
254
+ for (var s in source) {
255
+ if (source.hasOwnProperty(s)) {
256
+ var value = source[s];
257
+
258
+ if (typeof value === 'object' && typeof target[s] === 'object') {
259
+ target[s] = _extends({}, target[s], {}, value);
260
+ } else {
261
+ target[s] = value;
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ return target;
268
+ }
269
+
270
+ /**
271
+ * Rule for validating required fields.
272
+ *
273
+ * @param rule The validation rule.
274
+ * @param value The value of the field on the source object.
275
+ * @param source The source object being validated.
276
+ * @param errors An array of errors that this rule may add
277
+ * validation errors to.
278
+ * @param options The validation options.
279
+ * @param options.messages The validation messages.
280
+ */
281
+
282
+ function required(rule, value, source, errors, options, type) {
283
+ if (rule.required && (!source.hasOwnProperty(rule.field) || isEmptyValue(value, type || rule.type))) {
284
+ errors.push(format(options.messages.required, rule.fullField));
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Rule for validating whitespace.
290
+ *
291
+ * @param rule The validation rule.
292
+ * @param value The value of the field on the source object.
293
+ * @param source The source object being validated.
294
+ * @param errors An array of errors that this rule may add
295
+ * validation errors to.
296
+ * @param options The validation options.
297
+ * @param options.messages The validation messages.
298
+ */
299
+
300
+ function whitespace(rule, value, source, errors, options) {
301
+ if (/^\s+$/.test(value) || value === '') {
302
+ errors.push(format(options.messages.whitespace, rule.fullField));
303
+ }
304
+ }
305
+
306
+ /* eslint max-len:0 */
307
+
308
+ var pattern = {
309
+ // http://emailregex.com/
310
+ email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
311
+ url: new RegExp(
312
+ "^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$",
313
+ 'i'),
314
+ hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
315
+ };
316
+ var types = {
317
+ integer: function integer(value) {
318
+ return types.number(value) && parseInt(value, 10) === value;
319
+ },
320
+ "float": function float(value) {
321
+ return types.number(value) && !types.integer(value);
322
+ },
323
+ array: function array(value) {
324
+ return Array.isArray(value);
325
+ },
326
+ regexp: function regexp(value) {
327
+ if (value instanceof RegExp) {
328
+ return true;
329
+ }
330
+
331
+ try {
332
+ return !!new RegExp(value);
333
+ } catch (e) {
334
+ return false;
335
+ }
336
+ },
337
+ date: function date(value) {
338
+ return typeof value.getTime === 'function' && typeof value.getMonth === 'function' && typeof value.getYear ===
339
+ 'function';
340
+ },
341
+ number: function number(value) {
342
+ if (isNaN(value)) {
343
+ return false;
344
+ }
345
+
346
+ // 修改源码,将字符串数值先转为数值
347
+ return typeof +value === 'number';
348
+ },
349
+ object: function object(value) {
350
+ return typeof value === 'object' && !types.array(value);
351
+ },
352
+ method: function method(value) {
353
+ return typeof value === 'function';
354
+ },
355
+ email: function email(value) {
356
+ return typeof value === 'string' && !!value.match(pattern.email) && value.length < 255;
357
+ },
358
+ url: function url(value) {
359
+ return typeof value === 'string' && !!value.match(pattern.url);
360
+ },
361
+ hex: function hex(value) {
362
+ return typeof value === 'string' && !!value.match(pattern.hex);
363
+ }
364
+ };
365
+ /**
366
+ * Rule for validating the type of a value.
367
+ *
368
+ * @param rule The validation rule.
369
+ * @param value The value of the field on the source object.
370
+ * @param source The source object being validated.
371
+ * @param errors An array of errors that this rule may add
372
+ * validation errors to.
373
+ * @param options The validation options.
374
+ * @param options.messages The validation messages.
375
+ */
376
+
377
+ function type(rule, value, source, errors, options) {
378
+ if (rule.required && value === undefined) {
379
+ required(rule, value, source, errors, options);
380
+ return;
381
+ }
382
+
383
+ var custom = ['integer', 'float', 'array', 'regexp', 'object', 'method', 'email', 'number', 'date', 'url', 'hex'];
384
+ var ruleType = rule.type;
385
+
386
+ if (custom.indexOf(ruleType) > -1) {
387
+ if (!types[ruleType](value)) {
388
+ errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
389
+ } // straight typeof check
390
+
391
+ } else if (ruleType && typeof value !== rule.type) {
392
+ errors.push(format(options.messages.types[ruleType], rule.fullField, rule.type));
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Rule for validating minimum and maximum allowed values.
398
+ *
399
+ * @param rule The validation rule.
400
+ * @param value The value of the field on the source object.
401
+ * @param source The source object being validated.
402
+ * @param errors An array of errors that this rule may add
403
+ * validation errors to.
404
+ * @param options The validation options.
405
+ * @param options.messages The validation messages.
406
+ */
407
+
408
+ function range(rule, value, source, errors, options) {
409
+ var len = typeof rule.len === 'number';
410
+ var min = typeof rule.min === 'number';
411
+ var max = typeof rule.max === 'number'; // 正则匹配码点范围从U+010000一直到U+10FFFF的文字(补充平面Supplementary Plane)
412
+
413
+ var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
414
+ var val = value;
415
+ var key = null;
416
+ var num = typeof value === 'number';
417
+ var str = typeof value === 'string';
418
+ var arr = Array.isArray(value);
419
+
420
+ if (num) {
421
+ key = 'number';
422
+ } else if (str) {
423
+ key = 'string';
424
+ } else if (arr) {
425
+ key = 'array';
426
+ } // if the value is not of a supported type for range validation
427
+ // the validation rule rule should use the
428
+ // type property to also test for a particular type
429
+
430
+
431
+ if (!key) {
432
+ return false;
433
+ }
434
+
435
+ if (arr) {
436
+ val = value.length;
437
+ }
438
+
439
+ if (str) {
440
+ // 处理码点大于U+010000的文字length属性不准确的bug,如"𠮷𠮷𠮷".length !== 3
441
+ val = value.replace(spRegexp, '_').length;
442
+ }
443
+
444
+ if (len) {
445
+ if (val !== rule.len) {
446
+ errors.push(format(options.messages[key].len, rule.fullField, rule.len));
447
+ }
448
+ } else if (min && !max && val < rule.min) {
449
+ errors.push(format(options.messages[key].min, rule.fullField, rule.min));
450
+ } else if (max && !min && val > rule.max) {
451
+ errors.push(format(options.messages[key].max, rule.fullField, rule.max));
452
+ } else if (min && max && (val < rule.min || val > rule.max)) {
453
+ errors.push(format(options.messages[key].range, rule.fullField, rule.min, rule.max));
454
+ }
455
+ }
456
+
457
+ var ENUM = 'enum';
458
+ /**
459
+ * Rule for validating a value exists in an enumerable list.
460
+ *
461
+ * @param rule The validation rule.
462
+ * @param value The value of the field on the source object.
463
+ * @param source The source object being validated.
464
+ * @param errors An array of errors that this rule may add
465
+ * validation errors to.
466
+ * @param options The validation options.
467
+ * @param options.messages The validation messages.
468
+ */
469
+
470
+ function enumerable(rule, value, source, errors, options) {
471
+ rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
472
+
473
+ if (rule[ENUM].indexOf(value) === -1) {
474
+ errors.push(format(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
475
+ }
476
+ }
477
+
478
+ /**
479
+ * Rule for validating a regular expression pattern.
480
+ *
481
+ * @param rule The validation rule.
482
+ * @param value The value of the field on the source object.
483
+ * @param source The source object being validated.
484
+ * @param errors An array of errors that this rule may add
485
+ * validation errors to.
486
+ * @param options The validation options.
487
+ * @param options.messages The validation messages.
488
+ */
489
+
490
+ function pattern$1(rule, value, source, errors, options) {
491
+ if (rule.pattern) {
492
+ if (rule.pattern instanceof RegExp) {
493
+ // if a RegExp instance is passed, reset `lastIndex` in case its `global`
494
+ // flag is accidentally set to `true`, which in a validation scenario
495
+ // is not necessary and the result might be misleading
496
+ rule.pattern.lastIndex = 0;
497
+
498
+ if (!rule.pattern.test(value)) {
499
+ errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
500
+ }
501
+ } else if (typeof rule.pattern === 'string') {
502
+ var _pattern = new RegExp(rule.pattern);
503
+
504
+ if (!_pattern.test(value)) {
505
+ errors.push(format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
506
+ }
507
+ }
508
+ }
509
+ }
510
+
511
+ var rules = {
512
+ required: required,
513
+ whitespace: whitespace,
514
+ type: type,
515
+ range: range,
516
+ "enum": enumerable,
517
+ pattern: pattern$1
518
+ };
519
+
520
+ /**
521
+ * Performs validation for string types.
522
+ *
523
+ * @param rule The validation rule.
524
+ * @param value The value of the field on the source object.
525
+ * @param callback The callback function.
526
+ * @param source The source object being validated.
527
+ * @param options The validation options.
528
+ * @param options.messages The validation messages.
529
+ */
530
+
531
+ function string(rule, value, callback, source, options) {
532
+ var errors = [];
533
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
534
+
535
+ if (validate) {
536
+ if (isEmptyValue(value, 'string') && !rule.required) {
537
+ return callback();
538
+ }
539
+
540
+ rules.required(rule, value, source, errors, options, 'string');
541
+
542
+ if (!isEmptyValue(value, 'string')) {
543
+ rules.type(rule, value, source, errors, options);
544
+ rules.range(rule, value, source, errors, options);
545
+ rules.pattern(rule, value, source, errors, options);
546
+
547
+ if (rule.whitespace === true) {
548
+ rules.whitespace(rule, value, source, errors, options);
549
+ }
550
+ }
551
+ }
552
+
553
+ callback(errors);
554
+ }
555
+
556
+ /**
557
+ * Validates a function.
558
+ *
559
+ * @param rule The validation rule.
560
+ * @param value The value of the field on the source object.
561
+ * @param callback The callback function.
562
+ * @param source The source object being validated.
563
+ * @param options The validation options.
564
+ * @param options.messages The validation messages.
565
+ */
566
+
567
+ function method(rule, value, callback, source, options) {
568
+ var errors = [];
569
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
570
+
571
+ if (validate) {
572
+ if (isEmptyValue(value) && !rule.required) {
573
+ return callback();
574
+ }
575
+
576
+ rules.required(rule, value, source, errors, options);
577
+
578
+ if (value !== undefined) {
579
+ rules.type(rule, value, source, errors, options);
580
+ }
581
+ }
582
+
583
+ callback(errors);
584
+ }
585
+
586
+ /**
587
+ * Validates a number.
588
+ *
589
+ * @param rule The validation rule.
590
+ * @param value The value of the field on the source object.
591
+ * @param callback The callback function.
592
+ * @param source The source object being validated.
593
+ * @param options The validation options.
594
+ * @param options.messages The validation messages.
595
+ */
596
+
597
+ function number(rule, value, callback, source, options) {
598
+ var errors = [];
599
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
600
+
601
+ if (validate) {
602
+ if (value === '') {
603
+ value = undefined;
604
+ }
605
+
606
+ if (isEmptyValue(value) && !rule.required) {
607
+ return callback();
608
+ }
609
+
610
+ rules.required(rule, value, source, errors, options);
611
+
612
+ if (value !== undefined) {
613
+ rules.type(rule, value, source, errors, options);
614
+ rules.range(rule, value, source, errors, options);
615
+ }
616
+ }
617
+
618
+ callback(errors);
619
+ }
620
+
621
+ /**
622
+ * Validates a boolean.
623
+ *
624
+ * @param rule The validation rule.
625
+ * @param value The value of the field on the source object.
626
+ * @param callback The callback function.
627
+ * @param source The source object being validated.
628
+ * @param options The validation options.
629
+ * @param options.messages The validation messages.
630
+ */
631
+
632
+ function _boolean(rule, value, callback, source, options) {
633
+ var errors = [];
634
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
635
+
636
+ if (validate) {
637
+ if (isEmptyValue(value) && !rule.required) {
638
+ return callback();
639
+ }
640
+
641
+ rules.required(rule, value, source, errors, options);
642
+
643
+ if (value !== undefined) {
644
+ rules.type(rule, value, source, errors, options);
645
+ }
646
+ }
647
+
648
+ callback(errors);
649
+ }
650
+
651
+ /**
652
+ * Validates the regular expression type.
653
+ *
654
+ * @param rule The validation rule.
655
+ * @param value The value of the field on the source object.
656
+ * @param callback The callback function.
657
+ * @param source The source object being validated.
658
+ * @param options The validation options.
659
+ * @param options.messages The validation messages.
660
+ */
661
+
662
+ function regexp(rule, value, callback, source, options) {
663
+ var errors = [];
664
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
665
+
666
+ if (validate) {
667
+ if (isEmptyValue(value) && !rule.required) {
668
+ return callback();
669
+ }
670
+
671
+ rules.required(rule, value, source, errors, options);
672
+
673
+ if (!isEmptyValue(value)) {
674
+ rules.type(rule, value, source, errors, options);
675
+ }
676
+ }
677
+
678
+ callback(errors);
679
+ }
680
+
681
+ /**
682
+ * Validates a number is an integer.
683
+ *
684
+ * @param rule The validation rule.
685
+ * @param value The value of the field on the source object.
686
+ * @param callback The callback function.
687
+ * @param source The source object being validated.
688
+ * @param options The validation options.
689
+ * @param options.messages The validation messages.
690
+ */
691
+
692
+ function integer(rule, value, callback, source, options) {
693
+ var errors = [];
694
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
695
+
696
+ if (validate) {
697
+ if (isEmptyValue(value) && !rule.required) {
698
+ return callback();
699
+ }
700
+
701
+ rules.required(rule, value, source, errors, options);
702
+
703
+ if (value !== undefined) {
704
+ rules.type(rule, value, source, errors, options);
705
+ rules.range(rule, value, source, errors, options);
706
+ }
707
+ }
708
+
709
+ callback(errors);
710
+ }
711
+
712
+ /**
713
+ * Validates a number is a floating point number.
714
+ *
715
+ * @param rule The validation rule.
716
+ * @param value The value of the field on the source object.
717
+ * @param callback The callback function.
718
+ * @param source The source object being validated.
719
+ * @param options The validation options.
720
+ * @param options.messages The validation messages.
721
+ */
722
+
723
+ function floatFn(rule, value, callback, source, options) {
724
+ var errors = [];
725
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
726
+
727
+ if (validate) {
728
+ if (isEmptyValue(value) && !rule.required) {
729
+ return callback();
730
+ }
731
+
732
+ rules.required(rule, value, source, errors, options);
733
+
734
+ if (value !== undefined) {
735
+ rules.type(rule, value, source, errors, options);
736
+ rules.range(rule, value, source, errors, options);
737
+ }
738
+ }
739
+
740
+ callback(errors);
741
+ }
742
+
743
+ /**
744
+ * Validates an array.
745
+ *
746
+ * @param rule The validation rule.
747
+ * @param value The value of the field on the source object.
748
+ * @param callback The callback function.
749
+ * @param source The source object being validated.
750
+ * @param options The validation options.
751
+ * @param options.messages The validation messages.
752
+ */
753
+
754
+ function array(rule, value, callback, source, options) {
755
+ var errors = [];
756
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
757
+
758
+ if (validate) {
759
+ if (isEmptyValue(value, 'array') && !rule.required) {
760
+ return callback();
761
+ }
762
+
763
+ rules.required(rule, value, source, errors, options, 'array');
764
+
765
+ if (!isEmptyValue(value, 'array')) {
766
+ rules.type(rule, value, source, errors, options);
767
+ rules.range(rule, value, source, errors, options);
768
+ }
769
+ }
770
+
771
+ callback(errors);
772
+ }
773
+
774
+ /**
775
+ * Validates an object.
776
+ *
777
+ * @param rule The validation rule.
778
+ * @param value The value of the field on the source object.
779
+ * @param callback The callback function.
780
+ * @param source The source object being validated.
781
+ * @param options The validation options.
782
+ * @param options.messages The validation messages.
783
+ */
784
+
785
+ function object(rule, value, callback, source, options) {
786
+ var errors = [];
787
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
788
+
789
+ if (validate) {
790
+ if (isEmptyValue(value) && !rule.required) {
791
+ return callback();
792
+ }
793
+
794
+ rules.required(rule, value, source, errors, options);
795
+
796
+ if (value !== undefined) {
797
+ rules.type(rule, value, source, errors, options);
798
+ }
799
+ }
800
+
801
+ callback(errors);
802
+ }
803
+
804
+ var ENUM$1 = 'enum';
805
+ /**
806
+ * Validates an enumerable list.
807
+ *
808
+ * @param rule The validation rule.
809
+ * @param value The value of the field on the source object.
810
+ * @param callback The callback function.
811
+ * @param source The source object being validated.
812
+ * @param options The validation options.
813
+ * @param options.messages The validation messages.
814
+ */
815
+
816
+ function enumerable$1(rule, value, callback, source, options) {
817
+ var errors = [];
818
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
819
+
820
+ if (validate) {
821
+ if (isEmptyValue(value) && !rule.required) {
822
+ return callback();
823
+ }
824
+
825
+ rules.required(rule, value, source, errors, options);
826
+
827
+ if (value !== undefined) {
828
+ rules[ENUM$1](rule, value, source, errors, options);
829
+ }
830
+ }
831
+
832
+ callback(errors);
833
+ }
834
+
835
+ /**
836
+ * Validates a regular expression pattern.
837
+ *
838
+ * Performs validation when a rule only contains
839
+ * a pattern property but is not declared as a string type.
840
+ *
841
+ * @param rule The validation rule.
842
+ * @param value The value of the field on the source object.
843
+ * @param callback The callback function.
844
+ * @param source The source object being validated.
845
+ * @param options The validation options.
846
+ * @param options.messages The validation messages.
847
+ */
848
+
849
+ function pattern$2(rule, value, callback, source, options) {
850
+ var errors = [];
851
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
852
+
853
+ if (validate) {
854
+ if (isEmptyValue(value, 'string') && !rule.required) {
855
+ return callback();
856
+ }
857
+
858
+ rules.required(rule, value, source, errors, options);
859
+
860
+ if (!isEmptyValue(value, 'string')) {
861
+ rules.pattern(rule, value, source, errors, options);
862
+ }
863
+ }
864
+
865
+ callback(errors);
866
+ }
867
+
868
+ function date(rule, value, callback, source, options) {
869
+ var errors = [];
870
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
871
+
872
+ if (validate) {
873
+ if (isEmptyValue(value) && !rule.required) {
874
+ return callback();
875
+ }
876
+
877
+ rules.required(rule, value, source, errors, options);
878
+
879
+ if (!isEmptyValue(value)) {
880
+ var dateObject;
881
+
882
+ if (typeof value === 'number') {
883
+ dateObject = new Date(value);
884
+ } else {
885
+ dateObject = value;
886
+ }
887
+
888
+ rules.type(rule, dateObject, source, errors, options);
889
+
890
+ if (dateObject) {
891
+ rules.range(rule, dateObject.getTime(), source, errors, options);
892
+ }
893
+ }
894
+ }
895
+
896
+ callback(errors);
897
+ }
898
+
899
+ function required$1(rule, value, callback, source, options) {
900
+ var errors = [];
901
+ var type = Array.isArray(value) ? 'array' : typeof value;
902
+ rules.required(rule, value, source, errors, options, type);
903
+ callback(errors);
904
+ }
905
+
906
+ function type$1(rule, value, callback, source, options) {
907
+ var ruleType = rule.type;
908
+ var errors = [];
909
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
910
+
911
+ if (validate) {
912
+ if (isEmptyValue(value, ruleType) && !rule.required) {
913
+ return callback();
914
+ }
915
+
916
+ rules.required(rule, value, source, errors, options, ruleType);
917
+
918
+ if (!isEmptyValue(value, ruleType)) {
919
+ rules.type(rule, value, source, errors, options);
920
+ }
921
+ }
922
+
923
+ callback(errors);
924
+ }
925
+
926
+ /**
927
+ * Performs validation for any type.
928
+ *
929
+ * @param rule The validation rule.
930
+ * @param value The value of the field on the source object.
931
+ * @param callback The callback function.
932
+ * @param source The source object being validated.
933
+ * @param options The validation options.
934
+ * @param options.messages The validation messages.
935
+ */
936
+
937
+ function any(rule, value, callback, source, options) {
938
+ var errors = [];
939
+ var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
940
+
941
+ if (validate) {
942
+ if (isEmptyValue(value) && !rule.required) {
943
+ return callback();
944
+ }
945
+
946
+ rules.required(rule, value, source, errors, options);
947
+ }
948
+
949
+ callback(errors);
950
+ }
951
+
952
+ var validators = {
953
+ string: string,
954
+ method: method,
955
+ number: number,
956
+ "boolean": _boolean,
957
+ regexp: regexp,
958
+ integer: integer,
959
+ "float": floatFn,
960
+ array: array,
961
+ object: object,
962
+ "enum": enumerable$1,
963
+ pattern: pattern$2,
964
+ date: date,
965
+ url: type$1,
966
+ hex: type$1,
967
+ email: type$1,
968
+ required: required$1,
969
+ any: any
970
+ };
971
+
972
+ function newMessages() {
973
+ return {
974
+ "default": 'Validation error on field %s',
975
+ required: '%s is required',
976
+ "enum": '%s must be one of %s',
977
+ whitespace: '%s cannot be empty',
978
+ date: {
979
+ format: '%s date %s is invalid for format %s',
980
+ parse: '%s date could not be parsed, %s is invalid ',
981
+ invalid: '%s date %s is invalid'
982
+ },
983
+ types: {
984
+ string: '%s is not a %s',
985
+ method: '%s is not a %s (function)',
986
+ array: '%s is not an %s',
987
+ object: '%s is not an %s',
988
+ number: '%s is not a %s',
989
+ date: '%s is not a %s',
990
+ "boolean": '%s is not a %s',
991
+ integer: '%s is not an %s',
992
+ "float": '%s is not a %s',
993
+ regexp: '%s is not a valid %s',
994
+ email: '%s is not a valid %s',
995
+ url: '%s is not a valid %s',
996
+ hex: '%s is not a valid %s'
997
+ },
998
+ string: {
999
+ len: '%s must be exactly %s characters',
1000
+ min: '%s must be at least %s characters',
1001
+ max: '%s cannot be longer than %s characters',
1002
+ range: '%s must be between %s and %s characters'
1003
+ },
1004
+ number: {
1005
+ len: '%s must equal %s',
1006
+ min: '%s cannot be less than %s',
1007
+ max: '%s cannot be greater than %s',
1008
+ range: '%s must be between %s and %s'
1009
+ },
1010
+ array: {
1011
+ len: '%s must be exactly %s in length',
1012
+ min: '%s cannot be less than %s in length',
1013
+ max: '%s cannot be greater than %s in length',
1014
+ range: '%s must be between %s and %s in length'
1015
+ },
1016
+ pattern: {
1017
+ mismatch: '%s value %s does not match pattern %s'
1018
+ },
1019
+ clone: function clone() {
1020
+ var cloned = JSON.parse(JSON.stringify(this));
1021
+ cloned.clone = this.clone;
1022
+ return cloned;
1023
+ }
1024
+ };
1025
+ }
1026
+ var messages = newMessages();
1027
+
1028
+ /**
1029
+ * Encapsulates a validation schema.
1030
+ *
1031
+ * @param descriptor An object declaring validation rules
1032
+ * for this schema.
1033
+ */
1034
+
1035
+ function Schema(descriptor) {
1036
+ this.rules = null;
1037
+ this._messages = messages;
1038
+ this.define(descriptor);
1039
+ }
1040
+
1041
+ Schema.prototype = {
1042
+ messages: function messages(_messages) {
1043
+ if (_messages) {
1044
+ this._messages = deepMerge(newMessages(), _messages);
1045
+ }
1046
+
1047
+ return this._messages;
1048
+ },
1049
+ define: function define(rules) {
1050
+ if (!rules) {
1051
+ throw new Error('Cannot configure a schema with no rules');
1052
+ }
1053
+
1054
+ if (typeof rules !== 'object' || Array.isArray(rules)) {
1055
+ throw new Error('Rules must be an object');
1056
+ }
1057
+
1058
+ this.rules = {};
1059
+ var z;
1060
+ var item;
1061
+
1062
+ for (z in rules) {
1063
+ if (rules.hasOwnProperty(z)) {
1064
+ item = rules[z];
1065
+ this.rules[z] = Array.isArray(item) ? item : [item];
1066
+ }
1067
+ }
1068
+ },
1069
+ validate: function validate(source_, o, oc) {
1070
+ var _this = this;
1071
+
1072
+ if (o === void 0) {
1073
+ o = {};
1074
+ }
1075
+
1076
+ if (oc === void 0) {
1077
+ oc = function oc() {};
1078
+ }
1079
+
1080
+ var source = source_;
1081
+ var options = o;
1082
+ var callback = oc;
1083
+
1084
+ if (typeof options === 'function') {
1085
+ callback = options;
1086
+ options = {};
1087
+ }
1088
+
1089
+ if (!this.rules || Object.keys(this.rules).length === 0) {
1090
+ if (callback) {
1091
+ callback();
1092
+ }
1093
+
1094
+ return Promise.resolve();
1095
+ }
1096
+
1097
+ function complete(results) {
1098
+ var i;
1099
+ var errors = [];
1100
+ var fields = {};
1101
+
1102
+ function add(e) {
1103
+ if (Array.isArray(e)) {
1104
+ var _errors;
1105
+
1106
+ errors = (_errors = errors).concat.apply(_errors, e);
1107
+ } else {
1108
+ errors.push(e);
1109
+ }
1110
+ }
1111
+
1112
+ for (i = 0; i < results.length; i++) {
1113
+ add(results[i]);
1114
+ }
1115
+
1116
+ if (!errors.length) {
1117
+ errors = null;
1118
+ fields = null;
1119
+ } else {
1120
+ fields = convertFieldsError(errors);
1121
+ }
1122
+
1123
+ callback(errors, fields);
1124
+ }
1125
+
1126
+ if (options.messages) {
1127
+ var messages$1 = this.messages();
1128
+
1129
+ if (messages$1 === messages) {
1130
+ messages$1 = newMessages();
1131
+ }
1132
+
1133
+ deepMerge(messages$1, options.messages);
1134
+ options.messages = messages$1;
1135
+ } else {
1136
+ options.messages = this.messages();
1137
+ }
1138
+
1139
+ var arr;
1140
+ var value;
1141
+ var series = {};
1142
+ var keys = options.keys || Object.keys(this.rules);
1143
+ keys.forEach(function(z) {
1144
+ arr = _this.rules[z];
1145
+ value = source[z];
1146
+ arr.forEach(function(r) {
1147
+ var rule = r;
1148
+
1149
+ if (typeof rule.transform === 'function') {
1150
+ if (source === source_) {
1151
+ source = _extends({}, source);
1152
+ }
1153
+
1154
+ value = source[z] = rule.transform(value);
1155
+ }
1156
+
1157
+ if (typeof rule === 'function') {
1158
+ rule = {
1159
+ validator: rule
1160
+ };
1161
+ } else {
1162
+ rule = _extends({}, rule);
1163
+ }
1164
+
1165
+ rule.validator = _this.getValidationMethod(rule);
1166
+ rule.field = z;
1167
+ rule.fullField = rule.fullField || z;
1168
+ rule.type = _this.getType(rule);
1169
+
1170
+ if (!rule.validator) {
1171
+ return;
1172
+ }
1173
+
1174
+ series[z] = series[z] || [];
1175
+ series[z].push({
1176
+ rule: rule,
1177
+ value: value,
1178
+ source: source,
1179
+ field: z
1180
+ });
1181
+ });
1182
+ });
1183
+ var errorFields = {};
1184
+ return asyncMap(series, options, function(data, doIt) {
1185
+ var rule = data.rule;
1186
+ var deep = (rule.type === 'object' || rule.type === 'array') && (typeof rule.fields === 'object' || typeof rule.defaultField ===
1187
+ 'object');
1188
+ deep = deep && (rule.required || !rule.required && data.value);
1189
+ rule.field = data.field;
1190
+
1191
+ function addFullfield(key, schema) {
1192
+ return _extends({}, schema, {
1193
+ fullField: rule.fullField + "." + key
1194
+ });
1195
+ }
1196
+
1197
+ function cb(e) {
1198
+ if (e === void 0) {
1199
+ e = [];
1200
+ }
1201
+
1202
+ var errors = e;
1203
+
1204
+ if (!Array.isArray(errors)) {
1205
+ errors = [errors];
1206
+ }
1207
+
1208
+ if (!options.suppressWarning && errors.length) {
1209
+ Schema.warning('async-validator:', errors);
1210
+ }
1211
+
1212
+ if (errors.length && rule.message) {
1213
+ errors = [].concat(rule.message);
1214
+ }
1215
+
1216
+ errors = errors.map(complementError(rule));
1217
+
1218
+ if (options.first && errors.length) {
1219
+ errorFields[rule.field] = 1;
1220
+ return doIt(errors);
1221
+ }
1222
+
1223
+ if (!deep) {
1224
+ doIt(errors);
1225
+ } else {
1226
+ // if rule is required but the target object
1227
+ // does not exist fail at the rule level and don't
1228
+ // go deeper
1229
+ if (rule.required && !data.value) {
1230
+ if (rule.message) {
1231
+ errors = [].concat(rule.message).map(complementError(rule));
1232
+ } else if (options.error) {
1233
+ errors = [options.error(rule, format(options.messages.required, rule.field))];
1234
+ } else {
1235
+ errors = [];
1236
+ }
1237
+
1238
+ return doIt(errors);
1239
+ }
1240
+
1241
+ var fieldsSchema = {};
1242
+
1243
+ if (rule.defaultField) {
1244
+ for (var k in data.value) {
1245
+ if (data.value.hasOwnProperty(k)) {
1246
+ fieldsSchema[k] = rule.defaultField;
1247
+ }
1248
+ }
1249
+ }
1250
+
1251
+ fieldsSchema = _extends({}, fieldsSchema, {}, data.rule.fields);
1252
+
1253
+ for (var f in fieldsSchema) {
1254
+ if (fieldsSchema.hasOwnProperty(f)) {
1255
+ var fieldSchema = Array.isArray(fieldsSchema[f]) ? fieldsSchema[f] : [fieldsSchema[f]];
1256
+ fieldsSchema[f] = fieldSchema.map(addFullfield.bind(null, f));
1257
+ }
1258
+ }
1259
+
1260
+ var schema = new Schema(fieldsSchema);
1261
+ schema.messages(options.messages);
1262
+
1263
+ if (data.rule.options) {
1264
+ data.rule.options.messages = options.messages;
1265
+ data.rule.options.error = options.error;
1266
+ }
1267
+
1268
+ schema.validate(data.value, data.rule.options || options, function(errs) {
1269
+ var finalErrors = [];
1270
+
1271
+ if (errors && errors.length) {
1272
+ finalErrors.push.apply(finalErrors, errors);
1273
+ }
1274
+
1275
+ if (errs && errs.length) {
1276
+ finalErrors.push.apply(finalErrors, errs);
1277
+ }
1278
+
1279
+ doIt(finalErrors.length ? finalErrors : null);
1280
+ });
1281
+ }
1282
+ }
1283
+
1284
+ var res;
1285
+
1286
+ if (rule.asyncValidator) {
1287
+ res = rule.asyncValidator(rule, data.value, cb, data.source, options);
1288
+ } else if (rule.validator) {
1289
+ res = rule.validator(rule, data.value, cb, data.source, options);
1290
+
1291
+ if (res === true) {
1292
+ cb();
1293
+ } else if (res === false) {
1294
+ cb(rule.message || rule.field + " fails");
1295
+ } else if (res instanceof Array) {
1296
+ cb(res);
1297
+ } else if (res instanceof Error) {
1298
+ cb(res.message);
1299
+ }
1300
+ }
1301
+
1302
+ if (res && res.then) {
1303
+ res.then(function() {
1304
+ return cb();
1305
+ }, function(e) {
1306
+ return cb(e);
1307
+ });
1308
+ }
1309
+ }, function(results) {
1310
+ complete(results);
1311
+ });
1312
+ },
1313
+ getType: function getType(rule) {
1314
+ if (rule.type === undefined && rule.pattern instanceof RegExp) {
1315
+ rule.type = 'pattern';
1316
+ }
1317
+
1318
+ if (typeof rule.validator !== 'function' && rule.type && !validators.hasOwnProperty(rule.type)) {
1319
+ throw new Error(format('Unknown rule type %s', rule.type));
1320
+ }
1321
+
1322
+ return rule.type || 'string';
1323
+ },
1324
+ getValidationMethod: function getValidationMethod(rule) {
1325
+ if (typeof rule.validator === 'function') {
1326
+ return rule.validator;
1327
+ }
1328
+
1329
+ var keys = Object.keys(rule);
1330
+ var messageIndex = keys.indexOf('message');
1331
+
1332
+ if (messageIndex !== -1) {
1333
+ keys.splice(messageIndex, 1);
1334
+ }
1335
+
1336
+ if (keys.length === 1 && keys[0] === 'required') {
1337
+ return validators.required;
1338
+ }
1339
+
1340
+ return validators[this.getType(rule)] || false;
1341
+ }
1342
+ };
1343
+
1344
+ Schema.register = function register(type, validator) {
1345
+ if (typeof validator !== 'function') {
1346
+ throw new Error('Cannot register a validator by type, validator is not a function');
1347
+ }
1348
+
1349
+ validators[type] = validator;
1350
+ };
1351
+
1352
+ Schema.warning = warning;
1353
+ Schema.messages = messages;
1354
+
1355
+ export default Schema;
1356
+ //# sourceMappingURL=index.js.map