forked from fdzcxy212206413/gsl_grs
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
88 KiB
1 line
88 KiB
1 month ago
|
{"version":3,"file":"index.js","sources":["../../src/util.ts","../../src/rule/required.ts","../../src/rule/whitespace.ts","../../src/rule/url.ts","../../src/rule/type.ts","../../src/rule/range.ts","../../src/rule/enum.ts","../../src/rule/pattern.ts","../../src/rule/index.ts","../../src/validator/string.ts","../../src/validator/method.ts","../../src/validator/number.ts","../../src/validator/boolean.ts","../../src/validator/regexp.ts","../../src/validator/integer.ts","../../src/validator/float.ts","../../src/validator/array.ts","../../src/validator/object.ts","../../src/validator/enum.ts","../../src/validator/pattern.ts","../../src/validator/date.ts","../../src/validator/required.ts","../../src/validator/type.ts","../../src/validator/any.ts","../../src/validator/index.ts","../../src/messages.ts","../../src/index.ts"],"sourcesContent":["/* eslint no-console:0 */\n\nimport {\n ValidateError,\n ValidateOption,\n RuleValuePackage,\n InternalRuleItem,\n SyncErrorType,\n RuleType,\n Value,\n Values,\n} from './interface';\n\nconst formatRegExp = /%[sdj%]/g;\n\ndeclare var ASYNC_VALIDATOR_NO_WARNING;\n\nexport let warning: (type: string, errors: SyncErrorType[]) => void = () => {};\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 (\n typeof console !== 'undefined' &&\n console.warn &&\n typeof ASYNC_VALIDATOR_NO_WARNING === 'undefined'\n ) {\n if (errors.every(e => typeof e === 'string')) {\n console.warn(type, errors);\n }\n }\n };\n}\n\nexport function convertFieldsError(\n errors: ValidateError[],\n): Record<string, ValidateError[]> {\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(\n template: ((...args: any[]) => string) | string,\n ...args: any[]\n): string {\n let i = 0;\n const len = args.length;\n if (typeof template === 'function') {\n return template.apply(null, args);\n }\n if (typeof template === 'string') {\n let str = template.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++]) as unknown) as string;\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 template;\n}\n\nfunction isNativeStringType(type: string) {\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: Value, type?: string) {\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: object) {\n return Object.keys(obj).length === 0;\n}\n\nfunction asyncParallelArray(\n arr: RuleValuePackage[],\n func: ValidateFunc,\n callback: (errors: ValidateError[]) => void,\n) {\n const results: ValidateError[] = [];\n let total = 0;\n const arrLength = arr.length;\n\n function count(errors: ValidateError[]) {\n results.push(...(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(\n arr: RuleValue
|