index.js
23.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 17);
/******/ })
/************************************************************************/
/******/ ({
/***/ 17:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _WxValidate = __webpack_require__(18);
var _WxValidate2 = _interopRequireDefault(_WxValidate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var utils = __webpack_require__(19); /*
* @Description: 表单框架
* @Author: huyue
* @Date: 2023-04-28 16:19:53
* @LastEditors: huyue
* @LastEditTime: 2023-08-10 16:54:00
*/
Component({
externalClasses: ['switch-active-class', 'switch-class', 'switch-item-class', 'lable-class'],
options: {
multipleSlots: true // 复数插槽: 是
},
data: {
formDataObj: {},
formDataList: []
},
properties: {
/**
* formObj:表单数据绑定的对象
*/
formObj: {
type: Object,
value: {},
observer: function observer(n) {
this.setData({
formDataObj: n
});
}
},
/**
* formData:表单配置数据
*/
formData: {
type: Array,
value: [],
observer: function observer(n) {
console.log(n);
this.initValidate(n);
this.setData({
formDataList: n
});
}
},
/**
* inline:表单配置是否一行展示
*/
inline: {
type: Boolean,
value: true
},
/**
* themeStyle: 主题样式
*/
themeStyle: {
type: String,
value: '#3582EE'
},
textPostion: {
type: String,
value: 'right'
}
},
methods: {
// 初始化选项值
getOptionsList: function getOptionsList(optionList, refreshSigle) {
var _this = this;
console.log(optionList, refreshSigle);
if (refreshSigle) {
var _setData;
// 深拷贝传值
var cloneList = utils.deepClone(optionList[refreshSigle]);
var index = this.data.formDataList.findIndex(function (k) {
return k.name === refreshSigle;
});
this.setData((_setData = {}, _setData['formDataList[' + index + '].valueList'] = cloneList, _setData));
} else {
this.data.formDataList.forEach(function (item, index) {
if (optionList[item.name] && optionList[item.name].length) {
var _this$setData;
// 深拷贝传值
var _cloneList = utils.deepClone(optionList[item.name]);
_this.setData((_this$setData = {}, _this$setData['formDataList[' + index + '].valueList'] = _cloneList, _this$setData));
}
});
console.log(this.data.formDataList, '===');
}
},
// 表单验证规则
initValidate: function initValidate(obj) {
var rules = {};
// const messages = {}
obj.forEach(function (item) {
if (item.rules) {
rules[item.name] = item.rules;
// messages[item.name] = {
// required: item.rulesMessage || '请输入' + item.lable
// }
}
});
console.log(rules);
// console.log(messages);
this.WxValidate = new _WxValidate2.default(rules);
},
// 获取GlsxFormItem的值
getFormItemValue: function getFormItemValue(e) {
var _setData3;
// const value = this.selectComponent('#GlsxFormItem').formDataObj
console.log(e);
var _e$detail = e.detail,
name = _e$detail.name,
value = _e$detail.value,
type = _e$detail.type;
if (type === 'muiltiImg') {
var _setData2;
this.data.formDataObj[name].splice(value, 1);
this.setData((_setData2 = {}, _setData2['formDataObj.' + name] = this.data.formDataObj[name], _setData2));
return;
}
this.setData((_setData3 = {}, _setData3['formDataObj.' + name] = value, _setData3));
// 加change事件,告知表单项变化
this.triggerEvent('changeFormItem', e.detail);
},
// 验证表单数据
// eslint-disable-next-line consistent-return
validateFormData: function validateFormData() {
var params = this.data.formDataObj;
if (!this.WxValidate.checkForm(params)) {
var error = this.WxValidate.errorList;
return error;
}
},
// 返回formObj的值
returnFormObj: function returnFormObj() {
return this.data.formDataObj;
},
// select事件
customClick: function customClick(e) {
var clickName = e.detail + 'Click';
console.log(clickName);
this.triggerEvent(clickName, e.detail);
}
},
// 组件页面生周期
lifetimes: {
created: function created() {
// 在组件实例刚刚被创建时执行
// 初始化验证规则函数
this.initValidate();
}
}
});
/***/ }),
/***/ 18:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* 表单验证
*
* @param {Object} rules 验证字段的规则
* @param {Object} messages 验证字段的提示信息
*
*/
var WxValidate = function () {
function WxValidate() {
var rules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var messages = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, WxValidate);
Object.assign(this, {
data: {},
rules: rules,
messages: messages
});
this.__init();
}
/**
* __init
*/
WxValidate.prototype.__init = function __init() {
this.__initMethods();
this.__initDefaults();
this.__initData();
};
/**
* 初始化数据
*/
WxValidate.prototype.__initData = function __initData() {
this.form = {};
this.errorList = [];
};
/**
* 初始化默认提示信息
*/
WxValidate.prototype.__initDefaults = function __initDefaults() {
this.defaults = {
messages: {
required: '这是必填字段。',
email: '请输入有效的电子邮件地址。',
tel: '请输入11位的手机号码。',
url: '请输入有效的网址。',
date: '请输入有效的日期。',
dateISO: '请输入有效的日期(ISO),例如:2009-06-23,1998/01/22。',
number: '请输入有效的数字。',
digits: '只能输入数字。',
idcard: '请输入18位的有效身份证。',
equalTo: this.formatTpl('输入值必须和 {0} 相同。'),
contains: this.formatTpl('输入值必须包含 {0}。'),
minlength: this.formatTpl('最少要输入 {0} 个字符。'),
maxlength: this.formatTpl('最多可以输入 {0} 个字符。'),
rangelength: this.formatTpl('请输入长度在 {0} 到 {1} 之间的字符。'),
min: this.formatTpl('请输入不小于 {0} 的数值。'),
max: this.formatTpl('请输入不大于 {0} 的数值。'),
range: this.formatTpl('请输入范围在 {0} 到 {1} 之间的数值。')
}
};
};
/**
* 初始化默认验证方法
*/
WxValidate.prototype.__initMethods = function __initMethods() {
var that = this;
that.methods = {
/**
* 验证必填元素
*/
required: function required(value, param) {
if (!that.depend(param)) {
return 'dependency-mismatch';
} else if (typeof value === 'number') {
value = value.toString();
} else if (typeof value === 'boolean') {
return !0;
}
return value.length > 0;
},
/**
* 验证电子邮箱格式
*/
email: function email(value) {
return that.optional(value) ||
// eslint-disable-next-line no-useless-escape
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value);
},
/**
* 验证手机格式
*/
tel: function tel(value) {
return that.optional(value) || /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/.test(value);
},
/**
* 验证URL格式
*/
url: function url(value) {
return that.optional(value) ||
// eslint-disable-next-line max-len
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-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,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
},
/**
* 验证日期格式
*/
date: function date(value) {
return that.optional(value) || !/Invalid|NaN/.test(new Date(value).toString());
},
/**
* 验证ISO类型的日期格式
*/
dateISO: function dateISO(value) {
return that.optional(value) ||
// eslint-disable-next-line no-useless-escape
/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value);
},
/**
* 验证十进制数字
*/
number: function number(value) {
return that.optional(value) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
},
/**
* 验证整数
*/
digits: function digits(value) {
return that.optional(value) || /^\d+$/.test(value);
},
/**
* 验证身份证号码
*/
idcard: function idcard(value) {
return that.optional(value) || /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value);
},
/**
* 验证两个输入框的内容是否相同
*/
equalTo: function equalTo(value, param) {
return that.optional(value) || value === that.data[param];
},
/**
* 验证是否包含某个值
*/
contains: function contains(value, param) {
return that.optional(value) || value.indexOf(param) >= 0;
},
/**
* 验证最小长度
*/
minlength: function minlength(value, param) {
return that.optional(value) || value.length >= param;
},
/**
* 验证最大长度
*/
maxlength: function maxlength(value, param) {
return that.optional(value) || value.length <= param;
},
/**
* 验证一个长度范围[min, max]
*/
rangelength: function rangelength(value, param) {
return that.optional(value) || value.length >= param[0] && value.length <= param[1];
},
/**
* 验证最小值
*/
min: function min(value, param) {
return that.optional(value) || value >= param;
},
/**
* 验证最大值
*/
max: function max(value, param) {
return that.optional(value) || value <= param;
},
/**
* 验证一个值范围[min, max]
*/
range: function range(value, param) {
return that.optional(value) || value >= param[0] && value <= param[1];
}
};
};
/**
* 添加自定义验证方法
* @param {String} name 方法名
* @param {Function} method 函数体,接收两个参数(value, param),value表示元素的值,param表示参数
* @param {String} message 提示信息
*/
WxValidate.prototype.addMethod = function addMethod(name, method, message) {
this.methods[name] = method;
this.defaults.messages[name] = message !== undefined ? message : this.defaults.messages[name];
};
/**
* 判断验证方法是否存在
*/
WxValidate.prototype.isValidMethod = function isValidMethod(value) {
var methods = [];
for (var method in this.methods) {
if (method && typeof this.methods[method] === 'function') {
methods.push(method);
}
}
return methods.indexOf(value) !== -1;
};
/**
* 格式化提示信息模板
*/
WxValidate.prototype.formatTpl = function formatTpl(source, params) {
var that = this;
if (arguments.length === 1) {
return function () {
// eslint-disable-next-line prefer-rest-params
var args = Array.from(arguments);
args.unshift(source);
return that.formatTpl.apply(this, args);
};
}
if (params === undefined) {
return source;
}
if (arguments.length > 2 && params.constructor !== Array) {
// eslint-disable-next-line prefer-rest-params
params = Array.from(arguments).slice(1);
}
if (params.constructor !== Array) {
params = [params];
}
params.forEach(function (n, i) {
source = source.replace(new RegExp('\\{' + i + '\\}', 'g'), function () {
return n;
});
});
return source;
};
/**
* 判断规则依赖是否存在
*/
// eslint-disable-next-line class-methods-use-this
WxValidate.prototype.depend = function depend(param) {
switch (typeof param === 'undefined' ? 'undefined' : _typeof(param)) {
case 'boolean':
// eslint-disable-next-line no-self-assign
param = param;
break;
case 'string':
param = !!param.length;
break;
case 'function':
param = param();
// eslint-disable-next-line no-fallthrough
default:
param = !0;
}
return param;
};
/**
* 判断输入值是否为空
*/
WxValidate.prototype.optional = function optional(value) {
return !this.methods.required(value) && 'dependency-mismatch';
};
/**
* 获取自定义字段的提示信息
* @param {String} param 字段名
* @param {Object} rule 规则
*/
// eslint-disable-next-line consistent-return
WxValidate.prototype.customMessage = function customMessage(param, rule) {
var params = this.messages[param];
var isObject = (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object';
if (params && isObject) return params[rule.method];
};
/**
* 获取某个指定字段的提示信息
* @param {String} param 字段名
* @param {Object} rule 规则
*/
WxValidate.prototype.defaultMessage = function defaultMessage(param, rule) {
var message = this.customMessage(param, rule) || this.defaults.messages[rule.method];
var type = typeof message === 'undefined' ? 'undefined' : _typeof(message);
if (type === 'undefined') {
message = 'Warning: No message defined for ' + rule.method + '.';
} else if (type === 'function') {
message = message.call(this, rule.parameters);
}
return message;
};
/**
* 缓存错误信息
* @param {String} param 字段名
* @param {Object} rule 规则
* @param {String} value 元素的值
*/
WxValidate.prototype.formatTplAndAdd = function formatTplAndAdd(param, rule, value) {
var msg = this.defaultMessage(param, rule);
this.errorList.push({
param: param,
msg: msg,
value: value
});
};
/**
* 验证某个指定字段的规则
* @param {String} param 字段名
* @param {Object} rules 规则
* @param {Object} data 需要验证的数据对象
*/
WxValidate.prototype.checkParam = function checkParam(param, rules, data) {
// 缓存数据对象
this.data = data;
// 缓存字段对应的值
var value = data[param] !== null && data[param] !== undefined ? data[param] : '';
// 遍历某个指定字段的所有规则,依次验证规则,否则缓存错误信息
for (var method in rules) {
// 判断验证方法是否存在
if (this.isValidMethod(method)) {
// 缓存规则的属性及值
var rule = {
method: method,
parameters: rules[method]
};
// 调用验证方法
var result = this.methods[method](value, rule.parameters);
// 若result返回值为dependency-mismatch,则说明该字段的值为空或非必填字段
if (result === 'dependency-mismatch') {
continue;
}
this.setValue(param, method, result, value);
// 判断是否通过验证,否则缓存错误信息,跳出循环
if (!result) {
this.formatTplAndAdd(param, rule, value);
break;
}
}
}
};
/**
* 设置字段的默认验证值
* @param {String} param 字段名
*/
WxValidate.prototype.setView = function setView(param) {
this.form[param] = {
$name: param,
$valid: true,
$invalid: false,
$error: {},
$success: {},
// eslint-disable-next-line quotes
$viewValue: ''
};
};
/**
* 设置字段的验证值
* @param {String} param 字段名
* @param {String} method 字段的方法
* @param {Boolean} result 是否通过验证
* @param {String} value 字段的值
*/
WxValidate.prototype.setValue = function setValue(param, method, result, value) {
var params = this.form[param];
params.$valid = result;
params.$invalid = !result;
params.$error[method] = !result;
params.$success[method] = result;
params.$viewValue = value;
};
/**
* 验证所有字段的规则,返回验证是否通过
* @param {Object} data 需要验证数据对象
*/
WxValidate.prototype.checkForm = function checkForm(data) {
this.__initData();
// eslint-disable-next-line guard-for-in
for (var param in this.rules) {
this.setView(param);
this.checkParam(param, this.rules[param], data);
}
return this.valid();
};
/**
* 返回验证是否通过
*/
WxValidate.prototype.valid = function valid() {
return this.size() === 0;
};
/**
* 返回错误信息的个数
*/
WxValidate.prototype.size = function size() {
return this.errorList.length;
};
/**
* 返回所有错误信息
*/
WxValidate.prototype.validationErrors = function validationErrors() {
return this.errorList;
};
return WxValidate;
}();
exports.default = WxValidate;
/***/ }),
/***/ 19:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
module.exports = {
getFlag: function getFlag() {
return true;
},
deepClone: function deepClone(target) {
var map = new WeakMap();
function isObject(target) {
return (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target || typeof target === 'function';
}
function clone(data) {
if (!isObject(data)) {
return data;
}
if ([Date, RegExp].includes(data.constructor)) {
return new data.constructor(data);
}
if (typeof data === 'function') {
// eslint-disable-next-line no-new-func
return new Function('return ' + data.toString())();
}
var exist = map.get(data);
if (exist) {
return exist;
}
if (data instanceof Map) {
var _result = new Map();
map.set(data, _result);
data.forEach(function (val, key) {
if (isObject(val)) {
_result.set(key, clone(val));
} else {
_result.set(key, val);
}
});
return _result;
}
if (data instanceof Set) {
var _result2 = new Set();
map.set(data, _result2);
data.forEach(function (val) {
if (isObject(val)) {
_result2.add(clone(val));
} else {
_result2.add(val);
}
});
return _result2;
}
var keys = Reflect.ownKeys(data);
var allDesc = Object.getOwnPropertyDescriptors(data);
var result = Object.create(Object.getPrototypeOf(data), allDesc);
map.set(data, result);
keys.forEach(function (key) {
var val = data[key];
if (isObject(val)) {
result[key] = clone(val);
} else {
result[key] = val;
}
});
return result;
}
return clone(target);
}
};
/***/ })
/******/ });
//# sourceMappingURL=index.js.map