-
Notifications
You must be signed in to change notification settings - Fork 208
/
md-variables.json
1718 lines (1718 loc) · 57.7 KB
/
md-variables.json
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
{
"just-cartesian-product": {
"packageName": "just-cartesian-product",
"dir": "array-cartesian-product",
"description": "Takes an input of an array of arrays and returns their Cartesian product.",
"examples": [
"import cartesianProduct from 'just-cartesian-product';",
"",
"cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]",
"cartesianProduct([[1, 2], ['a', 'b', 'c']]); // [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']]",
"cartesianProduct([]); // []",
"cartesianProduct(); // throws"
]
},
"just-compact": {
"packageName": "just-compact",
"dir": "array-compact",
"description": "Returns a copy of an array with falsey values removed",
"examples": [
"import compact from 'just-compact';",
"",
"compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5]",
"compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}]",
"compact([]); // []",
"compact({}); // throws"
]
},
"just-flatten-it": {
"packageName": "just-flatten-it",
"dir": "array-flatten",
"description": "Return a flattened array",
"examples": [
"import flatten from 'just-flatten-it';",
"",
"flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]);",
"// [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"",
"flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1);",
"// [1, [2, 3], [[4, 5], 6, 7, [8, 9]]]"
]
},
"just-group-by": {
"packageName": "just-group-by",
"dir": "array-group-by",
"description": "Return a grouped object from array",
"examples": [
"import groupBy from 'just-group-by';",
"",
"groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] }",
"groupBy([1,2,3,4,5,6,7,8], function(i) { return i % 2}); // { '0': [2, 4, 6, 8], '1': [1, 3, 5, 7] }"
]
},
"just-index": {
"packageName": "just-index",
"dir": "array-index",
"description": "Return an object from an array, keyed by the value at the given id",
"examples": [
"import index from 'just-index';",
"",
"index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id');",
"// {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}}",
"index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}}",
"index([], 'id'); // {}",
"index([], null); // undefined",
"index({}, 'id'); // undefined"
]
},
"just-insert": {
"packageName": "just-insert",
"dir": "array-insert",
"description": "Inserts a sub-array into an array starting at the given index. Returns a copy",
"examples": [
"import insert from 'just-insert';",
"",
"insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6]",
"insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6]",
"insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6]",
"insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6]"
]
},
"just-intersect": {
"packageName": "just-intersect",
"dir": "array-intersect",
"description": "Return the intersect of two arrays",
"examples": [
"import intersect from 'just-intersect';",
"",
"intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6]",
"intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5] "
]
},
"just-last": {
"packageName": "just-last",
"dir": "array-last",
"description": "Return the last member of an array",
"examples": [
"import last from 'just-last';",
"",
"last([1, 2, 3, 4, 5]); // 5",
"last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1}",
"last([true, false, [true, false]]); // [true, false]",
"last(); // undefined",
"last([]); // undefined",
"last(null); // undefined",
"last(undefined); // undefined"
]
},
"just-mean": {
"packageName": "just-mean",
"dir": "array-mean",
"description": "The mean (average) value in an array",
"examples": [
"import mean from 'just-mean';",
"",
"mean([1, 2, 3, 2, 4, 1]); // 2.1666666667",
"mean(3, 2, 1); // 2",
"mean([4]); // 4",
"mean(['3', 2]); // throws",
"mean(); // throws"
]
},
"just-median": {
"packageName": "just-median",
"dir": "array-median",
"description": "Return the median value of an array of numbers",
"examples": [
"import median from 'just-median';",
"",
"median([1, 2, 3, 4, 5]); // 3",
"median([3, -1, 2]); // 2",
"median([9, 14, 14, 200, 15]); // 14",
"median(1, 2, 4, 3); // 2.5",
"median(['3', 2, 1]); // throws",
"median(); // throws"
]
},
"just-mode": {
"packageName": "just-mode",
"dir": "array-mode",
"description": "Return the most frequently occuring number(s)",
"examples": [
"import mode from 'just-mode';",
"",
"mode([1, 2, 3, 2]); // 2",
"mode(4, 4, 1, 4); // 4",
"mode(100, 100, 101, 101); // [100, 101]",
"mode(4, 3, 2, 1); // [1, 2, 3, 4]",
"mode(['1', 2, 2, 1, 2]); // throws",
"mode(null); // throws"
]
},
"just-order-by": {
"packageName": "just-order-by",
"dir": "array-order-by",
"description": "Produces a new array, sorted in given order",
"examples": [
"import orderBy from 'just-order-by';",
"",
"orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]",
"",
"orderBy(",
" [",
" { user: 'fabio', details: { city: 'Milan', age: 34 } },",
" { user: 'max', details: { city: 'Munich', age: 29 } },",
" { user: 'zacarias', details: { city: 'Sao Paulo', age: 44 } },",
" { user: 'robert', details: { city: 'Manchester', age: 28 } },",
" { user: 'max', details: { city: 'Zurich', age: 38 } },",
" ],",
" [",
" {",
" property(v) {",
" return v.details.age;",
" },",
" },",
" ]",
");",
"",
"/*",
"[",
" {user: 'robert', age: 28},",
" {user: 'max', age: 29},",
" {user: 'fabio', age: 34},",
" {user: 'klaus', age: 38},",
" {user: 'zacarias', age: 44},",
"]",
"*/",
"",
"orderBy(",
" [",
" {user: 'fabio', age: 34},",
" {user: 'max', age: 29},",
" {user: 'zacarias', age: 44},",
" {user: 'robert', age: 28},",
" {user: 'klaus', age: 38},",
" ],",
" [",
" {",
" property: 'user',",
" },",
" ]",
");",
"",
"/*",
"[",
" {user: 'fabio', age: 34},",
" {user: 'klaus', age: 38},",
" {user: 'max', age: 29},",
" {user: 'robert', age: 28},",
" {user: 'zacarias', age: 44},",
"]",
"*/",
"",
"orderBy(",
" [",
" { user: 'fabio', age: 34 },",
" { user: 'max', age: 29 },",
" { user: 'zacarias', age: 44 },",
" { user: 'moris', age: 28 },",
" { user: 'max', age: 38 },",
" ],",
" [",
" {",
" property: 'user',",
" order: 'desc',",
" },",
" {",
" property(v) {",
" return v.age;",
" },",
" },",
" ]",
");",
"",
"/*",
"[",
" {",
" user: 'zacarias',",
" age: 44",
" },",
" {",
" user: 'moris',",
" age: 28",
" },",
" {",
" user: 'max',",
" age: 29",
" },",
" {",
" user: 'max',",
" age: 38",
" },",
" {",
" user: 'fabio',",
" age: 34",
" }",
"]",
"*/"
]
},
"just-partition": {
"packageName": "just-partition",
"dir": "array-partition",
"description": "Elements satisfying predicate added to first array, remainder added to second",
"examples": [
"import partition from 'just-partition';",
"",
"partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]]",
"partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]]",
"partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]]",
"partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]]",
"partition([], n => n > 3); // [[], []]",
"partition({a: 1, b: 2}, n => n > 1); // throws",
"partition(null, n => n > 1); // throws",
"partition(undefined, n => n > 1); // throws"
]
},
"just-percentile": {
"packageName": "just-percentile",
"dir": "array-percentile",
"description": "Return the value at the given percentile (using linear interpolation)",
"examples": [
"import percentile from 'just-percentile';",
"",
"percentile([1, 2, 3], 0); // 1",
"percentile([1, 2, 3], 0.5); // 2",
"percentile([1, 2, 3], 1); // 3",
"",
"// See https://en.wikipedia.org/wiki/Percentile (linear interpolation method)",
"percentile([15, 20, 35, 40, 50], 0.05); // 15",
"percentile([15, 20, 35, 40, 50], 0.3); // 20",
"percentile([15, 20, 35, 40, 50], 0.4); // 27.5",
"percentile([15, 20, 35, 40, 50], 0.95); // 50",
"",
"percentile(1, 2, 3, 50); // throws",
"percentile(['1', 2, 3], 50); // throws",
"percentile([], 50); // throws"
]
},
"just-permutations": {
"packageName": "just-permutations",
"dir": "array-permutations",
"description": "Returns all permutations of the length N of the elements of the given Array",
"examples": [
"import permutations from 'just-permutations';",
"",
"permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]",
"permutations([]); // []",
"permutations(); // throws"
]
},
"just-pipe": {
"packageName": "just-pipe",
"dir": "function-pipe",
"description": "Pass a value through a pipeline of functions",
"examples": [
"import pipe from 'just-pipe",
"",
"pipe(3, a => a+1, b => b*2) // 8",
"pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]) // 'Smith'"
]
},
"just-random": {
"packageName": "just-random",
"dir": "array-random",
"description": "Return a randomly selected element in an array",
"examples": [
"import random from 'just-random';",
"",
"random([1, 2, 3]);",
"// one of [1, 2, 3], at random"
]
},
"just-range": {
"packageName": "just-range",
"dir": "array-range",
"description": "Generate a range array for numbers",
"examples": [
"import range from 'just-range';",
"",
"range(1, 5); // [1, 2, 3, 4]",
"range(5); // [0, 1, 2, 3, 4]",
"range(-5); // [0, -1, -2, -3, -4]",
"range(0, 20, 5) // [0, 5, 10, 15]"
]
},
"just-remove": {
"packageName": "just-remove",
"dir": "array-remove",
"description": "Removes one array from another",
"examples": [
"import remove from 'just-remove';",
"",
"remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5]"
]
},
"just-shuffle": {
"packageName": "just-shuffle",
"dir": "array-shuffle",
"description": "Return the elements of an array in random order",
"examples": [
"import shuffle from 'just-shuffle';",
"",
"shuffle([1, 2, 3]); ",
"// array with original elements randomly sorted",
"shuffle([1, 2, 3], {shuffleAll: true}); ",
"// array with original elements randomly sorted and all in new postions",
"shuffle([]); // []",
"shuffle([1]); // [1]",
"shuffle(); // throws",
"shuffle(undefined); // throws",
"shuffle(null); // throws",
"shuffle({}); // throws"
]
},
"just-skewness": {
"packageName": "just-skewness",
"dir": "array-skewness",
"description": "Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient",
"examples": [
"import skewness from \"just-skewness\";",
"",
"// Using Pearson's second skewness coefficient",
"skewness(3, 2, 1); // 0",
"skewness([1, 2, 3, 2, 4, 1]); // 0.4276994613841504",
"skewness(1, 2, 3, 4, 5, -6); // -0.762000762001143",
"skewness([1, 2, 3, 4, 9]); // 0.7705935588815224",
"skewness([4]); // throws",
"skewness([\"3\", 2]); // throws",
"skewness(NaN, NaN); // throws",
"skewness(); // throws"
]
},
"just-sort-by": {
"packageName": "just-sort-by",
"dir": "array-sort-by",
"description": "Produces a new array, sorted in ascending order",
"examples": [
"import sortBy from 'just-sort-by';",
"",
"sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]",
"",
"sortBy([",
" {user: 'fabio', details: {city: \"Milan\", age: 34}},",
" {user: 'max', details: {city: \"Munich\", age: 29}},",
" {user: 'zacarias', details: {city: \"Sao Paulo\", age: 44}},",
" {user: 'robert', details: {city: \"Manchester\", age: 28}},",
" {user: 'klaus', details: {city: \"Zurich\", age: 38}},",
"], function(o) {",
" return o.details.age;",
"});",
"",
"/*",
"[",
" {user: 'robert', age: 28},",
" {user: 'max', age: 29},",
" {user: 'fabio', age: 34},",
" {user: 'klaus', age: 38},",
" {user: 'zacarias', age: 44},",
"]",
"*/",
"",
"sortBy([",
" {user: 'fabio', age: 34},",
" {user: 'max', age: 29},",
" {user: 'zacarias', age: 44},",
" {user: 'robert', age: 28},",
" {user: 'klaus', age: 38},",
"], 'user');",
"/*",
"[",
" {user: 'fabio', age: 34},",
" {user: 'klaus', age: 38},",
" {user: 'max', age: 29},",
" {user: 'robert', age: 28},",
" {user: 'zacarias', age: 44},",
"]",
"*/"
]
},
"just-split": {
"packageName": "just-split",
"dir": "array-split",
"description": "Splits array into groups of n items each",
"examples": [
"import split from 'just-split';",
"",
"split([]); // []",
"split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]]",
"split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]",
"split([1, 2, 3, 4, 5, 6, 7, 8, 9], '3'); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]",
"split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']]",
"split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]"
]
},
"just-split-at": {
"packageName": "just-split-at",
"dir": "array-split-at",
"description": "Splits an array into two at a given position",
"examples": [
"import splitAt from 'just-split-at';",
"",
"splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]]",
"splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]]",
"splitAt([], 2); // [[], []]",
"splitAt(null, 1); // throws",
"splitAt(undefined, 1); // throws"
]
},
"just-standard-deviation": {
"packageName": "just-standard-deviation",
"dir": "array-standard-deviation",
"description": "Return the standard deviation of an array or numeric argument list",
"examples": [
"import standardDeviation from \"just-standard-deviation\";",
"",
"standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519",
"standardDeviation(3, 2, 1); // 1",
"standardDeviation([100, 100, 100.1, 100]); // 0.05",
"standardDeviation(1, 2, 3, 4, 5, -6); // 3.9370039",
"standardDeviation([4]); // throws",
"standardDeviation([\"3\", 2]); // throws",
"standardDeviation(NaN, NaN); // throws",
"standardDeviation(); // throws"
]
},
"just-tail": {
"packageName": "just-tail",
"dir": "array-tail",
"description": "Return all but the first element of an array",
"examples": [
"import tail from 'just-tail';",
"",
"tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5]",
"tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}]",
"tail([true, false, [true, false]]); // [false, [true, false]]",
"tail([]); // []",
"tail(); // undefined",
"tail(null); // undefined",
"tail(undefined); // undefined"
]
},
"just-union": {
"packageName": "just-union",
"dir": "array-union",
"description": "Returns the union of two arrays",
"examples": [
"import union from 'just-union';",
"",
"union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4]"
]
},
"just-unique": {
"packageName": "just-unique",
"dir": "array-unique",
"description": "Dedupes an array",
"examples": [
"import unique from 'just-unique';",
"",
"unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4]",
"",
"var a = {a: 3};",
"var b = {b: 4};",
"var c = {c: 5};",
"unique([a, a, b, c, b]); // [a, b, c]",
"",
"unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3]",
"",
"// declaring sorted array for performance",
"unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6']",
"",
"// declaring strings array for performance",
"unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c']"
]
},
"just-variance": {
"packageName": "just-variance",
"dir": "array-variance",
"description": "Return the standard deviation of an array or numeric argument list",
"examples": [
"import variance from 'just-variance';",
"",
"variance([1, 2, 3, 2, 4, 1]); // 1.3666666667",
"variance(3, 2, 1); // 1",
"variance([100, 100, 100.1, 100]); // 0.0025",
"variance(1, 2, 3, 4, 5, -6); // 15.5",
"variance([4]); // throws",
"variance(['3', 2]); // throws",
"variance(NaN, NaN); // throws",
"variance(); // throws"
]
},
"just-zip-it": {
"packageName": "just-zip-it",
"dir": "array-zip",
"description": "Returns an array of grouped elements, taking n-th element from every given array",
"examples": [
"import zip from 'just-zip-it';",
"",
"zip([1, 2, 3]); // [[1], [2], [3]]",
"zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]",
"zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]]",
"",
"zip(undefined, {}, false, 1, 'foo'); // []",
"zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // [[1, 'a'], [2, 'b']]",
"",
"zip([1, 2, 3], ['a', 'b'], [true]); // [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]]"
]
},
"just-clone": {
"packageName": "just-clone",
"dir": "collection-clone",
"description": "Deep copies objects, arrays, maps and sets",
"examples": [
"// Deep copies objects and arrays, doesn't clone functions",
"",
"import clone from 'just-clone';",
"",
"var arr = [1, 2, 3];",
"var subObj = { aa: 1 };",
"var obj = { a: 3, b: 5, c: arr, d: subObj };",
"var objClone = clone(obj);",
"arr.push(4);",
"objClone.d.bb = 2;",
"obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}}",
"objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}"
]
},
"just-compare": {
"packageName": "just-compare",
"dir": "collection-compare",
"description": "Compare two collections",
"examples": [
"import compare from 'just-compare';",
"",
"// primitives: value1 === value2",
"// functions: value1.toString == value2.toString",
"// arrays: if length, sequence and values of properties are identical",
"// objects: if length, names and values of properties are identical",
"compare([1, [2, 3]], [1, [2, 3]]); // true",
"compare([1, [2, 3], 4], [1, [2, 3]]); // false",
"compare({a: 2, b: 3}, {a: 2, b: 3}); // true",
"compare({a: 2, b: 3}, {b: 3, a: 2}); // true",
"compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false",
"compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false",
"compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false",
"compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true",
"compare(NaN, NaN); // true"
]
},
"just-diff": {
"packageName": "just-diff",
"dir": "collection-diff",
"description": [
"Return an object representing the difference between two other objects",
"Pass converter to format as http://jsonpatch.com"
],
"examples": [
"import {diff} from 'just-diff';",
"",
"const obj1 = {a: 4, b: 5};",
"const obj2 = {a: 3, b: 5};",
"const obj3 = {a: 4, c: 5};",
"",
"diff(obj1, obj2);",
"[",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }",
"]",
"",
"diff(obj2, obj3);",
"[",
" { \"op\": \"remove\", \"path\": ['b'] },",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 4 }",
" { \"op\": \"add\", \"path\": ['c'], \"value\": 5 }",
"]",
"",
"// using converter to generate jsPatch standard paths",
"import {diff, jsonPatchPathConverter} from 'just-diff'",
"diff(obj1, obj2, jsonPatchPathConverter);",
"[",
" { \"op\": \"replace\", \"path\": '/a', \"value\": 3 }",
"]",
"",
"diff(obj2, obj3, jsonPatchPathConverter);",
"[",
" { \"op\": \"remove\", \"path\": '/b' },",
" { \"op\": \"replace\", \"path\": '/a', \"value\": 4 }",
" { \"op\": \"add\", \"path\": '/c', \"value\": 5 }",
"]",
"",
"// arrays",
"const obj4 = {a: 4, b: [1, 2, 3]};",
"const obj5 = {a: 3, b: [1, 2, 4]};",
"const obj6 = {a: 3, b: [1, 2, 4, 5]};",
"",
"diff(obj4, obj5);",
"[",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }",
" { \"op\": \"replace\", \"path\": ['b', 2], \"value\": 4 }",
"]",
"",
"diff(obj5, obj6);",
"[",
" { \"op\": \"add\", \"path\": ['b', 3], \"value\": 5 }",
"]",
"",
"// nested paths",
"const obj7 = {a: 4, b: {c: 3}};",
"const obj8 = {a: 4, b: {c: 4}};",
"const obj9 = {a: 5, b: {d: 4}};",
"",
"diff(obj7, obj8);",
"[",
" { \"op\": \"replace\", \"path\": ['b', 'c'], \"value\": 4 }",
"]",
"",
"diff(obj8, obj9);",
"[",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 5 }",
" { \"op\": \"remove\", \"path\": ['b', 'c']}",
" { \"op\": \"add\", \"path\": ['b', 'd'], \"value\": 4 }",
"]"
]
},
"just-diff-apply": {
"packageName": "just-diff-apply",
"dir": "collection-diff-apply",
"description": "Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com standard patch",
"examples": [
" import {diffApply} from 'just-diff-apply';",
"",
" const obj1 = {a: 3, b: 5};",
" diffApply(obj1,",
" [",
" { \"op\": \"remove\", \"path\": ['b'] },",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 4 },",
" { \"op\": \"add\", \"path\": ['c'], \"value\": 5 }",
" ]",
" );",
" obj1; // {a: 4, c: 5}",
"",
" const obj2 = {a: 3, b: 5};",
" diffApply(obj2,",
" [",
" { \"op\": \"move\", \"from\": ['a'], \"path\": ['c']},",
" ]",
" );",
" obj2; // {b: 5, c: 3}",
"",
" // using converter to apply jsPatch standard paths",
" // see http://jsonpatch.com",
" import {diffApply, jsonPatchPathConverter} from 'just-diff-apply'",
" const obj3 = {a: 3, b: 5};",
" diffApply(obj3, [",
" { \"op\": \"remove\", \"path\": '/b' },",
" { \"op\": \"replace\", \"path\": '/a', \"value\": 4 }",
" { \"op\": \"add\", \"path\": '/c', \"value\": 5 }",
" ], jsonPatchPathConverter);",
" obj3; // {a: 4, c: 5}",
"",
" // arrays (array key can be string or numeric)",
" const obj4 = {a: 4, b: [1, 2, 3]};",
" diffApply(obj4, [",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }",
" { \"op\": \"replace\", \"path\": ['b', 2], \"value\": 4 }",
" { \"op\": \"add\", \"path\": ['b', 3], \"value\": 9 }",
" ]);",
" obj4; // {a: 3, b: [1, 2, 4, 9]}",
"",
" // nested paths",
" const obj5 = {a: 4, b: {c: 3}};",
" diffApply(obj5, [",
" { \"op\": \"replace\", \"path\": ['a'], \"value\": 5 }",
" { \"op\": \"remove\", \"path\": ['b', 'c']}",
" { \"op\": \"add\", \"path\": ['b', 'd'], \"value\": 4 }",
" ]);",
" obj5; // {a: 5, b: {d: 4}}"
]
},
"just-flush": {
"packageName": "just-flush",
"dir": "collection-flush",
"description": "Returns a copy of an array or object with null/undefined members removed",
"examples": [
"import flush from 'just-flush';",
"",
"flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0]",
"flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]]",
"flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4}",
"flush('something'); // undefined",
"flush(); // undefined"
]
},
"just-pluck-it": {
"packageName": "just-pluck-it",
"dir": "collection-pluck",
"description": "Pluck a property from each member of a collection",
"examples": [
"import pluck from 'just-pluck-it';",
"",
"pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2]",
"pluck({x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}}, 'a'); // {x: 1, y: 4, z: 2}"
]
},
"just-compose": {
"packageName": "just-compose",
"dir": "function-compose",
"description": "Return a function composed of 2 or more functions",
"examples": [
"import compose from 'just-compose';",
"",
"const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc);",
"sqRootBiggest(10, 5); // 3",
"sqRootBiggest(7, 0, 16); // 4"
]
},
"just-curry-it": {
"packageName": "just-curry-it",
"dir": "function-curry",
"description": "Return a curried function",
"examples": [
"import curry from 'just-curry-it';",
"",
"function add(a, b, c) {",
" return a + b + c;",
"}",
"curry(add)(1)(2)(3); // 6",
"curry(add)(1)(2)(2); // 5",
"curry(add)(2)(4, 3); // 9",
"",
"function add(...args) {",
" return args.reduce((sum, n) => sum + n, 0)",
"}",
"var curryAdd4 = curry(add, 4)",
"curryAdd4(1)(2, 3)(4); // 10",
"",
"function converter(ratio, input) {",
" return (input*ratio).toFixed(1);",
"}",
"const curriedConverter = curry(converter)",
"const milesToKm = curriedConverter(1.62);",
"milesToKm(35); // 56.7",
"milesToKm(10); // 16.2"
]
},
"just-debounce-it": {
"packageName": "just-debounce-it",
"dir": "function-debounce",
"description": "Return a debounced function",
"examples": [
"import debounce from \"just-debounce-it\";",
"",
"const fn1 = debounce(() => console.log(\"Hello\"), 500);",
"fn1();",
"fn1();",
"fn1();",
"// 500ms later logs 'hello' once",
"",
"const fn2 = debounce(() => console.log(\"Hello\"), 500, true);",
"fn2(); // logs hello immediately",
"fn2();",
"fn2();",
"// 500ms later logs 'hello' once",
"",
"const fn3 = debounce(() => console.log(\"Hello\"), 500);",
"fn3();",
"fn3();",
"fn3();",
"fn3.cancel();",
"// function cancelled before 'hello' is logged",
"",
"const fn4 = debounce(() => console.log(\"Hello\"), 500);",
"fn4();",
"fn4();",
"fn4();",
"fn4.flush();",
"// immediately invoke the debounced function"
]
},
"just-demethodize": {
"packageName": "just-demethodize",
"dir": "function-demethodize",
"description": "Turn a method into a standalone function; the first arg becomes `this`",
"examples": [
"import demethodize from 'just-demethodize';",
"",
"const trimFn = demethodize(''.trim);",
"['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again']"
]
},
"just-flip": {
"packageName": "just-flip",
"dir": "function-flip",
"description": "Flip first two arguments of a function",
"examples": [
"import flip from 'just-flip';",
"",
"flip(console.log)(1, 2, 3) // 2, 1, 3",
"",
"import map from 'just-map-object';",
"import partial from 'just-partial';",
"",
"const numbers = {x: 5, y: 10};",
"const flippedMap = flip(map);",
"const double = partial(flippedMap, (undefined, number) => number * 2);",
"double(numbers) // {x: 10, y: 20];"
]
},
"just-memoize": {
"packageName": "just-memoize",
"dir": "function-memoize",
"description": "An implementation of the memoize technique",
"examples": [
"import memoize from 'just-memoize';",
"",
"const sumByOne = memoize(function(value) {",
" return value + 1;",
"});",
"",
"sumByOne(10); // Returns value returned by the function",
"sumByOne(10); // Cache hit!",
"",
"sumByOne(20); // Returns value returned by the function",
"sumByOne(20); // Cache hit!",
"",
"// Custom cache key (key defaults to JSON stringified arguments)",
"var sum = memoize(function(a, b) {",
" return a + b;",
"}, function(a, b) {",
" return `${a}-${b}`;",
"});",
"",
"sum(10, 10); // Returns value returned by the function",
"sum(10, 20); // Returns value returned by the function",
"sum(10, 20); // Cache hit!"
]
},
"just-memoize-last": {
"packageName": "just-memoize-last",
"dir": "function-memoize-last",
"description": "A memoize implementation that only caches the most recent evaluation",
"examples": [
"const memoizeLast = require('just-memoize-last')",
"const compare = require('just-compare')",
"",
"const maxValue = memoizeLast(function(arr) {",
" return Math.max(...arr)",
"}, function(a, b) {",
" return compare(a, b)",
"});",
"",
"maxValue([1,2,3]) // 3",
"maxValue([1,2,3]) // cache hit!",
"maxValue([1,3,4]) // 4",
"maxValue([1,2,3]) // 3"
]
},
"just-once": {
"packageName": "just-once",
"dir": "function-once",
"description": "Create a function that can only be invoked once",
"examples": [
"import once from 'just-once';",
"",
"const fn = once(() => console.log('hello'));",
"",
"fn();",
"// logs 'hello'",
"fn();",
"// does nothing"
]
},
"just-partial-it": {
"packageName": "just-partial-it",
"dir": "function-partial",
"description": "Return a partial function",
"examples": [
"import partial from 'just-partial-it';",
"",
"const cubedRoot = partial(Math.pow, _, 1/3);",
"cubedRoot(64); // 4",
"",
"const getRoot = partial(Math.pow, 64);",
"getRoot(1/2); // 8"
]
},
"just-throttle": {
"packageName": "just-throttle",
"dir": "function-throttle",
"description": "Return a throttled function",
"examples": [
"import throttle from 'just-throttle';",
"",
"// no matter how many times the function is called, only invoke once within the given interval",
"// options: ",
"// `leading`: invoke before interval",
"// `trailing`: invoke afer interval",
"",
"const fn1 = throttle(() => console.log('hello'), 500, {leading: true});",
"setInterval(fn1, 400);",
"// logs 'hello' immediately and then every 500ms",
"",
"const fn2 = throttle(() => console.log('hello'), 500, {trailing: true});",
"setInterval(fn2, 400);",
"// logs 'hello' after 500ms and then every 500ms",
"",
"const fn3 = throttle(() => console.log('hello'), 500, {leading: true, trailing: true});",
"// forces trailing to false",
"",
"const fn4 = throttle(() => console.log('hello'), 500, { leading: false });",
"fn4();",
"fn4();",
"fn4();",
"fn4.cancel();",
"// function cancelled before 'hello' is logged",
"",
"const fn5 = throttle(() => console.log(\"Hello\"), 500);",
"fn5();",
"fn5();",
"fn5();",
"fn5.flush();",
"// immediately invoke the throttled function"
]
},
"just-clamp": {
"packageName": "just-clamp",
"dir": "number-clamp",
"description": "Restrict a number within a range",
"examples": [
"import clamp from 'just-clamp';",
"",
"var n = 5;",
"clamp(1, n, 12); // 5",
"clamp(3, n, 1); // 3",
"clamp(8, n, 9); // 8",
"clamp(0, n, 0); // 0",
"",
"var n = -5;",
"clamp(1, n, 12); // 1",
"clamp(-7, n, -8); // -7",
"",