-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1235 lines (1110 loc) · 32.8 KB
/
index.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
/*!
* PHP In JS v0.1 (https://github.com/DimitriSitchet/php-in-js)
* Copyright 2021 Dimtrov Lab's | Dimitri Sitchet Tomkeu
* Licensed under MIT (https://opensource.org/licences/mit)
*/
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global = {}));
}(this, (function(exports) {
'use strict';
/**
* ========================================================
* ------------------ FONCTIONS GLOBALES ------------------
* ========================================================
*/
/**
*
* @param {*} el
* @return {Boolean}
*/
const empty = (el) => {
if (typeof el === 'undefined' || el === null) {
return true
}
if (is_string(el) && el === '') {
return true
}
if (is_array(el) && !el.length) {
return true
}
if (is_object(el) && el.constructor === Object && !Object.keys(el).length) {
return true
}
return false
}
exports.empty = empty
/**
*
* @param {*} el
* @return {Boolean}
*/
const is_callable = (el) => {
return typeof el === 'function'
}
exports.is_callable = is_callable
/**
*
* @param {*} el
* @return {Boolean}
*/
const is_bool = (el) => {
if (el === true || el === false || typeof el === 'boolean') {
return true
}
if (toString.call(el) === '[object Boolean]') {
return true
}
if (typeof el === 'object' && el !== null && typeof el.valueOf() === 'boolean') {
return true
}
return false
}
exports.is_bool = is_bool
/**
*
* @param {String} prefix
* @param {Boolean} random
* @return {String}
*/
const uniqid = (prefix, random) => {
if (empty(prefix) || !is_string(prefix)) {
prefix = ''
}
if (empty(random) || !is_bool(random)) {
random = false
}
const sec = Date.now() * 1000 + Math.random() * 1000,
id = sec.toString(16).replace(/\./g, "").padEnd(14, "0")
return prefix + id + (!random ? '' : '.' + Math.trunc(Math.random() * 100000000))
}
exports.uniqid = uniqid
/**
* ========================================================
* ------------- MANIPULATION DES DATES/HEURES -------------
* ========================================================
*/
/**
*
* @param {String} format
* @param {Integer} timestamp
* @return {String}
*
* @credit https://raw.githubusercontent.com/locutusjs/locutus/master/src/php/datetime/date.js
*/
const date = (format, timestamp) => {
// example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400)
// returns 1: '07:09:40 m is month'
// example 2: date('F j, Y, g:i a', 1062462400)
// returns 2: 'September 2, 2003, 12:26 am'
// example 3: date('Y W o', 1062462400)
// returns 3: '2003 36 2003'
// example 4: var $x = date('Y m d', (new Date()).getTime() / 1000)
// example 4: $x = $x + ''
// example 4: var $result = $x.length // 2009 01 09
// returns 4: 10
// example 5: date('W', 1104534000)
// returns 5: '52'
// example 6: date('B t', 1104534000)
// returns 6: '999 31'
// example 7: date('W U', 1293750000.82); // 2010-12-31
// returns 7: '52 1293750000'
// example 8: date('W', 1293836400); // 2011-01-01
// returns 8: '52'
// example 9: date('W Y-m-d', 1293974054); // 2011-01-02
// returns 9: '52 2011-01-02'
// test: skip-1 skip-2 skip-5
let jsdate, f
// Keep this here (works, but for code commented-out below for file size reasons)
// var tal= [];
const txtWords = [
'Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur',
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
]
// trailing backslash -> (dropped)
// a backslash followed by any character (including backslash) -> the character
// empty string -> empty string
const formatChr = /\\?(.?)/gi
const formatChrCb = function(t, s) {
return f[t] ? f[t]() : s
}
const _pad = function(n, c) {
n = String(n)
while (n.length < c) {
n = '0' + n
}
return n
}
f = {
// Day
d: function() {
// Day of month w/leading 0; 01..31
return _pad(f.j(), 2)
},
D: function() {
// Shorthand day name; Mon...Sun
return f.l()
.slice(0, 3)
},
j: function() {
// Day of month; 1..31
return jsdate.getDate()
},
l: function() {
// Full day name; Monday...Sunday
return txtWords[f.w()] + 'day'
},
N: function() {
// ISO-8601 day of week; 1[Mon]..7[Sun]
return f.w() || 7
},
S: function() {
// Ordinal suffix for day of month; st, nd, rd, th
const j = f.j()
let i = j % 10
if (i <= 3 && parseInt((j % 100) / 10, 10) === 1) {
i = 0
}
return ['st', 'nd', 'rd'][i - 1] || 'th'
},
w: function() {
// Day of week; 0[Sun]..6[Sat]
return jsdate.getDay()
},
z: function() {
// Day of year; 0..365
const a = new Date(f.Y(), f.n() - 1, f.j())
const b = new Date(f.Y(), 0, 1)
return Math.round((a - b) / 864e5)
},
// Week
W: function() {
// ISO-8601 week number
const a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3)
const b = new Date(a.getFullYear(), 0, 4)
return _pad(1 + Math.round((a - b) / 864e5 / 7), 2)
},
// Month
F: function() {
// Full month name; January...December
return txtWords[6 + f.n()]
},
m: function() {
// Month w/leading 0; 01...12
return _pad(f.n(), 2)
},
M: function() {
// Shorthand month name; Jan...Dec
return f.F()
.slice(0, 3)
},
n: function() {
// Month; 1...12
return jsdate.getMonth() + 1
},
t: function() {
// Days in month; 28...31
return (new Date(f.Y(), f.n(), 0))
.getDate()
},
// Year
L: function() {
// Is leap year?; 0 or 1
const j = f.Y()
return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0
},
o: function() {
// ISO-8601 year
const n = f.n()
const W = f.W()
const Y = f.Y()
return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0)
},
Y: function() {
// Full year; e.g. 1980...2010
return jsdate.getFullYear()
},
y: function() {
// Last two digits of year; 00...99
return f.Y()
.toString()
.slice(-2)
},
// Time
a: function() {
// am or pm
return jsdate.getHours() > 11 ? 'pm' : 'am'
},
A: function() {
// AM or PM
return f.a()
.toUpperCase()
},
B: function() {
// Swatch Internet time; 000..999
const H = jsdate.getUTCHours() * 36e2
// Hours
const i = jsdate.getUTCMinutes() * 60
// Minutes
// Seconds
const s = jsdate.getUTCSeconds()
return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3)
},
g: function() {
// 12-Hours; 1..12
return f.G() % 12 || 12
},
G: function() {
// 24-Hours; 0..23
return jsdate.getHours()
},
h: function() {
// 12-Hours w/leading 0; 01..12
return _pad(f.g(), 2)
},
H: function() {
// 24-Hours w/leading 0; 00..23
return _pad(f.G(), 2)
},
i: function() {
// Minutes w/leading 0; 00..59
return _pad(jsdate.getMinutes(), 2)
},
s: function() {
return _pad(jsdate.getSeconds(), 2)
},
u: function() {
return _pad(jsdate.getMilliseconds() * 1000, 6)
},
// Timezone
e: function() {
throw new Error('Not supported (see source code of date() for timezone on how to add support)')
},
I: function() {
// DST observed?; 0 or 1
// Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
// If they are not equal, then DST is observed.
const a = new Date(f.Y(), 0)
// Jan 1
const c = Date.UTC(f.Y(), 0)
// Jan 1 UTC
const b = new Date(f.Y(), 6)
// Jul 1
// Jul 1 UTC
const d = Date.UTC(f.Y(), 6)
return ((a - c) !== (b - d)) ? 1 : 0
},
O: function() {
const tzo = jsdate.getTimezoneOffset()
const a = Math.abs(tzo)
return (tzo > 0 ? '-' : '+') + _pad(Math.floor(a / 60) * 100 + a % 60, 4)
},
P: function() {
const O = f.O()
return (O.substr(0, 3) + ':' + O.substr(3, 2))
},
T: function() {
return 'UTC'
},
Z: function() {
return -jsdate.getTimezoneOffset() * 60
},
// Full Date/Time
c: function() {
return 'Y-m-d\\TH:i:sP'.replace(formatChr, formatChrCb)
},
r: function() {
return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb)
},
U: function() {
return jsdate / 1000 | 0
}
}
const _date = function(format, timestamp) {
jsdate = (timestamp === undefined ? new Date() // Not provided
:
(timestamp instanceof Date) ? new Date(timestamp) // JS Date()
:
new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
)
return format.replace(formatChr, formatChrCb)
}
return _date(format, timestamp)
}
exports.date = date
/**
*
* @return {Integer}
*/
const time = () => {
return Math.floor(new Date().getTime() / 1000)
}
exports.time = time
/**
* ========================================================
* --------- MANIPULATION DE CHAINES DE CARACTERES --------
* ========================================================
*/
const chunk_split = (str, length, end) => {
let temp_string = ''
for (let i = 0, size = str.length; i < size; i++) {
temp_string += str[i]
if ((i + 1) % length == 0) {
temp_string += end;
}
}
return temp_string;
}
exports.chunk_split = chunk_split
/**
*
* @param {*} el
* @return {Boolean}
*/
const is_string = (el) => {
return typeof el === 'string' || el instanceof String
}
exports.is_string = is_string
/**
*
* @param {String} str
* @return {String}
*/
const lcfirst = (str) => {
if (is_string(str)) {
return str[0].toLowerCase() + str.substr(1, str.length)
}
return str
}
exports.lcfirst = lcfirst
/**
*
* @param {String} str
* @return {String}
*/
const lcwords = (str) => {
if (is_string(str)) {
let arr = str.split(' ')
for (let i = 0, size = arr.length; i < size; i++) {
arr[i] = lcfirst(arr[i])
}
return arr.join(' ')
}
return str
}
exports.lcwords = lcwords
/**
*
* @param {String} str1
* @param {String} str2
* @return {Integer}
*/
const similar_text = (str1, str2) => {
let seen = {},
similar_count = 0;
for (let i = 0, size = str1.length; i < size; i++) {
if ((str2.indexOf(str1[i]) !== -1 && !(str1[i] in seen)) || str1[i] == ' ') {
similar_count++
if (str[i] != '') {
seen[str1[i]] = true
}
}
}
return similar_count
}
exports.similar_text = similar_text
/**
*
* @param {String} str
* @param {Integer} size
* @param {*} value
* @return {String}
*/
const str_pad = (str, size, value) => {
if (is_string(str)) {
for (let i = 0; i < size; i++) {
str += value;
}
}
return str;
}
exports.str_pad = str_pad
/**
*
* @param {String} str
* @return {Integer|null}
*/
const strlen = (str) => {
if (is_string(str)) {
return str.split('').length
}
return null
}
exports.strlen = strlen
/**
*
* @param {String} str
* @return {String}
*/
const strrev = (str) => {
if (is_string(str)) {
/*
* Ancienne version, mais ne marche pas avec les caracteres unicode
* return str.split('').reverse().join('')
*/
/**
* @credit https://github.com/mathiasbynens/esrever
*/
str = str.replace(/(<%= allExceptCombiningMarks %>)(<%= combiningMarks %>+)/g, ($0, $1, $2) => {
return strrev($2) + $1;
}).replace(/([\uD800-\uDBFF])([\uDC00-\uDFFF])/g, '$2$1')
let result = [],
index = str.length;
while (index--) {
result.push(str.charAt(index));
}
return result.join('');
}
return str
}
exports.strrev = strrev
/**
*
* @param {String} str
* @return {String}
*/
const strtolower = (str) => {
if (is_string(str)) {
return str.toLowerCase()
}
return str
}
exports.strtolower = strtolower
/**
*
* @param {String} str
* @return {String}
*/
const strtoupper = (str) => {
if (is_string(str)) {
return str.toUpperCase()
}
return str
}
exports.strtoupper = strtoupper
/**
*
* @param {String} str
* @return {String}
*/
const ucfirst = (str) => {
if (is_string(str)) {
return str[0].toUpperCase() + str.substr(1, str.length)
}
return str
}
exports.ucfirst = ucfirst
/**
*
* @param {String} str
* @return {String}
*/
const ucwords = (str) => {
if (is_string(str)) {
let arr = str.split(' ')
for (let i = 0, size = arr.length; i < size; i++) {
arr[i] = ucfirst(arr[i])
}
return arr.join(' ')
}
return str
}
exports.ucwords = ucwords
/**
* ========================================================
* ---------------- MANIPULATION DE NOMBRES ----------------
* ========================================================
*/
/**
*
* @param {*} el
* @return {Boolean}
*/
const is_int = (el) => {
return !isNaN(parseInt(el)) && isFinite(el)
}
exports.is_int = is_int
/**
*
* @param {*} el
* @return {Boolean}
*/
const is_number = (el) => {
return !isNaN(parseFloat(el)) && isFinite(el)
}
exports.is_number = is_number
/**
*
* @param {Number} min
* @param {Number} max
* @return {Integer}
*/
const rand = (min, max) => {
const argc = arguments.length
if (argc === 0) {
min = 0
max = 2147483647
} else if (argc === 1) {
throw new Error('Warning: rand() expects exactly 2 parameters, 1 given')
}
return Math.floor(Math.random() * (max - min + 1)) + min
}
exports.rand = rand
/**
* ========================================================
* --------------- MANIPULATION DE TABLEAUX ---------------
* ========================================================
*/
/**
*
* @param {Array} arr
* @param {Integer} count
* @return {Array}
*/
const array_chunk = (arr, count) => {
let temp_arr = []
for (let i = 0, size = arr.length; i < size;) {
let chunk_arr = []
for (let j = 0; j < count; j++) {
if (!arr[i]) {
break
}
chunk_arr.push(arr[i])
i++;
}
temp_arr.push(chunk_arr)
}
return temp_arr
}
exports.array_chunk = array_chunk
/**
*
* @param {...Array} arrays
* @returns
*/
const array_collapse = (...arrays) => {
let collapse_arr = []
for (let i = 0, size = arrays.length; i < size; i++) {
for (let j = 0, taille = arrays[i].length; j < taille; j++) {
collapse_arr.push(arrays[i][j])
}
}
return collapse_arr
}
exports.array_collapse = array_collapse
/**
*
* @param {Array} arr1
* @param {Array} arr2
* @return {Array}
*/
const array_diff = (arr1, arr2) => {
let temp_arr = []
for (let i = 0, size = arr1.length; i < size; i++) {
if (arr2.indexOf(arr1[i]) == -1) {
temp_arr.push(arr1[i])
}
}
return temp_arr
}
exports.array_diff = array_diff
/**
*
* @param {Array} arr1
* @param {Array} arr2
* @return {Array}
*/
const array_intersect = (arr1, arr2) => {
let temp_arr = []
for (let i = 0, size = arr1.length; i < size; i++) {
if (arr2.indexOf(arr1[i]) != -1) {
temp_arr.push(arr1[i])
}
}
return temp_arr
}
exports.array_intersect = array_intersect
/**
*
* @param {Array} arr
* @param {Callable} func
* @return {Array}
*/
const array_map = (arr, func) => {
let temp_arr = []
if (typeof func !== "function") {
throw "Second parameter should be a function"
}
for (let i = 0, size = arr.length; i < size; i++) {
temp_arr.push(func(arr[i]))
}
return temp_arr
}
exports.array_map = array_map
/**
*
* @param {...Array}
* @return {Array}
*/
const array_merge = (...arrays) => {
let args = Array.prototype.slice.call(arguments),
tab = []
for (let i = 0, size = arrays.length; i < size; i++) {
if (is_array(arrays[i])) {
tab = [...tab, ...arrays[i]]
}
}
return tab
}
exports.array_merge = array_merge
/**
*
* @param {Array} arr
* @param {Integer} size
* @param {*} value
* @return {Array}
*/
const array_pad = (arr, size, value) => {
if (!is_array(arr)) {
return arr
}
for (let i = 0; i < size; i++) {
arr.push(value)
}
return arr
}
exports.array_pad = array_pad
/**
*
* @param {Array} arr
* @return {Array}
*/
const array_pop = (arr) => {
let elt = null
if (is_array(arr)) {
elt = arr.pop()
}
return elt ? [elt, arr] : [arr]
}
exports.array_pop = array_pop
/**
*
* @param {Array} arr
* @param {*} val
* @return {Array}
*/
const array_push = (arr, val) => {
let args = Array.prototype.slice.call(arguments);
arr = args.shift()
if (is_array(arr)) {
arr.push(...args)
}
return arr
}
exports.array_push = array_push
/**
* @param {Array} array
* @param {Number} num
* @return
*/
const array_rand = (array, num) => {
let keys = Object.keys(array)
if (typeof num === 'undefined' || num === null) {
num = 1
} else {
num = +num
}
if (isNaN(num) || num < 1 || num > keys.length) {
return null
}
keys = array_suffle(keys)
return num === 1 ? keys[0] : keys.slice(0, num)
}
exports.array_rand = array_rand
/**
*
* @param {Array} arr
* @param {Callable} func
* @return {Array}
*/
const array_reject = (arr, func) => {
let temp_arr = []
if (typeof func !== "function") {
throw "Second parameter should be a function"
}
for (let i = 0, size = arr.length; i < size; i++) {
if (func(arr[i])) {
temp_arr.push(arr[i])
}
}
return temp_arr;
}
exports.array_reject = array_reject
/**
*
* @param {Array} arr
* @return {Array}
*/
const array_shift = (arr) => {
let elt = null
if (is_array(arr)) {
elt = arr.shift()
}
return elt ? [elt, arr] : [arr]
}
exports.array_shift = array_shift
const array_slice = (arr, offst, lgth, preserveKeys) => {
let key = ''
if (Object.prototype.toString.call(arr) !== '[object Array]' || (preserveKeys && offst !== 0)) {
// Assoc. array as input or if required as output
let lgt = 0
const newAssoc = {}
for (key in arr) {
lgt += 1
newAssoc[key] = arr[key]
}
arr = newAssoc
offst = (offst < 0) ? lgt + offst : offst
lgth = lgth === undefined ? lgt : (lgth < 0) ? lgt + lgth - offst : lgth
const assoc = {}
let start = false
let it = -1
let arrlgth = 0
let noPkIdx = 0
for (key in arr) {
++it
if (arrlgth >= lgth) {
break
}
if (it === offst) {
start = true
}
if (!start) {
continue
}
++arrlgth
if (is_int(key) && !preserveKeys) {
assoc[noPkIdx++] = arr[key]
}
else {
assoc[key] = arr[key]
}
}
// Make as array-like object (though length will not be dynamic)
// assoc.length = arrlgth;
return assoc
}
if (lgth === undefined) {
return arr.slice(offst)
}
else if (lgth >= 0) {
return arr.slice(offst, offst + lgth)
}
else {
return arr.slice(offst, lgth)
}
}
exports.array_slice = array_slice
/**
*
* @param {Array} arr
* @param {Integer} count
* @return {Array}
*/
const array_split = (arr, count) => {
let temp_arr = [],
arr_length = arr.length,
chunk = Math.floor(arr_length / count)
for (let i = 0, size = arr.length; i < size;) {
let chunk_arr = []
if (temp_arr.length == (count - 1)) {
chunk = chunk + (arr_length - i)
}
for (let j = 0; j < chunk; j++) {
if (!arr[i]) {
break
}
chunk_arr.push(arr[i])
i++
}
temp_arr.push(chunk_arr)
}
return temp_arr
}
exports.array_split = array_split
/**
*
* @param {Array} arr
* @return {Array}
*/
const array_suffle = (arr) => {
if (is_array(arr)) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)),
tmp = arr[i]
arr[i] = arr[j];
arr[j] = tmp;
}
}
return arr
}
exports.array_suffle = array_suffle
/**
*
* @param {Array} arr
* @param {Integer} count
* @return {Array}
*/
const array_take = (arr, count) => {
let temp_arr = []
if (count < 0) {
count = Math.abs(count)
for (let size = arr.length, i = (size - count); i < size; i++) {
temp_arr.push(arr[i])
}
} else {
for (let i = 0; i < count; i++) {
temp_arr.push(arr[i])
}
}
return temp_arr
}
exports.array_take = array_take
/**
*
* @param {Array} arr
* @return {Array}
*/
const array_unique = (arr) => {
let seen = {},
ret_arr = [],
key,
i;
function keyify(obj) {
let ret = '',
j;
if (Object.prototype.toString.call(obj) === "[object Object]" || Object.prototype.toString.call(obj) === "[object Array]") {
for (j in obj) {
ret += "~" + j + "^" + keyify(obj[j]) + "%"
}
return ret
}
return obj
}