You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
76 KiB
1 line
76 KiB
3 years ago
|
{"version":3,"file":"index.js","sources":["../../src/util.js","../../src/rule/required.js","../../src/rule/whitespace.js","../../src/rule/type.js","../../src/rule/range.js","../../src/rule/enum.js","../../src/rule/pattern.js","../../src/rule/index.js","../../src/validator/string.js","../../src/validator/method.js","../../src/validator/number.js","../../src/validator/boolean.js","../../src/validator/regexp.js","../../src/validator/integer.js","../../src/validator/float.js","../../src/validator/array.js","../../src/validator/object.js","../../src/validator/enum.js","../../src/validator/pattern.js","../../src/validator/date.js","../../src/validator/required.js","../../src/validator/type.js","../../src/validator/any.js","../../src/validator/index.js","../../src/messages.js","../../src/index.js"],"sourcesContent":["/* eslint no-console:0 */\n\nconst formatRegExp = /%[sdj%]/g;\n\nexport let warning = () => {};\n\n// don't print warning message when in production env or node runtime\nif (\n typeof process !== 'undefined' &&\n process.env &&\n process.env.NODE_ENV !== 'production' &&\n typeof window !== 'undefined' &&\n typeof document !== 'undefined'\n) {\n warning = (type, errors) => {\n if (typeof console !== 'undefined' && console.warn) {\n if (errors.every(e => typeof e === 'string')) {\n console.warn(type, errors);\n }\n }\n };\n}\n\nexport function convertFieldsError(errors) {\n if (!errors || !errors.length) return null;\n const fields = {};\n errors.forEach(error => {\n const field = error.field;\n fields[field] = fields[field] || [];\n fields[field].push(error);\n });\n return fields;\n}\n\nexport function format(...args) {\n let i = 1;\n const f = args[0];\n const len = args.length;\n if (typeof f === 'function') {\n return f.apply(null, args.slice(1));\n }\n if (typeof f === 'string') {\n let str = String(f).replace(formatRegExp, x => {\n if (x === '%%') {\n return '%';\n }\n if (i >= len) {\n return x;\n }\n switch (x) {\n case '%s':\n return String(args[i++]);\n case '%d':\n return Number(args[i++]);\n case '%j':\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return '[Circular]';\n }\n break;\n default:\n return x;\n }\n });\n return str;\n }\n return f;\n}\n\nfunction isNativeStringType(type) {\n return (\n type === 'string' ||\n type === 'url' ||\n type === 'hex' ||\n type === 'email' ||\n type === 'date' ||\n type === 'pattern'\n );\n}\n\nexport function isEmptyValue(value, type) {\n if (value === undefined || value === null) {\n return true;\n }\n if (type === 'array' && Array.isArray(value) && !value.length) {\n return true;\n }\n if (isNativeStringType(type) && typeof value === 'string' && !value) {\n return true;\n }\n return false;\n}\n\nexport function isEmptyObject(obj) {\n return Object.keys(obj).length === 0;\n}\n\nfunction asyncParallelArray(arr, func, callback) {\n const results = [];\n let total = 0;\n const arrLength = arr.length;\n\n function count(errors) {\n results.push.apply(results, errors);\n total++;\n if (total === arrLength) {\n callback(results);\n }\n }\n\n arr.forEach(a => {\n func(a, count);\n });\n}\n\nfunction asyncSerialArray(arr, func, callback) {\n let index = 0;\n const arrLength = arr.length;\n\n function next(errors) {\n if (errors && errors.length) {\n callback(errors);\n return;\n }\n const original = index;\n index = index + 1;\n if (original < arrLength) {\n func(arr[original], next);\n } else {\n callback([]);\n }\n }\n\n next([]);\n}\n\nfunction flattenObjArr(objArr) {\n const ret = [];\n Object.keys(objArr).forEach(k => {\n ret.push.apply(ret, objArr[k]);\n });\n return ret;\n}\n\nexport class AsyncValidationError extends Error {\n constructor(errors, fields) {\n super('Async Validation Error');\n this.errors = error
|