-
Notifications
You must be signed in to change notification settings - Fork 0
/
pado.js
4700 lines (4147 loc) · 128 KB
/
pado.js
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.pado = factory());
}(this, function () { 'use strict';
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
if (i % 2) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(arguments[i]));
}
}
return target;
}
var isAbsoluteNaN = function isAbsoluteNaN(it) {
// eslint-disable-next-line no-self-compare
return it !== it && typeof it === "number";
};
var isNone = function isNone(data) {
return isAbsoluteNaN(data) || data === undefined || data === null;
};
var isInfinity = function isInfinity(it) {
return it === Number.POSITIVE_INFINITY || it === Number.NEGATIVE_INFINITY;
};
var isNumber = function isNumber(it) {
return typeof it === "number" && !isInfinity(it) && !isAbsoluteNaN(it);
};
var isInteger = function isInteger(value) {
//NaN, null, undefined
if (isNone(value) === true) return false;
if (typeof value === "string") {
value = value.trim();
}
if (!/string|number/.test(typeof value) || isInfinity(value) || isNaN(value)) {
return false;
}
return value == parseInt(value, 10);
};
var isArray = function isArray(data) {
return Array.isArray(data) || data instanceof Array;
};
var isObject = function isObject(it) {
return !!(it !== null && typeof it === "object");
};
var isFunction = function isFunction(it) {
return typeof it === "function";
};
/*
* likeObject is have hasOwnProperty
*/
var likeObject = function likeObject(it) {
return isObject(it) || isFunction(it);
};
var likeString = function likeString(data) {
if (typeof data === "string") return true;
if (isNumber(data)) return true;
return false;
};
var likeNumber = function likeNumber(data) {
if (isNumber(data)) return true;
if (typeof data === "string") return String(parseFloat(data)) === String(data);
return false;
};
var likeArray = function likeArray(item) {
return Array.isArray(item) || item !== null && typeof item === "object" && item.hasOwnProperty("length") && typeof item.length === "number" && item.length > 0;
};
var isPlainObject = function isPlainObject(data) {
return typeof data === "object" && data.constructor === Object;
};
var isEnumerableObject = function isEnumerableObject(data) {
return isPlainObject(data) || isArray(data);
};
var isNode = function isNode(a) {
return isObject(a) && typeof a.nodeType === "number";
};
var isEmpty = function isEmpty(it) {
if (typeof it === "undefined") return true;
if (typeof it === "string") return it.trim().length < 1;
if (typeof it === "object") {
if (it == null) return true;
if (it instanceof RegExp) return false;
if (isArray(it)) {
return !it.length;
} else {
for (var prop in it) {
return false;
}
return true;
}
}
if (typeof it === "number") {
//NaN check
return isAbsoluteNaN(it) || false;
}
if (typeof it === "function") return false;
if (typeof it === "boolean") return false;
return true;
}; // check JSON, input.value possible value
var isPresence = function isPresence(it) {
return !(it === undefined || isAbsoluteNaN(it));
};
var likeRegexp = function likeRegexp(s) {
return typeof s === "string" || s instanceof RegExp;
}; // none(undfinec, null, NaN), value(1,"1"), hash({}), array([]), node, object(new, Date), function, boolean
var eqof = function eqof(it) {
var typeIt = typeof it;
switch (typeIt) {
case "number":
if (isAbsoluteNaN(it)) return "none";
case "string":
return "value";
break;
case "object":
if (isNone(it)) return "none";
if (likeArray(it)) return "array";
if (isNode(it)) return "node";
if (!isPlainObject(it)) return "object";
return "hash";
break;
case "undefined":
return "none";
break;
case "function":
case "boolean":
default:
return typeIt;
break;
}
};
var baseEq = function baseEq(value, other, filter, depth, strict) {
if (depth === void 0) {
depth = 0;
}
if (arguments.length < 2) return false;
var valueType = eqof(value);
var otherType = eqof(other);
if (valueType !== otherType) return false;
switch (valueType) {
case "none":
return true;
case "array":
if (value.length !== other.length) {
return false;
}
return value.every(function (vValue, i) {
var oValue = other[i];
return typeof filter === "function" && filter(i, [vValue, oValue], depth) === false ? true : baseEq(vValue, oValue, filter, depth + 1, strict);
});
break;
case "hash":
var vKeys = Object.keys(value);
var oKeys = Object.keys(other);
if (vKeys.length !== oKeys.length || !baseEq(vKeys.sort(), oKeys.sort())) return false;
return vKeys.every(function (key) {
var vValue = value[key];
var oValue = other[key];
return typeof filter === "function" && filter(key, [vValue, oValue], depth) === false ? true : baseEq(vValue, oValue, filter, depth + 1, strict);
});
break;
case "node":
case "object":
case "function":
case "boolean":
case "value":
default:
return strict ? value === other : value == other;
}
};
var isEqual = function isEqual(value, other, filter, depth) {
return baseEq(value, other, filter, depth, true);
};
var likeEqual = function likeEqual(value, other, filter, depth) {
return baseEq(value, other, function (key, values, depth) {
return /^(\$|\_)/.test(key) ? false : typeof filter === "function" ? filter(key, values, depth) : true;
}, depth, true);
};
var eqeq = function eqeq(value, other, filter, depth) {
return baseEq(value, other, filter, depth, false);
};
var isExsist = function isExsist(value) {
if (value === true) {
return true;
}
if (value === false) {
return false;
}
if (typeof value === "string" || typeof value === "number") {
return true;
} else {
return false;
}
};
var notExsist = function notExsist(value) {
return !isExsist(value);
};
var likePromise = function likePromise(target) {
return typeof target === "object" && target !== null && typeof target['then'] === "function" && typeof target['catch'] === "function";
};
var baseAsArray = function baseAsArray(data, defaultArray) {
if (defaultArray === void 0) {
defaultArray = undefined;
}
if (isArray(data)) {
return data;
}
if (isNone(data)) {
return isArray(defaultArray) ? defaultArray : isNone(defaultArray) ? [] : [defaultArray];
}
if (typeof data === "object" && typeof data.toArray === "function") {
return data.toArray();
}
return [data];
};
var stringTest = function stringTest(string, rule, meta) {
if (!likeString(string)) return false;
if (typeof rule === "undefined") return true;
return typeof rule === "function" ? Boolean(rule(string, meta)) : likeString(rule) ? (string + '').indexOf(rule + '') > -1 : rule instanceof RegExp ? rule.test(string) : isArray(rule) ? rule.some(function (filterKey) {
return filterKey === string;
}) : false;
}; //remark.spec.js
var matchString = function matchString(it, search, at) {
if (at === void 0) {
at = 0;
}
if (typeof it !== "string") throw new Error("matchString :: worng argument " + it);
if (typeof search === "string") search = search.replace(new RegExp("(\\.|\\[|\\])", "g"), function (s) {
return "\\" + s;
});
var result = it.substr(at).match(search);
return result ? [result.index + at, result[0].length] : [-1, 0];
};
var baseKeys = function baseKeys(target, filterExp, strict) {
var result = [];
if (!likeObject(target)) {
return result;
}
if (strict === true ? isArray(target) : likeArray(target)) {
Object.keys(target).filter(function (key) {
if (isNaN(key)) return;
var numberKey = parseInt(key, 10);
stringTest(numberKey, filterExp, target[key]) && result.push(parseInt(numberKey, 10));
});
} else if (strict === true ? isPlainObject(target) : likeObject(target)) {
Object.keys(target).forEach(function (key) {
stringTest(key, filterExp, target[key]) && result.push(key);
});
}
return result;
};
var baseEntries = function baseEntries(it) {
var result = [];
switch (typeof it) {
case "object":
// eslint-disable-next-line no-unused-expressions
isNone(it) ? 0 : likeArray(it) ? baseAsArray(it).forEach(function (v, k) {
result.push([k, v]);
}) : Object.keys(it).forEach(function (key) {
result.push([key, it[key]]);
});
break;
}
return result;
};
var asArray = baseAsArray;
var toArray = function toArray(data, option) {
if (typeof data === "undefined" || data === null || isAbsoluteNaN(data)) return [];
if (isArray(data)) return Array.prototype.slice.call(data);
if (typeof data === "object" && typeof data.toArray === "function") return data.toArray();
if (typeof data === "string" && typeof option === "string") return data.split(option);
return [data];
};
var asObject = function asObject(data, defaultKey) {
if (defaultKey === void 0) {
defaultKey = "default";
}
if (isPlainObject(data)) {
return data;
} else {
var _ref;
return _ref = {}, _ref[defaultKey] = data, _ref;
}
};
var toNumber = function toNumber(v, d) {
switch (typeof v) {
case "number":
return v;
case "string":
var vr = v.replace(/[^.\d\-]/g, "") * 1;
return isAbsoluteNaN(vr) ? 0 : vr;
break;
}
switch (typeof d) {
case "number":
return d;
case "string":
var dr = d * 1;
return isAbsoluteNaN(dr) ? 0 : dr;
break;
}
return 0;
};
var cleanObject = function cleanObject(data) {
if (data instanceof Array) {
Array.prototype.splice.call(data, 0, data.length);
} else if (typeof data == "object") {
Object.keys(data).forEach(function (key) {
delete data[key];
});
}
return data;
};
var clone = function clone(target) {
switch (typeof target) {
case "undefined":
case "function":
case "boolean":
case "number":
case "string":
return target;
break;
case "object":
if (target === null) return target;
if (isArray(target)) {
var _r = [];
for (var i = 0, length = target.length; i < length; i++) {
_r.push(target[i]);
}
return _r;
}
if (!isPlainObject(target)) {
if (target instanceof Date) {
var _r2 = new Date();
_r2.setTime(target.getTime());
return _r2;
}
return target;
}
var r = {};
Object.keys(target).forEach(function (k) {
if (target.hasOwnProperty(k)) r[k] = target[k];
});
return r;
break;
default:
console.error("clone::copy failed : target => ", target);
return target;
break;
}
};
var cloneDeep = function cloneDeep(target) {
if (typeof target === "object") {
var d;
if (isArray(target)) {
if (!isArray(d)) {
d = [];
}
for (var i = 0, l = target.length; i < l; i++) {
d.push(typeof target[i] === "object" && target[i] !== null ? clone(target[i]) : target[i]);
}
return d;
} else {
d = {};
Object.keys(target).forEach(function (p) {
typeof target[p] === "object" && target[p] !== null && d[p] ? clone(target[p], d[p]) : d[p] = target[p];
});
return d;
}
} else {
return clone(target);
}
};
var getKeyWithValue = function getKeyWithValue(obj, value) {
if (isArray(obj)) {
for (var i = 0, l = obj.length; i < l; i++) {
if (obj[i] === value) return i;
}
}
if (isObject(obj)) {
for (var key in obj) {
if (obj[key] === value) return key;
}
}
return undefined;
};
var removeValue = function removeValue(obj, value) {
var detect = true;
var array = isArray(obj);
while (detect) {
var key = getKeyWithValue(obj, value);
if (typeof key === "undefined") {
detect = false;
} else {
if (array) {
obj.splice(key, 1);
} else {
delete obj[key];
}
}
}
return obj;
}; // Only one unique value is left.
var unique = function unique(array, findKey) {
var result = [];
var uniqueSet = new Set();
if (typeof findKey === "undefined") {
findKey = function findKey(v) {
return v;
};
}
if (typeof findKey === "string") {
var keyPath = findKey;
findKey = function findKey(v) {
return v[keyPath];
};
}
array.forEach(function (v) {
var key = findKey(v);
if (uniqueSet.has(key)) return;
uniqueSet.add(key);
result.push(v);
});
return result;
};
var getKeyBy = function getKeyBy(object, value) {
if (isFunction(value)) {
if (isArray(object)) for (var i = 0, l = object.length; i < l; i++) {
if (value(object[i], i) === true) return i;
}
if (isObject(object)) for (var key in object) {
if (value(object[key], key) === true) return key;
}
} else {
if (isArray(object)) for (var i = 0, l = object.length; i < l; i++) {
if (object[i] === value) return i;
}
if (isObject(object)) for (var key in object) {
if (object[key] === value) return key;
}
}
}; // Change the positions of the specified indexes in the array
var moveOf = function moveOf(data, oldIndex, newIndex) {
data = asArray(data);
oldIndex !== newIndex && isNumber(oldIndex) && isNumber(newIndex) && oldIndex >= 0 && oldIndex < data.length && Array.prototype.splice.call(data, newIndex > data.length ? data.length : newIndex, 0, Array.prototype.splice.call(data, oldIndex, 1)[0]);
return data;
};
var move = function move(data, oldIndex, newIndex) {
return moveOf(toArray(data), oldIndex, newIndex);
}; // Supports self concat.
var baseConcatOf = function baseConcatOf(data, args) {
var result = asArray(data);
return args.forEach(function (data) {
asArray(data).forEach(function (value) {
result.push(value);
});
}), result;
};
var concatOf = function concatOf(data) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return baseConcatOf(data, args);
};
var concat = function concat(data) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
return baseConcatOf(toArray(data), args);
}; // Removes the value of data that does not return a positive value to the filter function.
var filterOf = function filterOf(data, filterFn, exitFn) {
var dataArray = asArray(data);
var dataKeys = baseKeys(data);
var isOnExit = typeof exitFn === "function";
var exitArray = isOnExit ? [] : null;
for (var i = 0, removedIndex = 0, l = dataKeys.length; i < l; i++, removedIndex++) {
var datumKey = dataKeys[i];
var datum = dataArray[datumKey];
if (filterFn(datum, datumKey) !== true) {
var exitDatum = dataArray.splice(i, 1);
i--;
l--;
isOnExit && exitArray.push([removedIndex, exitDatum]);
}
}
isOnExit && exitFn(exitArray, dataArray);
return dataArray;
};
var filter = function filter(data, func, exitFn) {
return filterOf(toArray(data), func, exitFn);
}; // Put the specified value in the specified index.
var insertOf = function insertOf(data, v, a) {
data = asArray(data);
return data.splice(typeof a === "number" ? a : 0, 0, v), data;
};
var insert = function insert(data, v, a) {
return insertOf(toArray(data), v, a);
}; // Removes all contents of an array or object.
var clearOf = function clearOf(data, fillFn, sp) {
if (isArray(data)) {
sp = Array.prototype.splice.call(data, 0, data.length);
} else if (typeof data == "object") {
sp = {};
for (var key in data) {
sp[key] = data[key];
delete data[key];
}
}
return fillFn && fillFn(data, sp), data;
}; // sort
var sortOf = function sortOf(data, filter) {
if (data.length == 0) {
return data;
}
switch (filter) {
case 'desc':
filter = function filter(a, b) {
return a > b;
};
break;
case undefined:
case 'asc':
default:
if (typeof filter !== "function") {
filter = function filter(a, b) {
return a < b;
};
}
break;
}
var result = [data[0]];
for (var i = 1, l = data.length; i < l; i++) {
for (var ri = 0, rl = result.length; ri < rl; ri++) {
if (filter(data[i], result[ri]) === true) {
insertOf(result, data[i], ri);
break;
}
if (ri + 1 === result.length) {
result.push(data[i]);
}
}
}
clearOf(data);
for (var i = 0, l = result.length; i < l; data.push(result[i]), i++) {
}
return data;
};
var sort = function sort(data, filter) {
return sortOf(toArray(data), filter);
}; // If have defined multiple key names in one hash, change them appropriately.
// rebase({ "a,b":1 }) => { "a":1, "b":1 }
var rebase = function rebase(obj, ref) {
var result = {};
for (var key in obj) {
if (key === ".*") {
var refValue = obj[key];
for (var i = 0, d = Object.keys(ref), l = d.length; i < l; i++) {
var refKey = d[i];
if (typeof refValue === "function") {
result[refKey] = obj[key];
} else {
if (typeof refValue !== "object" && typeof refValue !== "object" || isNode(refValue)) {
result[refKey] = refValue;
} else {
result[refKey] = Object.assign(result[refKey], refValue);
}
}
}
} else if (key.indexOf(",") > -1) {
key.split(",").forEach(function (deepKey) {
deepKey = deepKey.trim();
if (typeof obj[key] === "function") {
result[deepKey] = obj[key];
} else {
if (!result.hasOwnProperty(deepKey) && typeof obj[key] !== "object" || isNode(obj[key])) {
result[deepKey] = obj[key];
} else {
result[deepKey] = Object.assign(result[deepKey] || (isArray(obj[key]) ? [] : {}), obj[key], obj[deepKey]);
}
}
});
} else {
if (typeof obj[key] === "function") {
result[key] = obj[key];
} else {
if (typeof result[key] !== "object" && typeof obj[key] !== "object" || isNode(obj[key])) {
result[key] = obj[key];
} else {
result[key] = Object.assign(result[key], obj[key]);
}
}
}
}
return result;
};
var removeKey = function removeKey(datum, rule) {
if (!isObject(datum)) return datum;
var removeRule = typeof rule === "function" ? function (key, value) {
return rule(value, key);
} : rule;
var removeKeys = baseKeys(datum, removeRule);
if (!removeKeys.length) return datum;
isArray(datum) ? removeKeys.forEach(function (originalIndex, offset) {
var removeIndex = originalIndex - offset;
datum.splice(removeIndex, 1);
}) : removeKeys.forEach(function (key) {
delete datum[key];
});
return datum;
}; // If the rule matches the rule, remove the key
var omitOf = function omitOf(datum, rule) {
return removeKey(datum, rule);
};
var omit = function omit(datum, rule) {
return omitOf(clone(datum), rule);
}; // If the rule matches the rule, preserve the key.
var pickOf = function pickOf(datum, rule) {
return removeKey(datum, function (value, key) {
return !stringTest(key, rule, value);
});
};
var pick = function pick(datum, rule) {
return pickOf(clone(datum), rule);
}; // Remove the key that has a value of undefined
//const COMPACT_MATCH_FN = value=>typeof value !== "undefined"
var COMPACT_MATCH_FN = function COMPACT_MATCH_FN(value) {
return typeof value === "undefined";
};
var compactOf = function compactOf(datum) {
return omitOf(datum, COMPACT_MATCH_FN);
};
var compact = function compact(datum) {
return compactOf(clone(datum));
}; // Clears key values starting with $
var FREE_MATCH_EXPRESSION = /^\$/;
var freeOf = function freeOf(datum) {
return omitOf(datum, FREE_MATCH_EXPRESSION);
};
var free = function free(datum) {
return freeOf(clone(datum));
}; // Remove the key that begins with $ or has a value of undefined.
var purgeOf = function purgeOf(datum) {
return omitOf(datum, function (value, key) {
return FREE_MATCH_EXPRESSION.test(key) || COMPACT_MATCH_FN(value);
});
};
var purge = function purge(datum) {
return purgeOf(clone(datum));
};
/* Experimental
export const injectOf = (data,injectFn)=>keys(data).reduce((dest, key)=>((dest[key] = injectFn(dest[key], key)), dest),asObject(data))
export const inject = (data, injectFn)=>injectOf(clone(data), injectFn);
export const mapOf = (data, mapFn)=>asArray(data).map(mapFn);
export const map = (data, mapFn)=>mapOf(clone(data), mapFn);
*/
//
var instance = function instance(func, proto) {
var ins;
var DummyInstance = function DummyInstance(param) {
if (typeof param === "object") for (var k in param) {
this[k] = param[k];
}
};
if (typeof func == "object") {
if (typeof proto === "object") DummyInstance.prototype = proto;
ins = new DummyInstance(func);
}
if (typeof func == "function") {
if (typeof proto === "object") func.prototype = proto;
ins = new func();
}
return ins;
};
var alloc = function alloc(init) {
var fn = init();
var rn = function rn() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return fn.apply(this, args);
};
rn['reset'] = function () {
fn = init(rn, rn);
};
rn['$constructor'] = fn;
return rn;
}; // TODO
/*
const syncData = (function (){
const ENTER_HOOK = (newDatum)=>Object.assign({}, newDatum)
const UPDATE_HOOK = (oldDatum, newDatum)=>Object.assign({}, oldDatum, newDatum)
return function (oldData, newData, getId, options){
if(!/string|function/.test(typeof getId)) throw new Error("syncData need getId")
if(typeof getId === "string"){
const getIdString = getId
getId = e=>_.get(e, getIdString)
}
oldData = asArray(oldData)
newData = asArray(newData)
const result = []
const hooks = asObject(options, "afterEach")
if(typeof hooks["enter"] !== "function"){
hooks["enter"] = ENTER_HOOK
}
if(typeof hooks["update"] !== "function"){
hooks["update"] = UPDATE_HOOK
}
const oldDataMap = _.map(oldData, e=>{
return { id: getId(e), ref: e }
})
asArray(newData).forEach((newDatum, i)=>{
const newId = getId(newDatum)
let oldDatum = _.get(oldDataMap[_.findIndex(oldDataMap, e=>e.id === newId)], "ref")
let genDatum
let dirty = false
// eslint-disable-next-line no-undef
if(oldDatum){
// change is not dirty, modify is dirty
if(typeof oldDatum !== typeof newDatum){
dirty = false
} else { // same type
const oldOwnKeys = Object.keys(oldDatum).filter(key=>!(key.indexOf("$") === 0))
const newOwnKeys = Object.keys(newDatum).filter(key=>!(key.indexOf("$") === 0))
// inspect key chnage
if(_.isEqual(oldOwnKeys, newOwnKeys)){
dirty = !_.isEqual(_.pick(oldDatum, oldOwnKeys), _.pick(newDatum, newOwnKeys))
} else {
dirty = true
}
}
if(typeof hooks["beforeUpdate"] === "function"){
if(hooks["beforeUpdate"](oldDatum, newDatum) === false){
return
}
}
genDatum = hooks["update"](oldDatum, newDatum)
if(typeof hooks["afterUpdate"] === "function"){
genDatum = hooks["afterUpdate"](genDatum, oldDatum, newDatum)
}
} else {
if(typeof hooks["beforeEnter"] === "function"){
if(hooks["beforeEnter"](newDatum) === false){
return
}
}
genDatum = hooks["enter"](newDatum)
if(typeof hooks["afterEnter"] === "function"){
genDatum = hooks["afterEnter"](genDatum, newDatum)
}
}
if(typeof hooks["afterEach"] === "function"){
hooks["afterEach"](genDatum, i, dirty)
}
result.push(genDatum)
})
return result
}
}())
*/
var baseCaseSplit = function baseCaseSplit(s) {
s = s.replace(/^\#/, "").trim();
var e = s.split(/\s+/);
if (e.length > 1) return e;
var k = s.split(/\-+/);
if (k.length > 1) return k;
var _ = s.split(/\_+/);
if (_.length > 1) return _;
return s.replace(/[A-Z][a-z]/g, function (s) {
return "%@" + s;
}).replace(/^\%\@/, "").split("%@");
};
var pascalCase = function pascalCase(string, joinString) {
if (joinString === void 0) {
joinString = "";
}
var words = baseCaseSplit(string);
for (var i = 0, l = words.length; i < l; i++) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase();
}
return words.join(joinString);
};
var camelCase = function camelCase(string, joinString) {
if (joinString === void 0) {
joinString = "";
}
var pascalCaseString = pascalCase(string, joinString);
return "" + (pascalCaseString.substr(0, 1) || '').toLowerCase() + (pascalCaseString.substr(1) || '');
};