index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. "use strict";
  2. var _a;
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. var verification_1 = require("../type/verification");
  5. var index_1 = require("../tool/toast/index");
  6. exports.default = (_a = {},
  7. _a['empty'] = function (value) {
  8. if (value === undefined || value === null || value !== value) {
  9. return false;
  10. }
  11. else if (typeof value === 'string') {
  12. value = this.handle.trim(value);
  13. return value !== '';
  14. } else if (value instanceof Array) {
  15. return value.length > 0;
  16. }
  17. else {
  18. return true;
  19. }
  20. },
  21. _a['mobile'] = function (value) {
  22. if (!value || typeof value === 'object')
  23. return false;
  24. else
  25. value = String(value);
  26. return /^1\d{10}$/.test(value);
  27. },
  28. _a.verificationItem = function (data, toast) {
  29. var _a;
  30. if (data.rules !== undefined) {
  31. var resultRules = void 0;
  32. if (typeof data.rules === 'string') {
  33. resultRules = (_a = {}, _a['empty'] = data.rules, _a);
  34. }
  35. else {
  36. resultRules = data.rules;
  37. }
  38. for (var key in resultRules) {
  39. if (resultRules.hasOwnProperty(key) && this[key] && !this[key](data.value, data)) {
  40. var value = resultRules[key] || data.placeholder || data.label;
  41. if (toast) {
  42. var rulesToast = typeof toast === 'boolean' ? 'info' : toast;
  43. if (index_1.default[rulesToast]) {
  44. index_1.default[rulesToast](value);
  45. }
  46. }
  47. return {
  48. verification: false,
  49. value: value,
  50. type: key
  51. };
  52. }
  53. }
  54. return {
  55. verification: true,
  56. value: data.value
  57. };
  58. }
  59. return {
  60. verification: true,
  61. value: data.value
  62. };
  63. },
  64. _a.verification = function (data, toast) {
  65. var resultData;
  66. if (verification_1.default.isObject(data))
  67. resultData = [data];
  68. else
  69. resultData = data;
  70. var result = {};
  71. for (var i = 0, count = resultData.length; i < count; i++) {
  72. var useResult = this.verificationItem(resultData[i], toast);
  73. if (!useResult.verification) {
  74. return useResult;
  75. }
  76. else {
  77. var useKey = resultData[i].exportKey || resultData[i].key;
  78. if (useKey) {
  79. result[useKey] = useResult.value;
  80. }
  81. }
  82. }
  83. return {
  84. verification: true,
  85. value: result
  86. };
  87. },
  88. _a.verificationPromise = function (data, toast) {
  89. var _this = this;
  90. return new Promise(function (resolve, reject) {
  91. var result = _this.verification(data, toast);
  92. return result.verification ? resolve(result.value) : reject(result.value);
  93. });
  94. },
  95. _a.handle = {
  96. trim: function (value) {
  97. value = value || '';
  98. if (typeof value !== 'string')
  99. value += '';
  100. return value.replace(/^\s*|\s*$/, '');
  101. }
  102. },
  103. _a);
  104. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxxREFBZ0Q7QUFFaEQsNkNBQTZDO0FBRTdDLG1CQUFlO0lBR1gsUUFBb0IsVUFBUyxLQUFTO1FBRWxDLElBQUksS0FBSyxLQUFLLFNBQVMsSUFBSSxLQUFLLEtBQUcsSUFBSSxJQUFJLEtBQUssS0FBSyxLQUFLLEVBQUM7WUFDdkQsT0FBTyxLQUFLLENBQUM7U0FDaEI7YUFBTSxJQUFJLE9BQU8sS0FBSyxLQUFLLFFBQVEsRUFBRTtZQUVsQyxLQUFLLEdBQUcsSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7WUFFaEMsT0FBTyxLQUFLLEtBQUssRUFBRSxDQUFDO1NBRXZCO2FBQU07WUFDSCxPQUFPLElBQUksQ0FBQztTQUNmO0lBRUwsQ0FBQztJQUdELFFBQXFCLFVBQVMsS0FBUztRQUNuQyxJQUFJLENBQUMsS0FBSyxJQUFJLE9BQU8sS0FBSyxLQUFLLFFBQVE7WUFBRSxPQUFPLEtBQUssQ0FBQzs7WUFDakQsS0FBSyxHQUFHLE1BQU0sQ0FBQyxLQUFLLENBQU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G4gICAgICAgICAgICBpZiAodHlwZW9mIGRhdGEucnVsZXMgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0UnVsZXMgPSB7W0xpYlRlc3RUeXBlLmVtcHR5XTpkYXRhLnJ1bGVzfVxuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICByZXN1bHRSdWxlcyA9IGRhdGEucnVsZXM7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGZvciAobGV0IGtleSBpbiByZXN1bHRSdWxlcykge1xuXG5cbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0UnVsZXMuaGFzT3duUHJvcGVydHkoa2V5KSAmJiB0aGlzW2tleV0gJiYgIXRoaXNba2V5XShkYXRhLnZhbHVlLGRhdGEpKSB7XG5cbiAgICAgICAgICAgICAgICAgICAgbGV0IHZhbHVlID0gcmVzdWx0UnVsZXNba2V5XSB8fCBkYXRhLnBsYWNlaG9sZGVyIHx8IGRhdGEubGFiZWw7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8g5aaC5p6c5LiN6YCa6L+HLOaYr+WQpuiHquWKqOaPkOekulxuICAgICAgICAgICAgICAgICAgICBpZiAodG9hc3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBydWxlc1RvYXN0ID0gdHlwZW9mIHRvYXN0ID09PSAnYm9vbGVhbicgPyAnaW5mbycgOiB0b2FzdDtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0b2FzdE1vZGFsW3J1bGVzVG9hc3RdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdG9hc3RNb2RhbFtydWxlc1RvYXN0XSh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZlcmlmaWNhdGlvbjogZmFsc2UsXG4gICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IGtleSBhcyB1bmtub3duIGFzIExpYlRlc3RUeXBlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHJldHVybiAge1xuICAgICAgICAgICAgICAgIHZlcmlmaWNhdGlvbjp0cnVlLFxuICAgICAgICAgICAgICAgIHZhbHVlOiBkYXRhLnZhbHVlXG4gICAgICAgICAgICB9XG5cblxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuICB7XG4gICAgICAgICAgICB2ZXJpZmljYXRpb246IHRydWUsXG4gICAgICAgICAgICB2YWx1ZTpkYXRhLnZhbHVlXG4gICAgICAgIH1cblxuICAgIH0sXG5cbiAgICAvLyDmoKHpqoxcbiAgICB2ZXJpZmljYXRpb24oZGF0YSx0b2FzdDpib29sZWFufHN0cmluZyk6TGliVGVzdEl0ZW1SZXN1bHR7XG5cbiAgICAgICAgbGV0IHJlc3VsdERhdGE6TGliRGF0YUFycmF5O1xuICAgICAgICBpZiAodmVyaWZpY2F0aW9uLmlzT2JqZWN0KGRhdGEpKSByZXN1bHREYXRhID0gW2RhdGEgYXMgTGliRGF0YV07XG4gICAgICAgIGVsc2UgcmVzdWx0RGF0YSA9IGRhdGEgYXMgTGliRGF0YUFycmF5O1xuXG4gICAgICAgIGxldCByZXN1bHQ6UmVjb3JkPHN0cmluZywgYW55PiA9IHt9O1xuXG4gICAgICAgIGZvciAobGV0IGk9MCxjb3VudD1yZXN1bHREYXRhLmxlbmd0aDtpPGNvdW50O2krKykge1xuXG4gICAgICAgICAgICBsZXQgdXNlUmVzdWx0OkxpYlRlc3RJdGVtUmVzdWx0ID0gdGhpcy52ZXJpZmljYXRpb25JdGVtKHJlc3VsdERhdGFbaV0sdG9hc3QpO1xuXG4gICAgICAgICAgICBpZiAoIXVzZVJlc3VsdC52ZXJpZmljYXRpb24pIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdXNlUmVzdWx0O1xuICAgICAgICAgICAgfSBlbHNlIHtcblxuICAgICAgICAgICAgICAgIGxldCB1c2VLZXkgPSByZXN1bHREYXRhW2ldLmV4cG9ydEtleSB8fCByZXN1bHREYXRhW2ldLmtleTtcblxuICAgICAgICAgICAgICAgIGlmICh1c2VLZXkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0W3VzZUtleV0gPSB1c2VSZXN1bHQudmFsdWU7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB2ZXJpZmljYXRpb246dHJ1ZSxcbiAgICAgICAgICAgIHZhbHVlOnJlc3VsdFxuICAgICAgICB9XG5cblxuICAgIH0sXG5cbiAgICAvLyDmoKHpqozov5Tlm54gUHJvbWlzZVxuICAgIHZlcmlmaWNhdGlvblByb21pc2UoZGF0YSx0b2FzdDpib29sZWFufHN0cmluZyk6UHJvbWlzZTxSZWNvcmQ8c3RyaW5nLCBhbnk+PntcblxuICAgICAgICByZXR1cm4gIG5ldyBQcm9taXNlPFJlY29yZDxzdHJpbmcsIGFueT4+KCAocmVzb2x2ZSxyZWplY3QpPT57XG4gICAgICAgICAgICBsZXQgcmVzdWx0OkxpYlRlc3RJdGVtUmVzdWx0ID0gdGhpcy52ZXJpZmljYXRpb24oZGF0YSx0b2FzdCk7XG4gICAgICAgICAgICByZXR1cm4gcmVzdWx0LnZlcmlmaWNhdGlvbiA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IHJlamVjdChyZXN1bHQudmFsdWUpO1xuICAgICAgICB9KTtcblxuICAgIH0sXG5cblxuXG4gICAgaGFuZGxlOntcbiAgICAgICAgdHJpbTpmdW5jdGlvbih2YWx1ZTphbnkpe1xuICAgICAgICAgICAgdmFsdWUgPSB2YWx1ZSB8fCAnJztcbiAgICAgICAgICAgIGlmICh0eXBlb2YgdmFsdWUgIT09ICdzdHJpbmcnKSAgdmFsdWUgKz0nJztcbiAgICAgICAgICAgIHJldHVybiB2YWx1ZS5yZXBsYWNlKC9eXFxzKnxcXHMqJC8sJycpO1xuICAgICAgICB9XG4gICAgfVxuXG5cblxufSJdfQ==