-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathagile.js
2713 lines (2421 loc) · 70.7 KB
/
agile.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
/**
* Like Underscore, but with zero callbacks and really more fun
* @version v0.0.2 - 2015-04-14 * @link https://github.com/a8m/agile
* @author Ariel Mashraki <[email protected]>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
(function ( context, undefined ) {
'use strict';
/**
* @description
* generate error message
* @param {string} module The namespace to use for the new minErr instance.
* @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
* error from returned function, for cases when a particular type of error is useful.
* @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
*/
function minErr(module, ErrorConstructor) {
ErrorConstructor = Error;
return function (input) {
var args = Array.prototype.slice.call(arguments, 1);
var template = '[' + module + ':]' +
input.replace(/{(\d+)}/g, function (match, number) {
return isUndefined(args[number]) ? match : args[number];
});
return ErrorConstructor(template);
};
}
/**
* @private
* @description
* function that get a value and return another function
* that return this value
* @example
* 1. valueFn(function (e) { return e; })() ==> function (e) { return e }
* 2. valueFn(e)() ==> e
* @param value
* @returns {Function}
*/
function valueFn(value) {return function() {return value;};}
/**
*
* @param {Object|Array} obj Object to iterate over.
* @param {Function} iterator Iterator function.
* @param {Object=} context Object to become context (`this`) for the iterator function.
* @returns {Object|Array} Reference to `obj`.
*/
function forEach(obj, iterator, context) {
var key, length;
if (obj) {
if (isFunction(obj)) {
for (key in obj) {
// Need to check if hasOwnProperty exists,
// as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
iterator.call(context, obj[key], key, obj);
}
}
} else if (isArray(obj) || isArrayLike(obj)) {
var isPrimitive = typeof obj !== 'object';
for (key = 0, length = obj.length; key < length; key++) {
if (isPrimitive || key in obj) {
iterator.call(context, obj[key], key, obj);
}
}
} else if (obj.forEach && obj.forEach !== forEach) {
obj.forEach(iterator, context, obj);
} else {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key, obj);
}
}
}
}
return obj;
}
/**
* @description
* return the first n element of an array,
* if expression provided, is returns as long the expression return truthy
* @param array
* @param n {number}
* @param expression {$parse}
* @return array or single object
*/
function getFirstMatches(array, n, expression) {
var count = 0;
return array.filter(function(elm) {
var rest = isDefined(expression) ? (count < n && expression(elm)) : count < n;
count = rest ? count+1 : count;
return rest;
});
}
/**
* @description
* gets method name, array and expression
* @param method {String}
* @param array {Array}
* @param exp {String} expression to parse
* @returns {Number}
*/
function indexByMath(method, array, exp) {
var mappedArray = array.map(function(elm){
return $parse(exp)(elm);
});
return mappedArray.indexOf(Math[method].apply(Math, mappedArray));
}
//Parse Dependencies
var $parseMinErr = minErr('$parse');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var NODE_TYPE_ELEMENT = 1;
/**
* @param {*} obj
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments, String ...)
*/
function isArrayLike(obj) {
if (obj == null || isWindow(obj)) {
return false;
}
var length = obj.length;
if (obj.nodeType === NODE_TYPE_ELEMENT && length) {
return true;
}
return isString(obj) || isArray(obj) || length === 0 ||
typeof length === 'number' && length > 0 && (length - 1) in obj;
}
/**
* @private
* @param obj
* @returns {*|boolean}
*/
function isWindow(obj) {
return obj && obj.window === obj;
}
/**
* @description
* Iterate over the given array and return the first member that the getterFn
* returns true, if `isIndex` set to `true`, return the index.
* @param array
* @param getterFn
* @param isIndex
* @returns {*}
*/
function findInArray(array, getterFn, isIndex) {
var index = -1;
var res;
while(++index < array.length) {
if(getterFn(array[index])) {
res = isIndex ? index : array[index];
break;
}
}
return res;
}
/**
* @name after-where
* @kind function
*
* @description
* get a an array and $parse:expression, and returns all of the items
* in the array after the first that return true, include it.
*
*/
function afterWhere(array, exp) {
if(!isArray(array) || isUndefined(exp))
return array;
var index = array.map(function(elm) {
return $parse(exp)(elm);
}).indexOf(true);
return array.slice((index === -1) ? 0 : index);
}
/**
* @name after
* @kind function
*
* @description
* get an array and specified count, and returns all of the items
* in the collection after the specified count.
*/
function after(array, count) {
return (isArray(array))
? array.slice(count)
: array;
}
/**
* @ngdoc filter
* @name before-where
* @kind function
*
* @description
* get an array and $parse:expression, and returns all of the items
* in the array before the first that return true.
*/
function beforeWhere(array, exp) {
if(!isArray(array) || isUndefined(exp))
return array;
var index = array.map(function(elm) {
return $parse(exp)(elm);
}).indexOf(true);
return array.slice(0, (index === -1) ? array.length : ++index);
}
/**
* @name before
* @kind function
*
* @description
* get a array and specified count, and returns all of the items
* in the array before the specified count.
*/
function before(array, count) {
return isArray(array)
? array.slice(0, (!count) ? count : --count)
: array;
}
/**
* @name contains
* @kind function
*
* @description
* Checks if given exp is present in one or more object in the array
* aliases: _.some
*/
function contains(array, exp) {
if(!isArray(array) || isUndefined(exp)) {
return true;
}
return array.some(function(elm) {
return (isObject(elm) || isFunction(exp))
? $parse(exp)(elm)
: elm === exp;
});
}
/**
* @name countBy
* @kind function
*
* @description
* Gets an array and $parse:expression,
* and returns a count for the number of objects in each group.
*/
function countBy(array, exp) {
var result = {},
prop;
if(!isArray(array) || isUndefined(exp)) {
return array;
}
array.forEach( function(elm) {
prop = $parse(exp)(elm);
if(!result[prop]) {
result[prop] = 0;
}
result[prop]++;
});
return result;
}
/**
* @name defaults
* @kind function
*
* @description
* defaults allows to specify a default fallback value for properties that resolve to undefined.
*/
function defaults(array, defaults) {
if(!isArray(array) || !isObject(defaults)) {
return array;
}
//get defaults keys(include nested).
var keys = deepKeys(defaults);
array.forEach(function(elm) {
//loop through all the keys
keys.forEach(function(key) {
var getter = $parse(key);
var setter = getter.assign;
//if it's not exist
if(isUndefined(getter(elm))) {
//get from defaults, and set to the returned object
setter(elm, getter(defaults))
}
});
});
return array;
}
/**
* @name every
* @kind function
*
* @description
* Checks if given exp is present in all members in the array
*/
function every(array, exp) {
if(!isArray(array) || isUndefined(exp)) {
return true;
}
return array.every(function(elm) {
return (isObject(elm) || isFunction(exp))
? $parse(exp)(elm)
: elm === exp;
});
}
/**
* @name filter
* @kind function
*
* @description
* filter by $parse:expression,
* return all elements that return true, avoid the rest
*/
function filter(array, exp) {
if(!isArray(array) || isUndefined(exp)) {
return array;
}
return array.filter(function(elm) {
return (isObject(elm) || isFunction(exp))
? $parse(exp)(elm)
: elm === exp;
});
}
/**
* @name findIndex
* @kind function
*
* @description
* Iterate over the given array and return the index of the first member that the expression
* returns truthy for
*/
function findIndex(array, exp) {
return (isArray(array) && isDefined(exp))
//return the the index of the member
? findInArray(array, $parse(exp), true)
: array;
}
/**
* @name findLastIndex
* @kind function
*
* @description
* Iterate over the given array and return the index of the last member that the expression
* returns truthy for
*/
function findLastIndex(array, exp) {
if(!isArray(array) || isUndefined(exp)) {
return array;
}
//return the the index of the last member
var index = (array.length - 1) - findInArray(reverse(array), $parse(exp), true);
//if it's a NaN
return index === index ? index : -1;
}
/**
* @name findLast
* @kind function
*
* @description
* Iterate over the given array and return the last member that the expression
* returns truthy for,
*/
function findLast(array, exp) {
return (isArray(array) && isDefined(exp))
//return the member and not an array like `last`
? findInArray(reverse(array), $parse(exp), false)
: array;
}
/**
* @name find
* @kind function
*
* @description
* Iterate over the given array and return the first member that the expression
* returns truthy for,
*/
function find(array, exp) {
return (isArray(array) && isDefined(exp))
//return the member and not an array like `first`
? findInArray(array, $parse(exp), false)
: array;
}
/**
* @name first
* @kind function
*
* @description
* Gets the first element or first `n` elements of an array
* if expression is provided, is returns as long the expression return truthy
*/
function first(array) {
var n,
getter,
args;
if(!isArray(array)) {
return array;
}
args = Array.prototype.slice.call(arguments, 1);
n = (isNumber(args[0])) ? args[0] : 1;
getter = (!isNumber(args[0])) ? args[0] : (!isNumber(args[1])) ? args[1] : undefined;
return (args.length)
? getFirstMatches(array, n,(getter) ? $parse(getter) : getter)
: array[0];
}
/**
* @name flatten
* @kind function
*
* @description
* Flattens a nested array (the nesting can be to any depth).
* If shallow, the array will only be flattened a one level
*/
function flatten(array, shallow) {
shallow = shallow || false;
if(!isArray(array)) {
return array;
}
return !shallow
? depthFlatten(array, 0)
: [].concat.apply([], array);
}
/**
* flatten nested array (the nesting can be to any depth).
* @param array {Array}
* @param i {int}
* @returns {Array}
* @private
*/
function depthFlatten(array, i) {
i = i || 0;
if(i >= array.length)
return array;
if(isArray(array[i])) {
return depthFlatten(array.slice(0,i)
.concat(array[i], array.slice(i+1)), i);
}
return depthFlatten(array, i+1);
}
/**
* @name groupBy
* @kind function
*
* @description
* Create an object composed of keys generated from the result of running each element of a array,
* each key is an array contains the results members.
*/
function groupBy(array, property) {
var result = {},
prop,
getter = $parse(property);
if(!isArray(array) || isUndefined(property)) {
return array;
}
forEach(array, function(elm) {
prop = getter(elm);
if(!result[prop]) {
result[prop] = [];
}
result[prop].push(elm);
});
return result;
}
/**
* @name last
* @kind function
*
* @description
* Gets the last element or last n elements of an array
* if expression is provided, is returns as long the expression return truthy
*/
function last(array) {
var n,
getter,
args,
reversed;
if(!isArray(array)) {
return array;
}
//cuz reverse change our src array
//and we don't want side effects
reversed = array.slice();
args = Array.prototype.slice.call(arguments, 1);
n = (isNumber(args[0])) ? args[0] : 1;
getter = (!isNumber(args[0])) ? args[0] : (!isNumber(args[1])) ? args[1] : undefined;
return (args.length)
//send reversed array as arguments, and reverse it back as result
? getFirstMatches(reversed.reverse(), n,(getter) ? $parse(getter) : getter).reverse()
//get the last element
: reversed[reversed.length-1];
}
/**
* @name map
* @kind function
*
* @description
* Returns a new Array with the results of each expression execution.
*/
function map(array, expression) {
if(!isArray(array) || isUndefined(expression)) {
return array;
}
return array.map(function (elm) {
return $parse(expression)(elm);
});
}
/**
* @name max
* @kind function
*
* @description
* Math.max will get an array return the max value. if an expression
* is provided, will return max value by expression.
*/
function max(input, expression) {
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? Math.max.apply(Math, input)
: input[indexByMath('max', input, expression)]
}
/**
* @ngdoc filter
* @name min
* @kind function
*
* @description
* Math.min will get an array return the min value. if an expression
* is provided, will return min value by expression.
*/
function min(input, expression) {
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? Math.min.apply(Math, input)
: input[indexByMath('min', input, expression)]
}
/**
* @name omit
* @kind function
*
* @description
* get an array, and return a new array without the omitted objects(by expression).
*/
function omit(array, exp) {
if(!isArray(array) || isUndefined(exp)) {
return array;
}
return array.filter(function(elm) {
return (isObject(elm) || isFunction(exp))
? !$parse(exp)(elm)
: elm !== exp;
});
}
/**
* @name orderBy
* @kind function
* fork of AngularJS#orderByFilter
*
* @description
* Orders a specified array by the expression predicate.
* It is ordered alphabetically for strings and numerically for numbers.
*/
function orderBy(array, sortPredicate, reverseOrder) {
if (!isArrayLike(array)) {
return array;
}
sortPredicate = isArray(sortPredicate) ? sortPredicate : [sortPredicate];
if (sortPredicate.length === 0) { sortPredicate = ['+']; }
sortPredicate = sortPredicate.map(function(predicate) {
var descending = false;
var get = predicate || value;
if (isString(predicate)) {
if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {
descending = predicate.charAt(0) == '-';
predicate = predicate.substring(1);
}
if (predicate === '') {
// Effectively no predicate was passed so we compare identity
return reverseComparator(function(a, b) {
return compare(a, b);
}, descending);
}
get = $parse(predicate);
if (get.constant) {
var key = get();
return reverseComparator(function(a, b) {
return compare(a[key], b[key]);
}, descending);
}
}
return reverseComparator(function(a, b) {
return compare(get(a),get(b));
}, descending);
});
var arrayCopy = [];
for (var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
return arrayCopy.sort(reverseComparator(comparator, reverseOrder));
function comparator(o1, o2) {
for (var i = 0; i < sortPredicate.length; i++) {
var comp = sortPredicate[i](o1, o2);
if (comp !== 0) break;
}
return comp;
}
function reverseComparator(comp, descending) {
return descending
? function(a, b) {return comp(b,a);}
: comp;
}
function compare(v1, v2) {
var t1 = typeof v1;
var t2 = typeof v2;
if (t1 == t2) {
if (isDate(v1) && isDate(v2)) {
v1 = v1.valueOf();
v2 = v2.valueOf();
}
if (t1 == "string") {
v1 = v1.toLowerCase();
v2 = v2.toLowerCase();
}
if (v1 === v2) return 0;
return v1 < v2 ? -1 : 1;
} else {
return t1 < t2 ? -1 : 1;
}
}
}
/**
* @name remove
* @kind function
*
* @description
* remove specific members from array by equality
*/
function remove(array) {
var args = Array.prototype.slice.call(arguments, 1);
if(!isArray(array) || isEmpty(args)) {
return array;
}
return array.filter(function(member) {
return !args.some(function(nest) {
return equals(nest, member);
})
});
}
/**
* @name reverse
* @kind function
*
* @description
* Reverses a string or collection
*/
function reverse(input) {
if(isString(input)) {
return input.split('').reverse().join('');
}
return (isArray(input))
? input.slice().reverse()
: input;
}
/**
* @name sum
* @kind function
*
* @description
* Sum up all values within an array
*/
function sum(input, initial) {
return (!isArray(input)) ? input :
input.reduce(function(prev, curr) {
return prev + curr;
}, initial || 0);
}
/**
* @name unique/uniq
* @kind function
*
* @description
* get array and filter duplicate members
* if uniqueFilter get a property(nested to) as argument it's
* filter by this property as unique identifier
*/
function unique(array, property) {
if (!isArray(array)) {
return array;
}
//store all unique identifiers
var uniqueItems = [],
get = $parse(property);
return (isUndefined(property)) ?
//if it's kind of primitive array
array.filter(function (elm, pos, self) {
return self.indexOf(elm) === pos;
}) :
//else compare with equals
array.filter(function (elm) {
var prop = get(elm);
if(some(uniqueItems, prop)) {
return false;
}
uniqueItems.push(prop);
return true;
});
//checked if the unique identifier is already exist
function some(array, member) {
if(isUndefined(member)) {
return false;
}
return array.some(function(el) {
return equals(el, member);
});
}
}
/**
* @name xor
* @kind function
*
* @description
* Exclusive or filter by expression
*/
function xor(col1, col2, expression) {
expression = expression || false;
if(!isArray(col1) || !isArray(col2)) return col1;
return col1.concat(col2)
.filter(function(elm) {
return !(some(elm, col1) && some(elm, col2));
});
function some(el, col) {
var getter = $parse(expression);
return col.some(function(dElm) {
return expression
? equals(getter(dElm), getter(el))
: equals(dElm, el);
});
}
}
// AngularJS Boolean
/**
* @description
* Determines if a reference is a `String`.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `String`.
*/
function isString(value){return typeof value === 'string';}
/**
* @description
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
* considered to be objects. Note that JavaScript arrays are objects.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Object` but not `null`.
*/
function isObject(value){
// http://jsperf.com/isobject4
return value !== null && typeof value === 'object';
}
/**
* @description
* Determines if a reference is a `Number`.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Number`.
*/
function isNumber(value){return typeof value === 'number';}
/**
* @description
* Determines if a reference is undefined.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is undefined.
*/
function isUndefined(value){return typeof value === 'undefined';}
/**
* @description
* Determines if a reference is defined.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is defined.
*/
function isDefined(value){return typeof value !== 'undefined';}
/**
* @description
* Determines if a value is a date.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Date`.
*/
function isDate(value) {
var toString = (value).toString;
return toString.call(value) === '[object Date]';
}
/**
* @description
* Determines if a reference is an `Array`.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Array`.
*/
var isArray = Array.isArray;
/**
* @description
* Determines if a reference is a `Function`.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Function`.
*/
function isFunction(value){return typeof value === 'function';}
/**
* @description
* Determines if a value is a regular expression object.
* @private
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `RegExp`.
*/
function isRegExp(value) {
return toString.call(value) === '[object RegExp]';
}
/**
* @description
* get Array or String and return if is empty
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a Empty.
*/
function isEmpty(value) {
return (isString(value) || isArray(value)) ? !value.length : false;
}
/**
* @description
* Determines if a reference is a `Boolean`.
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Boolean`.
*/
function isBoolean(value){return typeof value === 'boolean';}
//these methods is kind of common methods for chaining wrappers
/**
* @description
* add methods get an object extend(based on type) and return it.
* @param object
* @returns {*}
* @example
* add(1,2) ==> 3
* add([],1) ==> [1]
* add('f','g') ==> 'fg'
* add({}, {a:1}) ==> {a:1}
*/
function add(object) {
var args = Array.prototype.slice.call(arguments, 1);
//loop through all over the arguments
forEach(args, function(value, i) {
switch(typeof object) {
case 'object':
isArray(object)
? object.push(value)
: extend(object, isObject(value) ? value : creObject(i, value));
break;
case 'string':
object += isString(value) ? value : '';
break;
case 'number':
object += isNumber(value) ? value : 0;
}
});
return object;
}
/**
* @private
* @description
* return an object that index is the key
* @param i {Index}
* @param value
* @returns {Object}
*/
function creObject(i, value) {
var o = {};
o[i] = value;
return o;
}
/**
* @description
* get object and return it's keys,
* if deep set to true, it will return it deeply.
* @param obj {Object}
* @param deep {Boolean}
*/
function objKeys(obj, deep) {
return isObject(obj)
? (deep) ? deepKeys(obj) : Object.keys(obj)
: obj;
}
/**
* @description
* Get an object, and return an array composed of it's properties names(nested too).
* @param obj {Object}
* @param stack {Array}
* @param parent {String}
* @returns {Array}
* @example
* deepKeys({ a:1, b: { c:2, d: { e: 3 } } }) ==> ["a", "b.c", "b.d.e"]
*/
function deepKeys(obj, stack, parent) {
stack = stack || [];