ddan-js 2.9.4 → 2.9.6

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 (131) hide show
  1. package/bin/types/browser.d.ts +1 -1
  2. package/bin/types/index.d.ts +1 -1
  3. package/bin/types/modules/node/aliyun.d.ts +1 -1
  4. package/bin/types/upload.d.ts +2 -0
  5. package/bin/upload.js +1 -0
  6. package/package.json +18 -13
  7. package/bin/lib/browser.js +0 -111
  8. package/bin/lib/class/event.js +0 -104
  9. package/bin/lib/class/getset.js +0 -12
  10. package/bin/lib/class/icon.js +0 -94
  11. package/bin/lib/class/joker.js +0 -121
  12. package/bin/lib/class/kvalue.js +0 -29
  13. package/bin/lib/class/mapping.js +0 -82
  14. package/bin/lib/class/persist.js +0 -65
  15. package/bin/lib/class/pipeTask.js +0 -42
  16. package/bin/lib/class/pipeparallel.js +0 -24
  17. package/bin/lib/class/store.js +0 -87
  18. package/bin/lib/class/tracker.js +0 -125
  19. package/bin/lib/class/watermark.js +0 -63
  20. package/bin/lib/common/_Symbol.js +0 -5
  21. package/bin/lib/common/_freeGlobal.js +0 -5
  22. package/bin/lib/common/_object.js +0 -40
  23. package/bin/lib/common/_root.js +0 -10
  24. package/bin/lib/common/internal/asciiToArray.js +0 -13
  25. package/bin/lib/common/internal/castSlice.js +0 -18
  26. package/bin/lib/common/internal/createCaseFirst.js +0 -30
  27. package/bin/lib/common/internal/hasUnicode.js +0 -26
  28. package/bin/lib/common/internal/nodeTypes.js +0 -26
  29. package/bin/lib/common/internal/slice.js +0 -46
  30. package/bin/lib/common/internal/stringToArray.js +0 -18
  31. package/bin/lib/common/internal/unicodeToArray.js +0 -40
  32. package/bin/lib/common/internal/unicodeWords.js +0 -67
  33. package/bin/lib/index.js +0 -114
  34. package/bin/lib/modules/browser/ecdh.js +0 -124
  35. package/bin/lib/modules/browser/index.js +0 -4
  36. package/bin/lib/modules/cdn.js +0 -62
  37. package/bin/lib/modules/convert/base.js +0 -125
  38. package/bin/lib/modules/convert/base64.js +0 -114
  39. package/bin/lib/modules/convert/index.js +0 -99
  40. package/bin/lib/modules/convert/md5.js +0 -222
  41. package/bin/lib/modules/convert/pkcs.js +0 -16
  42. package/bin/lib/modules/convert/utf8.js +0 -106
  43. package/bin/lib/modules/crypto/base64.js +0 -14
  44. package/bin/lib/modules/crypto/const.js +0 -7
  45. package/bin/lib/modules/crypto/index.js +0 -30
  46. package/bin/lib/modules/crypto/rsa.js +0 -143
  47. package/bin/lib/modules/crypto/tea.js +0 -79
  48. package/bin/lib/modules/crypto/uuid.js +0 -34
  49. package/bin/lib/modules/css.js +0 -137
  50. package/bin/lib/modules/decorator.js +0 -14
  51. package/bin/lib/modules/fetch.js +0 -82
  52. package/bin/lib/modules/gbk.js +0 -46
  53. package/bin/lib/modules/hook/base.js +0 -60
  54. package/bin/lib/modules/hook/hooker.js +0 -39
  55. package/bin/lib/modules/hook/index.js +0 -49
  56. package/bin/lib/modules/hook/log.js +0 -54
  57. package/bin/lib/modules/hook/modules/bezier.js +0 -121
  58. package/bin/lib/modules/hook/modules/debounce.js +0 -127
  59. package/bin/lib/modules/hook/modules/mutex.js +0 -22
  60. package/bin/lib/modules/hook/modules/pipeline.js +0 -59
  61. package/bin/lib/modules/hook/modules/polling.js +0 -20
  62. package/bin/lib/modules/hook/modules/safeTask.js +0 -25
  63. package/bin/lib/modules/hook/modules/throttle.js +0 -30
  64. package/bin/lib/modules/html.js +0 -293
  65. package/bin/lib/modules/http/index.js +0 -171
  66. package/bin/lib/modules/http/interceptor.js +0 -22
  67. package/bin/lib/modules/list/base.js +0 -37
  68. package/bin/lib/modules/list/index.js +0 -90
  69. package/bin/lib/modules/logger.js +0 -55
  70. package/bin/lib/modules/math/index.js +0 -118
  71. package/bin/lib/modules/mini/diff.js +0 -97
  72. package/bin/lib/modules/mini/http/index.js +0 -155
  73. package/bin/lib/modules/mini/index.js +0 -71
  74. package/bin/lib/modules/node/aliyun.js +0 -156
  75. package/bin/lib/modules/node/brotli.js +0 -46
  76. package/bin/lib/modules/node/child.js +0 -18
  77. package/bin/lib/modules/node/ecdh-web.js +0 -11
  78. package/bin/lib/modules/node/ecdh.js +0 -115
  79. package/bin/lib/modules/node/file.js +0 -25
  80. package/bin/lib/modules/node/index.js +0 -11
  81. package/bin/lib/modules/node/proxy.js +0 -147
  82. package/bin/lib/modules/node/rsa-web.js +0 -19
  83. package/bin/lib/modules/node/socks5.js +0 -424
  84. package/bin/lib/modules/obj/index.js +0 -184
  85. package/bin/lib/modules/qs/base.js +0 -5
  86. package/bin/lib/modules/qs/decode.js +0 -45
  87. package/bin/lib/modules/qs/encode.js +0 -53
  88. package/bin/lib/modules/qs/index.js +0 -152
  89. package/bin/lib/modules/regex.js +0 -16
  90. package/bin/lib/modules/rsa.js +0 -18
  91. package/bin/lib/modules/rule/async-validator/index.js +0 -306
  92. package/bin/lib/modules/rule/async-validator/interface.js +0 -2
  93. package/bin/lib/modules/rule/async-validator/messages.js +0 -59
  94. package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
  95. package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
  96. package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
  97. package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
  98. package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
  99. package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
  100. package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
  101. package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
  102. package/bin/lib/modules/rule/async-validator/util.js +0 -255
  103. package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
  104. package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
  105. package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
  106. package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
  107. package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
  108. package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
  109. package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
  110. package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
  111. package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
  112. package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
  113. package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
  114. package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
  115. package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
  116. package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
  117. package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
  118. package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
  119. package/bin/lib/modules/rule/index.js +0 -67
  120. package/bin/lib/modules/string/index.js +0 -121
  121. package/bin/lib/modules/string/words.js +0 -33
  122. package/bin/lib/modules/time/const.js +0 -11
  123. package/bin/lib/modules/time/dtime.js +0 -132
  124. package/bin/lib/modules/time/frame.js +0 -49
  125. package/bin/lib/modules/time/index.js +0 -84
  126. package/bin/lib/typings/index.js +0 -2
  127. package/bin/lib/util/function.js +0 -33
  128. package/bin/lib/util/includes.js +0 -96
  129. package/bin/lib/util/index.js +0 -26
  130. package/bin/lib/util/is.js +0 -148
  131. package/bin/lib/util/to.js +0 -47
@@ -1,306 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const util_1 = require("./util");
18
- const index_1 = require("./validator/index");
19
- const messages_1 = require("./messages");
20
- __exportStar(require("./interface"), exports);
21
- /**
22
- * Encapsulates a validation schema.
23
- *
24
- * @param descriptor An object declaring validation rules
25
- * for this schema.
26
- */
27
- class Schema {
28
- // ========================= Static =========================
29
- static register = function register(type, validator) {
30
- if (typeof validator !== 'function') {
31
- throw new Error('Cannot register a validator by type, validator is not a function');
32
- }
33
- index_1.default[type] = validator;
34
- };
35
- static warning = util_1.warning;
36
- static messages = messages_1.messages;
37
- static validators = index_1.default;
38
- // ======================== Instance ========================
39
- rules = {};
40
- _messages = messages_1.messages;
41
- constructor(descriptor) {
42
- this.define(descriptor);
43
- }
44
- define(rules) {
45
- if (!rules) {
46
- throw new Error('Cannot configure a schema with no rules');
47
- }
48
- if (typeof rules !== 'object' || Array.isArray(rules)) {
49
- throw new Error('Rules must be an object');
50
- }
51
- this.rules = {};
52
- Object.keys(rules).forEach(name => {
53
- const item = rules[name];
54
- this.rules[name] = Array.isArray(item) ? item : [item];
55
- });
56
- }
57
- messages(messages) {
58
- if (messages) {
59
- this._messages = (0, util_1.deepMerge)((0, messages_1.newMessages)(), messages);
60
- }
61
- return this._messages;
62
- }
63
- validate(source_, o = {}, oc = () => { }) {
64
- let source = source_;
65
- let options = o;
66
- let callback = oc;
67
- if (typeof options === 'function') {
68
- callback = options;
69
- options = {};
70
- }
71
- if (!this.rules || Object.keys(this.rules).length === 0) {
72
- if (callback) {
73
- callback(null, source);
74
- }
75
- return Promise.resolve(source);
76
- }
77
- function complete(results) {
78
- let errors = [];
79
- let fields = {};
80
- function add(e) {
81
- if (Array.isArray(e)) {
82
- errors = errors.concat(...e);
83
- }
84
- else {
85
- errors.push(e);
86
- }
87
- }
88
- for (let i = 0; i < results.length; i++) {
89
- add(results[i]);
90
- }
91
- if (!errors.length) {
92
- callback(null, source);
93
- }
94
- else {
95
- fields = (0, util_1.convertFieldsError)(errors);
96
- callback(errors, fields);
97
- }
98
- }
99
- if (options.messages) {
100
- let messages = this.messages();
101
- if (messages === messages_1.messages) {
102
- messages = (0, messages_1.newMessages)();
103
- }
104
- (0, util_1.deepMerge)(messages, options.messages);
105
- options.messages = messages;
106
- }
107
- else {
108
- options.messages = this.messages();
109
- }
110
- const series = {};
111
- const keys = options.keys || Object.keys(this.rules);
112
- keys.forEach(z => {
113
- const arr = this.rules[z];
114
- let value = source[z];
115
- arr.forEach(r => {
116
- let rule = r;
117
- if (typeof rule.transform === 'function') {
118
- if (source === source_) {
119
- source = { ...source };
120
- }
121
- value = source[z] = rule.transform(value);
122
- }
123
- if (typeof rule === 'function') {
124
- rule = {
125
- validator: rule,
126
- };
127
- }
128
- else {
129
- rule = { ...rule };
130
- }
131
- // Fill validator. Skip if nothing need to validate
132
- rule.validator = this.getValidationMethod(rule);
133
- if (!rule.validator) {
134
- return;
135
- }
136
- rule.field = z;
137
- rule.fullField = rule.fullField || z;
138
- rule.type = this.getType(rule);
139
- series[z] = series[z] || [];
140
- series[z].push({
141
- rule,
142
- value,
143
- source,
144
- field: z,
145
- });
146
- });
147
- });
148
- const errorFields = {};
149
- return (0, util_1.asyncMap)(series, options, (data, doIt) => {
150
- const rule = data.rule;
151
- let deep = (rule.type === 'object' || rule.type === 'array') &&
152
- (typeof rule.fields === 'object' ||
153
- typeof rule.defaultField === 'object');
154
- deep = deep && (rule.required || (!rule.required && data.value));
155
- rule.field = data.field;
156
- function addFullField(key, schema) {
157
- return {
158
- ...schema,
159
- fullField: `${rule.fullField}.${key}`,
160
- fullFields: rule.fullFields ? [...rule.fullFields, key] : [key],
161
- };
162
- }
163
- function cb(e = []) {
164
- let errorList = Array.isArray(e) ? e : [e];
165
- if (options.suppressWarning === true && errorList.length) {
166
- Schema.warning('async-validator:', errorList);
167
- }
168
- if (errorList.length && rule.message !== undefined) {
169
- //@ts-ignore
170
- errorList = [].concat(rule.message);
171
- }
172
- // Fill error info
173
- let filledErrors = errorList.map((0, util_1.complementError)(rule, source));
174
- if (options.first && filledErrors.length) {
175
- errorFields[rule.field] = 1;
176
- return doIt(filledErrors);
177
- }
178
- if (!deep) {
179
- doIt(filledErrors);
180
- }
181
- else {
182
- // if rule is required but the target object
183
- // does not exist fail at the rule level and don't
184
- // go deeper
185
- if (rule.required && !data.value) {
186
- if (rule.message !== undefined) {
187
- filledErrors = []
188
- //@ts-ignore
189
- .concat(rule.message)
190
- .map((0, util_1.complementError)(rule, source));
191
- }
192
- else if (options.error) {
193
- filledErrors = [
194
- options.error(rule, (0, util_1.format)(options.messages.required, rule.field)),
195
- ];
196
- }
197
- return doIt(filledErrors);
198
- }
199
- let fieldsSchema = {};
200
- if (rule.defaultField) {
201
- Object.keys(data.value).map(key => {
202
- //@ts-ignore
203
- fieldsSchema[key] = rule.defaultField;
204
- });
205
- }
206
- fieldsSchema = {
207
- ...fieldsSchema,
208
- ...data.rule.fields,
209
- };
210
- const paredFieldsSchema = {};
211
- Object.keys(fieldsSchema).forEach(field => {
212
- const fieldSchema = fieldsSchema[field];
213
- const fieldSchemaList = Array.isArray(fieldSchema)
214
- ? fieldSchema
215
- : [fieldSchema];
216
- paredFieldsSchema[field] = fieldSchemaList.map(addFullField.bind(null, field));
217
- });
218
- const schema = new Schema(paredFieldsSchema);
219
- schema.messages(options.messages);
220
- if (data.rule.options) {
221
- data.rule.options.messages = options.messages;
222
- data.rule.options.error = options.error;
223
- }
224
- schema.validate(data.value, data.rule.options || options, errs => {
225
- const finalErrors = [];
226
- if (filledErrors && filledErrors.length) {
227
- //@ts-ignore
228
- finalErrors.push(...filledErrors);
229
- }
230
- if (errs && errs.length) {
231
- //@ts-ignore
232
- finalErrors.push(...errs);
233
- }
234
- //@ts-ignore
235
- doIt(finalErrors.length ? finalErrors : null);
236
- });
237
- }
238
- }
239
- let res = undefined;
240
- if (rule.asyncValidator) {
241
- res = rule.asyncValidator(rule, data.value, cb, data.source, options);
242
- }
243
- else if (rule.validator) {
244
- try {
245
- res = rule.validator(rule, data.value, cb, data.source, options);
246
- }
247
- catch (error) {
248
- console.error?.(error);
249
- // rethrow to report error
250
- if (!options.suppressValidatorError) {
251
- setTimeout(() => {
252
- throw error;
253
- }, 0);
254
- }
255
- //@ts-ignore
256
- cb(error.message);
257
- }
258
- if (res === true) {
259
- cb();
260
- }
261
- else if (res === false) {
262
- cb(typeof rule.message === 'function'
263
- ? rule.message(rule.fullField || rule.field)
264
- : rule.message || `${rule.fullField || rule.field} fails`);
265
- }
266
- else if (res instanceof Array) {
267
- cb(res);
268
- }
269
- else if (res instanceof Error) {
270
- cb(res.message);
271
- }
272
- }
273
- if (res && res.then) {
274
- res.then(() => cb(), e => cb(e));
275
- }
276
- }, results => {
277
- complete(results);
278
- }, source);
279
- }
280
- getType(rule) {
281
- if (rule.type === undefined && rule.pattern instanceof RegExp) {
282
- rule.type = 'pattern';
283
- }
284
- if (typeof rule.validator !== 'function' &&
285
- rule.type &&
286
- !index_1.default.hasOwnProperty(rule.type)) {
287
- throw new Error((0, util_1.format)('Unknown rule type %s', rule.type));
288
- }
289
- return rule.type || 'string';
290
- }
291
- getValidationMethod(rule) {
292
- if (typeof rule.validator === 'function') {
293
- return rule.validator;
294
- }
295
- const keys = Object.keys(rule);
296
- const messageIndex = keys.indexOf('message');
297
- if (messageIndex !== -1) {
298
- keys.splice(messageIndex, 1);
299
- }
300
- if (keys.length === 1 && keys[0] === 'required') {
301
- return index_1.default.required;
302
- }
303
- return index_1.default[this.getType(rule)] || undefined;
304
- }
305
- }
306
- exports.default = Schema;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.messages = exports.newMessages = void 0;
4
- function newMessages() {
5
- return {
6
- default: 'Validation error on field %s',
7
- required: '%s is required',
8
- enum: '%s must be one of %s',
9
- whitespace: '%s cannot be empty',
10
- date: {
11
- format: '%s date %s is invalid for format %s',
12
- parse: '%s date could not be parsed, %s is invalid ',
13
- invalid: '%s date %s is invalid',
14
- },
15
- types: {
16
- string: '%s is not a %s',
17
- method: '%s is not a %s (function)',
18
- array: '%s is not an %s',
19
- object: '%s is not an %s',
20
- number: '%s is not a %s',
21
- date: '%s is not a %s',
22
- boolean: '%s is not a %s',
23
- integer: '%s is not an %s',
24
- float: '%s is not a %s',
25
- regexp: '%s is not a valid %s',
26
- email: '%s is not a valid %s',
27
- url: '%s is not a valid %s',
28
- hex: '%s is not a valid %s',
29
- },
30
- string: {
31
- len: '%s must be exactly %s characters',
32
- min: '%s must be at least %s characters',
33
- max: '%s cannot be longer than %s characters',
34
- range: '%s must be between %s and %s characters',
35
- },
36
- number: {
37
- len: '%s must equal %s',
38
- min: '%s cannot be less than %s',
39
- max: '%s cannot be greater than %s',
40
- range: '%s must be between %s and %s',
41
- },
42
- array: {
43
- len: '%s must be exactly %s in length',
44
- min: '%s cannot be less than %s in length',
45
- max: '%s cannot be greater than %s in length',
46
- range: '%s must be between %s and %s in length',
47
- },
48
- pattern: {
49
- mismatch: '%s value %s does not match pattern %s',
50
- },
51
- clone() {
52
- const cloned = JSON.parse(JSON.stringify(this));
53
- cloned.clone = this.clone;
54
- return cloned;
55
- },
56
- };
57
- }
58
- exports.newMessages = newMessages;
59
- exports.messages = newMessages();
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const ENUM = 'enum';
5
- const enumerable = (rule, value, source, errors, options) => {
6
- rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
7
- if (rule[ENUM].indexOf(value) === -1) {
8
- errors.push(
9
- //@ts-ignore
10
- (0, util_1.format)(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
11
- }
12
- };
13
- exports.default = enumerable;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const required_1 = require("./required");
4
- const whitespace_1 = require("./whitespace");
5
- const type_1 = require("./type");
6
- const range_1 = require("./range");
7
- const enum_1 = require("./enum");
8
- const pattern_1 = require("./pattern");
9
- exports.default = {
10
- required: required_1.default,
11
- whitespace: whitespace_1.default,
12
- type: type_1.default,
13
- range: range_1.default,
14
- enum: enum_1.default,
15
- pattern: pattern_1.default,
16
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const pattern = (rule, value, source, errors, options) => {
5
- if (rule.pattern) {
6
- if (rule.pattern instanceof RegExp) {
7
- // if a RegExp instance is passed, reset `lastIndex` in case its `global`
8
- // flag is accidentally set to `true`, which in a validation scenario
9
- // is not necessary and the result might be misleading
10
- rule.pattern.lastIndex = 0;
11
- if (!rule.pattern.test(value)) {
12
- errors.push((0, util_1.format)(
13
- //@ts-ignore
14
- options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
15
- }
16
- }
17
- else if (typeof rule.pattern === 'string') {
18
- const _pattern = new RegExp(rule.pattern);
19
- if (!_pattern.test(value)) {
20
- errors.push((0, util_1.format)(
21
- //@ts-ignore
22
- options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
23
- }
24
- }
25
- }
26
- };
27
- exports.default = pattern;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const range = (rule, value, source, errors, options) => {
5
- const len = typeof rule.len === 'number';
6
- const min = typeof rule.min === 'number';
7
- const max = typeof rule.max === 'number';
8
- // 正则匹配码点范围从U+010000一直到U+10FFFF的文字(补充平面Supplementary Plane)
9
- const spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
10
- let val = value;
11
- let key = "";
12
- const num = typeof value === 'number';
13
- const str = typeof value === 'string';
14
- const arr = Array.isArray(value);
15
- if (num) {
16
- key = 'number';
17
- }
18
- else if (str) {
19
- key = 'string';
20
- }
21
- else if (arr) {
22
- key = 'array';
23
- }
24
- // if the value is not of a supported type for range validation
25
- // the validation rule rule should use the
26
- // type property to also test for a particular type
27
- if (!key) {
28
- return false;
29
- }
30
- if (arr) {
31
- val = value.length;
32
- }
33
- if (str) {
34
- // 处理码点大于U+010000的文字length属性不准确的bug,如"𠮷𠮷𠮷".length !== 3
35
- val = value.replace(spRegexp, '_').length;
36
- }
37
- if (len) {
38
- if (val !== rule.len) {
39
- //@ts-ignore
40
- errors.push((0, util_1.format)(options.messages[key].len, rule.fullField, rule.len));
41
- }
42
- //@ts-ignore
43
- }
44
- else if (min && !max && val < rule.min) {
45
- errors.push((0, util_1.format)(options.messages[key].min, rule.fullField, rule.min));
46
- }
47
- else if (max && !min && val > rule.max) {
48
- errors.push((0, util_1.format)(options.messages[key].max, rule.fullField, rule.max));
49
- }
50
- else if (min && max && (val < rule.min || val > rule.max)) {
51
- errors.push((0, util_1.format)(options.messages[key].range, rule.fullField, rule.min, rule.max));
52
- }
53
- };
54
- exports.default = range;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const required = (rule, value, source, errors, options, type) => {
5
- if (rule.required &&
6
- (!source.hasOwnProperty(rule.field || "") ||
7
- (0, util_1.isEmptyValue)(value, type || rule.type))) {
8
- //@ts-ignore
9
- errors.push((0, util_1.format)(options.messages.required, rule.fullField));
10
- }
11
- };
12
- exports.default = required;
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- const required_1 = require("./required");
5
- const url_1 = require("./url");
6
- /* eslint max-len:0 */
7
- const pattern = {
8
- // http://emailregex.com/
9
- email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
10
- // url: new RegExp(
11
- // '^(?!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]*)?$',
12
- // 'i',
13
- // ),
14
- hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,
15
- };
16
- const types = {
17
- integer(value) {
18
- return types.number(value) && parseInt(value, 10) === value;
19
- },
20
- float(value) {
21
- return types.number(value) && !types.integer(value);
22
- },
23
- array(value) {
24
- return Array.isArray(value);
25
- },
26
- regexp(value) {
27
- if (value instanceof RegExp) {
28
- return true;
29
- }
30
- try {
31
- return !!new RegExp(value);
32
- }
33
- catch (e) {
34
- return false;
35
- }
36
- },
37
- date(value) {
38
- return (typeof value.getTime === 'function' &&
39
- typeof value.getMonth === 'function' &&
40
- typeof value.getYear === 'function' &&
41
- !isNaN(value.getTime()));
42
- },
43
- number(value) {
44
- if (isNaN(value)) {
45
- return false;
46
- }
47
- return typeof value === 'number';
48
- },
49
- object(value) {
50
- return typeof value === 'object' && !types.array(value);
51
- },
52
- method(value) {
53
- return typeof value === 'function';
54
- },
55
- email(value) {
56
- return (typeof value === 'string' &&
57
- value.length <= 320 &&
58
- !!value.match(pattern.email));
59
- },
60
- url(value) {
61
- return (typeof value === 'string' &&
62
- value.length <= 2048 &&
63
- !!value.match((0, url_1.default)()));
64
- },
65
- hex(value) {
66
- return typeof value === 'string' && !!value.match(pattern.hex);
67
- },
68
- };
69
- const type = (rule, value, source, errors, options) => {
70
- if (rule.required && value === undefined) {
71
- (0, required_1.default)(rule, value, source, errors, options);
72
- return;
73
- }
74
- const custom = [
75
- 'integer',
76
- 'float',
77
- 'array',
78
- 'regexp',
79
- 'object',
80
- 'method',
81
- 'email',
82
- 'number',
83
- 'date',
84
- 'url',
85
- 'hex',
86
- ];
87
- const ruleType = rule.type;
88
- if (custom.indexOf(ruleType) > -1) {
89
- if (!types[ruleType](value)) {
90
- errors.push((0, util_1.format)(options.messages.types[ruleType], rule.fullField, rule.type));
91
- }
92
- // straight typeof check
93
- }
94
- else if (ruleType && typeof value !== rule.type) {
95
- errors.push((0, util_1.format)(options.messages.types[ruleType], rule.fullField, rule.type));
96
- }
97
- };
98
- exports.default = type;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // https://github.com/kevva/url-regex/blob/master/index.js
4
- let urlReg;
5
- exports.default = () => {
6
- if (urlReg) {
7
- return urlReg;
8
- }
9
- const word = '[a-fA-F\\d:]';
10
- const b = options => options && options.includeBoundaries
11
- ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))`
12
- : '';
13
- const v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
14
- const v6seg = '[a-fA-F\\d]{1,4}';
15
- const v6 = `
16
- (?:
17
- (?:${v6seg}:){7}(?:${v6seg}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
18
- (?:${v6seg}:){6}(?:${v4}|:${v6seg}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
19
- (?:${v6seg}:){5}(?::${v4}|(?::${v6seg}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
20
- (?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
21
- (?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
22
- (?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
23
- (?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
24
- (?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
25
- )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
26
- `
27
- .replace(/\s*\/\/.*$/gm, '')
28
- .replace(/\n/g, '')
29
- .trim();
30
- // Pre-compile only the exact regexes because adding a global flag make regexes stateful
31
- const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
32
- const v4exact = new RegExp(`^${v4}$`);
33
- const v6exact = new RegExp(`^${v6}$`);
34
- const ip = options => options && options.exact
35
- ? v46Exact
36
- : new RegExp(`(?:${b(options)}${v4}${b(options)})|(?:${b(options)}${v6}${b(options)})`, 'g');
37
- ip.v4 = (options) => options && options.exact
38
- ? v4exact
39
- : new RegExp(`${b(options)}${v4}${b(options)}`, 'g');
40
- ip.v6 = (options) => options && options.exact
41
- ? v6exact
42
- : new RegExp(`${b(options)}${v6}${b(options)}`, 'g');
43
- const protocol = `(?:(?:[a-z]+:)?//)`;
44
- const auth = '(?:\\S+(?::\\S*)?@)?';
45
- const ipv4 = ip.v4().source;
46
- const ipv6 = ip.v6().source;
47
- const host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)';
48
- const domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
49
- const tld = `(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))`;
50
- const port = '(?::\\d{2,5})?';
51
- const path = '(?:[/?#][^\\s"]*)?';
52
- const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ipv4}|${ipv6}|${host}${domain}${tld})${port}${path}`;
53
- urlReg = new RegExp(`(?:^${regex}$)`, 'i');
54
- return urlReg;
55
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../util");
4
- /**
5
- * Rule for validating whitespace.
6
- *
7
- * @param rule The validation rule.
8
- * @param value The value of the field on the source object.
9
- * @param source The source object being validated.
10
- * @param errors An array of errors that this rule may add
11
- * validation errors to.
12
- * @param options The validation options.
13
- * @param options.messages The validation messages.
14
- */
15
- const whitespace = (rule, value, source, errors, options) => {
16
- if (/^\s+$/.test(value) || value === '') {
17
- errors.push((0, util_1.format)(options.messages.whitespace, rule.fullField));
18
- }
19
- };
20
- exports.default = whitespace;