jsfunx 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/jsfunx.cjs +315 -411
  2. package/jsfunx.mjs +318 -418
  3. package/package.json +1 -1
package/jsfunx.cjs CHANGED
@@ -26,6 +26,8 @@ Author: Khiat Mohammed Abderrezzak <khiat.dev@gmail.com>
26
26
 
27
27
  // JavaScript utility functions for cleaner, more readable code
28
28
 
29
+ "use strict";
30
+
29
31
  /** @type {string} */
30
32
 
31
33
  const and = "and";
@@ -82,6 +84,10 @@ const Func = Function;
82
84
 
83
85
  const nil = null;
84
86
 
87
+ /** @type {null} */
88
+
89
+ const none = null;
90
+
85
91
  /** @type {string} */
86
92
 
87
93
  const num = "number";
@@ -172,54 +178,40 @@ function checkType(data, dataType, logic, match, strict) {
172
178
  ]);
173
179
 
174
180
  if (!(dataType instanceof Array)) {
175
- if (!setOfTypes.has(dataType)) {
176
- throw new TypeError("type undefined !");
177
- }
181
+ if (!setOfTypes.has(dataType)) throw new TypeError("type undefined !");
178
182
 
179
183
  if (!(data instanceof Array)) {
180
- if (data === null) {
181
- return dataType === null;
182
- }
184
+ if (data === null) return dataType === null;
183
185
 
184
- if (dataType === undefined) {
185
- return data === undefined;
186
- }
186
+ if (dataType === undefined) return data === undefined;
187
187
 
188
188
  return typeof data === dataType;
189
189
  }
190
190
 
191
- if (data.length === 0) {
192
- data[0] = [];
193
- }
191
+ if (data.length === 0) data[0] = [];
194
192
 
195
193
  if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
196
194
  for (let dt of data) {
197
195
  // 1 step directly in all cases
198
196
 
199
197
  if (dt === null) {
200
- if (dataType !== null) {
201
- return false;
202
- }
198
+ if (dataType !== null) return false;
199
+
203
200
  continue;
204
201
  }
205
202
 
206
203
  if (dataType === undefined) {
207
- if (dt !== undefined) {
208
- return false;
209
- }
204
+ if (dt !== undefined) return false;
205
+
210
206
  continue;
211
207
  }
212
208
 
213
- if (!(typeof dt === dataType)) {
214
- return false;
215
- }
209
+ if (!(typeof dt === dataType)) return false;
216
210
 
217
211
  // or using recursion (one to one)
218
212
  // 2 steps
219
213
 
220
- // if (!checkType(dt, dataType, logic, match, strict)) {
221
- // return false;
222
- // }
214
+ // if (!checkType(dt, dataType, logic, match, strict)) return false;
223
215
  }
224
216
 
225
217
  return true;
@@ -230,29 +222,23 @@ function checkType(data, dataType, logic, match, strict) {
230
222
  // 1 step directly in all cases
231
223
 
232
224
  if (dt === null) {
233
- if (dataType === null) {
234
- return true;
235
- }
225
+ if (dataType === null) return true;
226
+
236
227
  continue;
237
228
  }
238
229
 
239
230
  if (dataType === undefined) {
240
- if (dt === undefined) {
241
- return true;
242
- }
231
+ if (dt === undefined) return true;
232
+
243
233
  continue;
244
234
  }
245
235
 
246
- if (typeof dt === dataType) {
247
- return true;
248
- }
236
+ if (typeof dt === dataType) return true;
249
237
 
250
238
  // or using recursion (one to one)
251
239
  // 2 steps
252
240
 
253
- // if (checkType(dt, dataType, logic, match, strict)) {
254
- // return true;
255
- // }
241
+ // if (checkType(dt, dataType, logic, match, strict)) return true;
256
242
  }
257
243
 
258
244
  return false;
@@ -265,68 +251,54 @@ function checkType(data, dataType, logic, match, strict) {
265
251
  for (let dtype of dataType) {
266
252
  // 1 step directly in all cases
267
253
 
268
- if (!setOfTypes.has(dtype)) {
254
+ if (!setOfTypes.has(dtype))
269
255
  throw new TypeError(`type ${dtype} undefined !`);
270
- }
271
256
 
272
257
  if (data === null) {
273
- if (dtype === null) {
274
- return true;
275
- }
258
+ if (dtype === null) return true;
259
+
276
260
  continue;
277
261
  }
278
262
 
279
263
  if (dtype === undefined) {
280
- if (data === undefined) {
281
- return true;
282
- }
264
+ if (data === undefined) return true;
265
+
283
266
  continue;
284
267
  }
285
268
 
286
- if (typeof data === dtype) {
287
- return true;
288
- }
269
+ if (typeof data === dtype) return true;
289
270
 
290
271
  // or using recursion if (one to one) enabled
291
272
  // 2 steps
292
273
 
293
- // if (checkType(data, dtype, logic, match, strict)) {
294
- // return true;
295
- // }
274
+ // if (checkType(data, dtype, logic, match, strict)) return true;
296
275
  }
297
276
 
298
277
  return false;
299
278
  }
300
279
 
301
- if (data.length === 0) {
302
- data[0] = [];
303
- }
280
+ if (data.length === 0) data[0] = [];
304
281
 
305
282
  if (not(match)) {
306
283
  if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
307
284
  outerLoop: for (let dt of data) {
308
285
  for (let dtype of dataType) {
309
- if (!setOfTypes.has(dtype)) {
286
+ if (!setOfTypes.has(dtype))
310
287
  throw new TypeError(`type ${dtype} undefined !`);
311
- }
312
288
 
313
289
  if (dt === null) {
314
- if (dtype === null) {
315
- continue outerLoop;
316
- }
290
+ if (dtype === null) continue outerLoop;
291
+
317
292
  continue;
318
293
  }
319
294
 
320
295
  if (dtype === undefined) {
321
- if (dt === undefined) {
322
- continue outerLoop;
323
- }
296
+ if (dt === undefined) continue outerLoop;
297
+
324
298
  continue;
325
299
  }
326
300
 
327
- if (typeof dt === dtype) {
328
- continue outerLoop;
329
- }
301
+ if (typeof dt === dtype) continue outerLoop;
330
302
  }
331
303
 
332
304
  return false;
@@ -346,42 +318,33 @@ function checkType(data, dataType, logic, match, strict) {
346
318
  // // one step plus
347
319
 
348
320
  // // 2 steps (one to one)
349
- // if (!checkType(data[0], dataType, logic, match, strict)) {
350
- // return false;
351
- // }
321
+ // if (!checkType(data[0], dataType, logic, match, strict)) return false;
352
322
 
353
323
  // return true;
354
324
 
355
325
  // // 1 step directly using (one to one)
356
326
 
357
327
  // // for (let dtype of dataType) {
358
- // // if (checkType(data[0], dtype, logic, match, strict)) {
359
- // // return true;
360
- // // }
328
+ // // if (checkType(data[0], dtype, logic, match, strict)) return true;
361
329
 
362
330
  // // // the same as this
363
331
 
364
- // // // if (!setOfTypes.has(dtype)) {
332
+ // // // if (!setOfTypes.has(dtype))
365
333
  // // // throw new TypeError(`type ${dtype} undefined !`);
366
- // // // }
367
334
 
368
335
  // // // if (data[0] === null) {
369
- // // // if (dtype === null) {
370
- // // // return true;
371
- // // // }
336
+ // // // if (dtype === null) return true;
337
+
372
338
  // // // continue;
373
339
  // // // }
374
340
 
375
341
  // // // if (dtype === undefined) {
376
- // // // if (data[0] === undefined) {
377
- // // // return true;
378
- // // // }
342
+ // // // if (data[0] === undefined) return true;
343
+
379
344
  // // // continue;
380
345
  // // // }
381
346
 
382
- // // // if (typeof data[0] === dtype) {
383
- // // // return true;
384
- // // // }
347
+ // // // if (typeof data[0] === dtype) return true;
385
348
  // // }
386
349
 
387
350
  // // return false;
@@ -398,40 +361,31 @@ function checkType(data, dataType, logic, match, strict) {
398
361
 
399
362
  // // 2 steps (one to one)
400
363
 
401
- // if (!checkType(data, dataType[0], logic, match, strict)) {
402
- // return false;
403
- // }
364
+ // if (!checkType(data, dataType[0], logic, match, strict)) return false;
404
365
 
405
366
  // // 1 step directly (one to one)
406
367
 
407
368
  // // for (let dt of data) {
408
- // // if (!checkType(dt, dataType[0], logic, match, strict)) {
409
- // // return false;
410
- // // }
369
+ // // if (!checkType(dt, dataType[0], logic, match, strict)) return false;
411
370
 
412
371
  // // // the same as this
413
372
 
414
- // // // if (!setOfTypes.has(dataType[0])) {
373
+ // // // if (!setOfTypes.has(dataType[0]))
415
374
  // // // throw new TypeError("type undefined !");
416
- // // // }
417
375
 
418
376
  // // // if (dt === null) {
419
- // // // if (dataType[0] !== null) {
420
- // // // return false;
421
- // // // }
377
+ // // // if (dataType[0] !== null) return false;
378
+
422
379
  // // // continue;
423
380
  // // // }
424
381
 
425
382
  // // // if (dataType[0] === undefined) {
426
- // // // if (dt !== undefined) {
427
- // // // return false;
428
- // // // }
383
+ // // // if (dt !== undefined) return false;
384
+
429
385
  // // // continue;
430
386
  // // // }
431
387
 
432
- // // // if (!(typeof dt === dataType[0])) {
433
- // // // return false;
434
- // // // }
388
+ // // // if (!(typeof dt === dataType[0])) return false;
435
389
  // // }
436
390
 
437
391
  // // shared return
@@ -458,9 +412,7 @@ function checkType(data, dataType, logic, match, strict) {
458
412
  // // checkType(dt, dataType, logic, match, strict) but take
459
413
  // // one step plus
460
414
 
461
- // if (!checkType(dt, dataType, logic, match, strict)) {
462
- // return false;
463
- // }
415
+ // if (!checkType(dt, dataType, logic, match, strict)) return false;
464
416
  // }
465
417
 
466
418
  // return true;
@@ -476,9 +428,7 @@ function checkType(data, dataType, logic, match, strict) {
476
428
  // // checkType([dt], dataType, logic, match, strict) but take
477
429
  // // one step plus
478
430
 
479
- // if (!checkType([dt], dataType, logic, match, strict)) {
480
- // return false;
481
- // }
431
+ // if (!checkType([dt], dataType, logic, match, strict)) return false;
482
432
  // }
483
433
 
484
434
  // return true;
@@ -487,27 +437,22 @@ function checkType(data, dataType, logic, match, strict) {
487
437
  if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
488
438
  for (let dt of data) {
489
439
  for (let dtype of dataType) {
490
- if (!setOfTypes.has(dtype)) {
440
+ if (!setOfTypes.has(dtype))
491
441
  throw new TypeError(`type ${dtype} undefined !`);
492
- }
493
442
 
494
443
  if (dt === null) {
495
- if (dtype === null) {
496
- return true;
497
- }
444
+ if (dtype === null) return true;
445
+
498
446
  continue;
499
447
  }
500
448
 
501
449
  if (dtype === undefined) {
502
- if (dt === undefined) {
503
- return true;
504
- }
450
+ if (dt === undefined) return true;
451
+
505
452
  continue;
506
453
  }
507
454
 
508
- if (typeof dt === dtype) {
509
- return true;
510
- }
455
+ if (typeof dt === dtype) return true;
511
456
  }
512
457
  }
513
458
  return false;
@@ -525,40 +470,31 @@ function checkType(data, dataType, logic, match, strict) {
525
470
 
526
471
  // // 2 steps (one to one)
527
472
 
528
- // if (checkType(data[0], dataType, logic, match, strict)) {
529
- // return true;
530
- // }
473
+ // if (checkType(data[0], dataType, logic, match, strict)) return true;
531
474
 
532
475
  // // 1 step directly using (one to one)
533
476
 
534
477
  // // for (let dtype of dataType) {
535
- // // if (checkType(data[0], dtype, logic, match, strict)) {
536
- // // return true;
537
- // // }
478
+ // // if (checkType(data[0], dtype, logic, match, strict)) return true;
538
479
 
539
480
  // // // the same as this
540
481
 
541
- // // // if (!setOfTypes.has(dtype)) {
482
+ // // // if (!setOfTypes.has(dtype))
542
483
  // // // throw new TypeError(`type ${dtype} undefined !`);
543
- // // // }
544
484
 
545
485
  // // // if (data[0] === null) {
546
- // // // if (dtype === null) {
547
- // // // return true;
548
- // // // }
486
+ // // // if (dtype === null) return true;
487
+
549
488
  // // // continue;
550
489
  // // // }
551
490
 
552
491
  // // // if (dtype === undefined) {
553
- // // // if (data[0] === undefined) {
554
- // // // return true;
555
- // // // }
492
+ // // // if (data[0] === undefined) return true;
493
+
556
494
  // // // continue;
557
495
  // // // }
558
496
 
559
- // // // if (typeof data[0] === dtype) {
560
- // // // return true;
561
- // // // }
497
+ // // // if (typeof data[0] === dtype) return true;
562
498
  // // }
563
499
 
564
500
  // // shared return
@@ -577,40 +513,31 @@ function checkType(data, dataType, logic, match, strict) {
577
513
 
578
514
  // // 2 steps (one to one)
579
515
 
580
- // if (checkType(data, dataType[0], logic, match, strict)) {
581
- // return true;
582
- // }
516
+ // if (checkType(data, dataType[0], logic, match, strict)) return true;
583
517
 
584
518
  // // 1 step directly using (one to one)
585
519
 
586
520
  // // for (let dt of data) {
587
- // // if (checkType(dt, dataType[0], logic, match, strict)) {
588
- // // return true;
589
- // // }
521
+ // // if (checkType(dt, dataType[0], logic, match, strict)) return true;
590
522
 
591
523
  // // // the same as this
592
524
 
593
- // // // if (!setOfTypes.has(dataType[0])) {
525
+ // // // if (!setOfTypes.has(dataType[0]))
594
526
  // // // throw new TypeError("type undefined !");
595
- // // // }
596
527
 
597
528
  // // // if (dt === null) {
598
- // // // if (dataType[0] === null) {
599
- // // // return true;
600
- // // // }
529
+ // // // if (dataType[0] === null) return true;
530
+
601
531
  // // // continue;
602
532
  // // // }
603
533
 
604
534
  // // // if (dataType[0] === undefined) {
605
- // // // if (dt === undefined) {
606
- // // // return true;
607
- // // // }
535
+ // // // if (dt === undefined) return true;
536
+
608
537
  // // // continue;
609
538
  // // // }
610
539
 
611
- // // // if (typeof dt === dataType[0]) {
612
- // // // return true;
613
- // // // }
540
+ // // // if (typeof dt === dataType[0]) return true;
614
541
  // // }
615
542
 
616
543
  // // shared return
@@ -637,9 +564,7 @@ function checkType(data, dataType, logic, match, strict) {
637
564
  // // checkType(dt, dataType, logic, match, strict) but take
638
565
  // // one step plus
639
566
 
640
- // if (checkType(dt, dataType, logic, match, strict)) {
641
- // return true;
642
- // }
567
+ // if (checkType(dt, dataType, logic, match, strict)) return true;
643
568
  // }
644
569
 
645
570
  // return false;
@@ -655,9 +580,7 @@ function checkType(data, dataType, logic, match, strict) {
655
580
  // // checkType(data, dtype, logic, match, strict) but take
656
581
  // // one step plus
657
582
 
658
- // if (checkType(data, dtype, logic, match, strict)) {
659
- // return true;
660
- // }
583
+ // if (checkType(data, dtype, logic, match, strict)) return true;
661
584
  // }
662
585
 
663
586
  // return false;
@@ -673,9 +596,7 @@ function checkType(data, dataType, logic, match, strict) {
673
596
  // // checkType([dt], dataType, logic, match, strict) but take
674
597
  // // one step plus
675
598
 
676
- // if (checkType([dt], dataType, logic, match, strict)) {
677
- // return true;
678
- // }
599
+ // if (checkType([dt], dataType, logic, match, strict)) return true;
679
600
  // }
680
601
 
681
602
  // return false;
@@ -691,9 +612,7 @@ function checkType(data, dataType, logic, match, strict) {
691
612
  // // checkType(data, [dtype], logic, match, strict) but take
692
613
  // // one step plus
693
614
 
694
- // if (checkType(data, [dtype], logic, match, strict)) {
695
- // return true;
696
- // }
615
+ // if (checkType(data, [dtype], logic, match, strict)) return true;
697
616
  // }
698
617
 
699
618
  // return false;
@@ -703,11 +622,10 @@ function checkType(data, dataType, logic, match, strict) {
703
622
  }
704
623
 
705
624
  if (data.length !== dataType.length) {
706
- if (strict) {
625
+ if (strict)
707
626
  throw new TypeError(
708
627
  "length of array of dataTypes must match number of data"
709
628
  );
710
- }
711
629
 
712
630
  /** @type {number} */
713
631
 
@@ -723,34 +641,28 @@ function checkType(data, dataType, logic, match, strict) {
723
641
  for (let i = 0; i < min; ++i) {
724
642
  // 1 step directly in all cases
725
643
 
726
- if (!setOfTypes.has(dataType[i])) {
644
+ if (!setOfTypes.has(dataType[i]))
727
645
  throw new TypeError(`type ${dataType[i]} undefined !`);
728
- }
729
646
 
730
647
  if (data[i] === null) {
731
- if (dataType[i] !== null) {
732
- return false;
733
- }
648
+ if (dataType[i] !== null) return false;
649
+
734
650
  continue;
735
651
  }
736
652
 
737
653
  if (dataType[i] === undefined) {
738
- if (data[i] !== undefined) {
739
- return false;
740
- }
654
+ if (data[i] !== undefined) return false;
655
+
741
656
  continue;
742
657
  }
743
658
 
744
- if (!(typeof data[i] === dataType[i])) {
745
- return false;
746
- }
659
+ if (!(typeof data[i] === dataType[i])) return false;
747
660
 
748
661
  // or using recursion (one to one)
749
662
  // 2 steps
750
663
 
751
- // if (!checkType(data[i], dataType[i], logic, match, strict)) {
664
+ // if (!checkType(data[i], dataType[i], logic, match, strict))
752
665
  // return false;
753
- // }
754
666
  }
755
667
 
756
668
  // shared return
@@ -762,34 +674,27 @@ function checkType(data, dataType, logic, match, strict) {
762
674
  for (let i = 0; i < min; ++i) {
763
675
  // 1 step directly in all cases
764
676
 
765
- if (!setOfTypes.has(dataType[i])) {
677
+ if (!setOfTypes.has(dataType[i]))
766
678
  throw new TypeError(`type ${dataType[i]} undefined !`);
767
- }
768
679
 
769
680
  if (data[i] === null) {
770
- if (dataType[i] === null) {
771
- return true;
772
- }
681
+ if (dataType[i] === null) return true;
682
+
773
683
  continue;
774
684
  }
775
685
 
776
686
  if (dataType[i] === undefined) {
777
- if (data[i] === undefined) {
778
- return true;
779
- }
687
+ if (data[i] === undefined) return true;
688
+
780
689
  continue;
781
690
  }
782
691
 
783
- if (typeof data[i] === dataType[i]) {
784
- return true;
785
- }
692
+ if (typeof data[i] === dataType[i]) return true;
786
693
 
787
694
  // or using recursion (one to one)
788
695
  // 2 steps
789
696
 
790
- // if (checkType(data[i], dataType[i], logic, match, strict)) {
791
- // return true;
792
- // }
697
+ // if (checkType(data[i], dataType[i], logic, match, strict)) return true;
793
698
  }
794
699
 
795
700
  // shared return
@@ -804,34 +709,27 @@ function checkType(data, dataType, logic, match, strict) {
804
709
  for (let i = 0; i < data.length; ++i) {
805
710
  // 1 step directly in all cases
806
711
 
807
- if (!setOfTypes.has(dataType[i])) {
712
+ if (!setOfTypes.has(dataType[i]))
808
713
  throw new TypeError(`type ${dataType[i]} undefined !`);
809
- }
810
714
 
811
715
  if (data[i] === null) {
812
- if (dataType[i] !== null) {
813
- return false;
814
- }
716
+ if (dataType[i] !== null) return false;
717
+
815
718
  continue;
816
719
  }
817
720
 
818
721
  if (dataType[i] === undefined) {
819
- if (data[i] !== undefined) {
820
- return false;
821
- }
722
+ if (data[i] !== undefined) return false;
723
+
822
724
  continue;
823
725
  }
824
726
 
825
- if (!(typeof data[i] === dataType[i])) {
826
- return false;
827
- }
727
+ if (!(typeof data[i] === dataType[i])) return false;
828
728
 
829
729
  // or using recursion (one to one)
830
730
  // 2 steps
831
731
 
832
- // if (!checkType(data[i], dataType[i], logic, match, strict)) {
833
- // return false;
834
- // }
732
+ // if (!checkType(data[i], dataType[i], logic, match, strict)) return false;
835
733
  }
836
734
 
837
735
  // shared return
@@ -843,34 +741,27 @@ function checkType(data, dataType, logic, match, strict) {
843
741
  for (let i = 0; i < data.length; ++i) {
844
742
  // 1 step directly in all cases
845
743
 
846
- if (!setOfTypes.has(dataType[i])) {
744
+ if (!setOfTypes.has(dataType[i]))
847
745
  throw new TypeError(`type ${dataType[i]} undefined !`);
848
- }
849
746
 
850
747
  if (data[i] === null) {
851
- if (dataType[i] === null) {
852
- return true;
853
- }
748
+ if (dataType[i] === null) return true;
749
+
854
750
  continue;
855
751
  }
856
752
 
857
753
  if (dataType[i] === undefined) {
858
- if (data[i] === undefined) {
859
- return true;
860
- }
754
+ if (data[i] === undefined) return true;
755
+
861
756
  continue;
862
757
  }
863
758
 
864
- if (typeof data[i] === dataType[i]) {
865
- return true;
866
- }
759
+ if (typeof data[i] === dataType[i]) return true;
867
760
 
868
761
  // or using recursion (one to one)
869
762
  // 2 steps
870
763
 
871
- // if (checkType(data[i], dataType[i], logic, match, strict)) {
872
- // return true;
873
- // }
764
+ // if (checkType(data[i], dataType[i], logic, match, strict)) return true;
874
765
  }
875
766
 
876
767
  // shared return
@@ -903,30 +794,26 @@ function isinstancesof(objs, type, logic, match, strict) {
903
794
  // uncomment (return objs instanceof type)
904
795
  // to enable the 1/4 of (one to one)
905
796
 
906
- if (!(objs instanceof Array)) {
797
+ if (!(objs instanceof Array))
907
798
  // return objs instanceof type;
908
799
 
909
800
  throw new TypeError(
910
801
  `instancesof expected at least : 2 objects as first argument 'objs' or 2 types as second argument 'type', got 1`
911
802
  );
912
- }
913
803
 
914
- // remove this (if) condition to enable the 1/4 of (one to one)
804
+ // comment this condition to enable the 1/4 of (one to one)
915
805
 
916
- if (objs.length < 2) {
806
+ if (objs.length < 2)
917
807
  throw new TypeError(
918
808
  `instancesof expected at least 2 objects as first argument 'objs', got 1`
919
809
  );
920
- }
921
810
 
922
811
  if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
923
812
  for (let obj of objs) {
924
813
  // 1 step directly in all cases
925
814
 
926
815
  try {
927
- if (!(obj instanceof type)) {
928
- return false;
929
- }
816
+ if (!(obj instanceof type)) return false;
930
817
  } catch (error) {
931
818
  throw new TypeError(
932
819
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -936,9 +823,7 @@ function isinstancesof(objs, type, logic, match, strict) {
936
823
  // or using recursion if (one to one) enabled
937
824
  // 2 steps
938
825
 
939
- // if (!isinstances(obj, type, logic, match, strict)) {
940
- // return false;
941
- // }
826
+ // if (!isinstancesof(obj, type, logic, match, strict)) return false;
942
827
  }
943
828
 
944
829
  return true;
@@ -949,9 +834,7 @@ function isinstancesof(objs, type, logic, match, strict) {
949
834
  // 1 step directly in all cases
950
835
 
951
836
  try {
952
- if (obj instanceof type) {
953
- return true;
954
- }
837
+ if (obj instanceof type) return true;
955
838
  } catch (error) {
956
839
  throw new TypeError(
957
840
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -961,9 +844,7 @@ function isinstancesof(objs, type, logic, match, strict) {
961
844
  // or using recursion if (one to one) enabled
962
845
  // 2 steps
963
846
 
964
- // if (isinstances(obj, type, logic, match, strict)) {
965
- // return true;
966
- // }
847
+ // if (isinstancesof(obj, type, logic, match, strict)) return true;
967
848
  }
968
849
 
969
850
  return false;
@@ -973,21 +854,18 @@ function isinstancesof(objs, type, logic, match, strict) {
973
854
  }
974
855
 
975
856
  if (!(objs instanceof Array)) {
976
- // remove this (if) condition to enable the 1/4 of (one to one)
857
+ // comment this condition to enable the 1/4 of (one to one)
977
858
 
978
- if (type.length < 2) {
859
+ if (type.length < 2)
979
860
  throw new TypeError(
980
861
  `instancesof expected at least 2 types as second argument 'type', got 1`
981
862
  );
982
- }
983
863
 
984
864
  for (let dt of type) {
985
865
  // 1 step directly in all cases
986
866
 
987
867
  try {
988
- if (objs instanceof dt) {
989
- return true;
990
- }
868
+ if (objs instanceof dt) return true;
991
869
  } catch (error) {
992
870
  throw new TypeError(
993
871
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -997,34 +875,27 @@ function isinstancesof(objs, type, logic, match, strict) {
997
875
  // or using recursion if (one to one) enabled
998
876
  // 2 steps
999
877
 
1000
- // if (isinstances(objs, dt, logic, match, strict)) {
1001
- // return true;
1002
- // }
878
+ // if (isinstancesof(objs, dt, logic, match, strict)) return true;
1003
879
  }
1004
880
 
1005
881
  return false;
1006
882
  }
1007
883
 
1008
- // remove this (if) to enable 1/4 of (one to one)
884
+ // comment this condition to enable 1/4 of (one to one)
1009
885
 
1010
- if (objs.length < 2 && type.length < 2) {
886
+ if (objs.length < 2 && type.length < 2)
1011
887
  throw new TypeError(
1012
888
  `instancesof expected at least : 2 objects as first argument 'objs' or 2 types as second argument 'type', got 1`
1013
889
  );
1014
- }
1015
890
 
1016
891
  if (not(match)) {
1017
- if (objs.length === 0) {
1018
- objs[0] = [];
1019
- }
892
+ if (objs.length === 0) objs[0] = [];
1020
893
 
1021
894
  if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
1022
895
  outerLoop: for (let obj of objs) {
1023
896
  for (let dt of type) {
1024
897
  try {
1025
- if (obj instanceof dt) {
1026
- continue outerLoop;
1027
- }
898
+ if (obj instanceof dt) continue outerLoop;
1028
899
  } catch (error) {
1029
900
  throw new TypeError(
1030
901
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1045,28 +916,22 @@ function isinstancesof(objs, type, logic, match, strict) {
1045
916
  // // [x], [y, z] => x, [y, z] (one to many)
1046
917
 
1047
918
  // // we can call instancesof(objs[0], type) in place of
1048
- // // isinstances(objs[0], type, logic, match, strict) but take
919
+ // // isinstancesof(objs[0], type, logic, match, strict) but take
1049
920
  // // one step plus
1050
921
 
1051
922
  // // 2 steps if (one to one) enabled
1052
- // if (!isinstances(objs[0], type, logic, match, strict)) {
1053
- // return false;
1054
- // }
923
+ // if (!isinstancesof(objs[0], type, logic, match, strict)) return false;
1055
924
 
1056
925
  // return true;
1057
926
 
1058
927
  // // 1 step directly using (one to one) if enabled
1059
928
 
1060
929
  // // for (let dt of type) {
1061
- // // if (isinstances(objs[0], dt, logic, match, strict)) {
1062
- // // return true;
1063
- // // }
930
+ // // if (isinstancesof(objs[0], dt, logic, match, strict)) return true;
1064
931
 
1065
932
  // // // the same as this
1066
933
 
1067
- // // // if (objs[0] instanceof dt) {
1068
- // // // return true;
1069
- // // // }
934
+ // // // if (objs[0] instanceof dt) return true;
1070
935
  // // }
1071
936
 
1072
937
  // // return false;
@@ -1078,27 +943,21 @@ function isinstancesof(objs, type, logic, match, strict) {
1078
943
  // // [x, y], [z] => [x, y], z (many to one)
1079
944
 
1080
945
  // // we can call instancesof(objs, type[0]) in place of
1081
- // // isinstances(objs, type[0], logic, match, strict) but take
946
+ // // isinstancesof(objs, type[0], logic, match, strict) but take
1082
947
  // // one step plus
1083
948
 
1084
949
  // // 2 steps if (one to one) enabled
1085
950
 
1086
- // if (!isinstances(objs, type[0], logic, match, strict)) {
1087
- // return false;
1088
- // }
951
+ // if (!isinstancesof(objs, type[0], logic, match, strict)) return false;
1089
952
 
1090
953
  // // 1 step directly using (one to one) if enabled
1091
954
 
1092
955
  // // for (let obj of objs) {
1093
- // // if (!isinstances(obj, type[0], logic, match, strict)) {
1094
- // // return false;
1095
- // // }
956
+ // // if (!isinstancesof(obj, type[0], logic, match, strict)) return false;
1096
957
 
1097
958
  // // // the same as this
1098
959
 
1099
- // // // if (!(obj instanceof type[0])) {
1100
- // // // return false;
1101
- // // // }
960
+ // // // if (!(obj instanceof type[0])) return false;
1102
961
  // // }
1103
962
 
1104
963
  // // shared return
@@ -1122,12 +981,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1122
981
  // // (one to many) (1 step directly)
1123
982
 
1124
983
  // // we can call instancesof(obj, type) in place of
1125
- // // isinstances(obj, type, logic, match, strict) but take
984
+ // // isinstancesof(obj, type, logic, match, strict) but take
1126
985
  // // one step plus
1127
986
 
1128
- // if (!isinstances(obj, type, logic, match, strict)) {
1129
- // return false;
1130
- // }
987
+ // if (!isinstancesof(obj, type, logic, match, strict)) return false;
1131
988
  // }
1132
989
 
1133
990
  // return true;
@@ -1140,12 +997,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1140
997
  // // (one to many) (2 steps)
1141
998
 
1142
999
  // // we can call instancesof([obj], type, match) in place of
1143
- // // isinstances([obj], type, logic, match, strict) but take
1000
+ // // isinstancesof([obj], type, logic, match, strict) but take
1144
1001
  // // one step plus
1145
1002
 
1146
- // if (!isinstances([obj], type, logic, match, strict)) {
1147
- // return false;
1148
- // }
1003
+ // if (!isinstancesof([obj], type, logic, match, strict)) return false;
1149
1004
  // }
1150
1005
 
1151
1006
  // return true;
@@ -1155,9 +1010,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1155
1010
  for (let obj of objs) {
1156
1011
  for (let dt of type) {
1157
1012
  try {
1158
- if (obj instanceof dt) {
1159
- return true;
1160
- }
1013
+ if (obj instanceof dt) return true;
1161
1014
  } catch (error) {
1162
1015
  throw new TypeError(
1163
1016
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1175,27 +1028,21 @@ function isinstancesof(objs, type, logic, match, strict) {
1175
1028
  // // [x], [y, z] => x, [y, z] (one to many)
1176
1029
 
1177
1030
  // // we can call instancesof(objs[0], type, logic) in place of
1178
- // // isinstances(objs[0], type, logic, match, strict) but take
1031
+ // // isinstancesof(objs[0], type, logic, match, strict) but take
1179
1032
  // // one step plus
1180
1033
 
1181
1034
  // // 2 steps if (one to one) enabled
1182
1035
 
1183
- // if (isinstances(objs[0], type, logic, match, strict)) {
1184
- // return true;
1185
- // }
1036
+ // if (isinstancesof(objs[0], type, logic, match, strict)) return true;
1186
1037
 
1187
1038
  // // // 1 step directly using (one to one) if enabled
1188
1039
 
1189
1040
  // // for (let dt of type) {
1190
- // // if (isinstances(objs[0], dt, logic, match, strict)) {
1191
- // // return true;
1192
- // // }
1041
+ // // if (isinstancesof(objs[0], dt, logic, match, strict)) return true;
1193
1042
 
1194
1043
  // // // the same as this
1195
1044
 
1196
- // // // if (objs[0] instanceof dt) {
1197
- // // // return true;
1198
- // // // }
1045
+ // // // if (objs[0] instanceof dt) return true;
1199
1046
  // // }
1200
1047
 
1201
1048
  // // shared return
@@ -1209,27 +1056,21 @@ function isinstancesof(objs, type, logic, match, strict) {
1209
1056
  // // [x, y], [z] => [x, y], z (many to one)
1210
1057
 
1211
1058
  // // we can call instancesof(objs, type[0], logic) in place of
1212
- // // isinstances(objs, type[0], logic, match, strict) but take
1059
+ // // isinstancesof(objs, type[0], logic, match, strict) but take
1213
1060
  // // one step plus
1214
1061
 
1215
1062
  // // 2 steps if (one to one) enabled
1216
1063
 
1217
- // if (isinstances(objs, type[0], logic, match, strict)) {
1218
- // return true;
1219
- // }
1064
+ // if (isinstancesof(objs, type[0], logic, match, strict)) return true;
1220
1065
 
1221
1066
  // // // 1 step directly using (one to one) if enabled
1222
1067
 
1223
1068
  // // for (let obj of objs) {
1224
- // // if (isinstances(obj, type[0], logic, match, strict)) {
1225
- // // return true;
1226
- // // }
1069
+ // // if (isinstancesof(obj, type[0], logic, match, strict)) return true;
1227
1070
 
1228
1071
  // // // the same as this
1229
1072
 
1230
- // // // if (obj instanceof type[0]) {
1231
- // // // return true;
1232
- // // // }
1073
+ // // // if (obj instanceof type[0]) return true;
1233
1074
  // // }
1234
1075
 
1235
1076
  // // shared return
@@ -1253,12 +1094,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1253
1094
  // // (one to many) (1 step directly) & (2 steps if (one to one) enabled)
1254
1095
 
1255
1096
  // // we can call instancesof(obj, type, logic) in place of
1256
- // // isinstances(obj, type, logic, match, strict) but take
1097
+ // // isinstancesof(obj, type, logic, match, strict) but take
1257
1098
  // // one step plus
1258
1099
 
1259
- // if (isinstances(obj, type, logic, match, strict)) {
1260
- // return true;
1261
- // }
1100
+ // if (isinstancesof(obj, type, logic, match, strict)) return true;
1262
1101
  // }
1263
1102
 
1264
1103
  // return false;
@@ -1271,12 +1110,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1271
1110
  // // (many to one) (1 step directly) & (2 steps if (one to one) enabled)
1272
1111
 
1273
1112
  // // we can call instancesof(objs, dt, logic) in place of
1274
- // // isinstances(objs, dt, logic, match, strict) but take
1113
+ // // isinstancesof(objs, dt, logic, match, strict) but take
1275
1114
  // // one step plus
1276
1115
 
1277
- // if (isinstances(objs, dt, logic, match, strict)) {
1278
- // return true;
1279
- // }
1116
+ // if (isinstancesof(objs, dt, logic, match, strict)) return true;
1280
1117
  // }
1281
1118
 
1282
1119
  // return false;
@@ -1289,12 +1126,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1289
1126
  // // (one to many) (2 steps) & (3 steps if (one to one) enabled)
1290
1127
 
1291
1128
  // // we can call instancesof([obj], type, logic, match) in place of
1292
- // // isinstances([obj], type, logic, match, strict) but take
1129
+ // // isinstancesof([obj], type, logic, match, strict) but take
1293
1130
  // // one step plus
1294
1131
 
1295
- // if (isinstances([obj], type, logic, match, strict)) {
1296
- // return true;
1297
- // }
1132
+ // if (isinstancesof([obj], type, logic, match, strict)) return true;
1298
1133
  // }
1299
1134
 
1300
1135
  // return false;
@@ -1307,12 +1142,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1307
1142
  // // (many to one) (2 steps) & (3 steps if (one to one) enabled)
1308
1143
 
1309
1144
  // // we can call instancesof(objs, [dt], logic, match) in place of
1310
- // // isinstances(objs, [dt], logic, match, strict) but take
1145
+ // // isinstancesof(objs, [dt], logic, match, strict) but take
1311
1146
  // // one step plus
1312
1147
 
1313
- // if (isinstances(objs, [dt], logic, match, strict)) {
1314
- // return true;
1315
- // }
1148
+ // if (isinstancesof(objs, [dt], logic, match, strict)) return true;
1316
1149
  // }
1317
1150
 
1318
1151
  // return false;
@@ -1322,11 +1155,10 @@ function isinstancesof(objs, type, logic, match, strict) {
1322
1155
  }
1323
1156
 
1324
1157
  if (objs.length !== type.length) {
1325
- if (strict) {
1158
+ if (strict)
1326
1159
  throw new TypeError(
1327
1160
  "length of array of types must match number of objects"
1328
1161
  );
1329
- }
1330
1162
 
1331
1163
  /** @type {number} */
1332
1164
 
@@ -1343,9 +1175,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1343
1175
  // 1 step directly in all cases
1344
1176
 
1345
1177
  try {
1346
- if (!(objs[i] instanceof type[i])) {
1347
- return false;
1348
- }
1178
+ if (!(objs[i] instanceof type[i])) return false;
1349
1179
  } catch (error) {
1350
1180
  throw new TypeError(
1351
1181
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1355,9 +1185,8 @@ function isinstancesof(objs, type, logic, match, strict) {
1355
1185
  // or using recursion if (one to one) enabled
1356
1186
  // 2 steps
1357
1187
 
1358
- // if (!isinstances(objs[i], type[i], logic, match, strict)) {
1188
+ // if (!isinstancesof(objs[i], type[i], logic, match, strict))
1359
1189
  // return false;
1360
- // }
1361
1190
  }
1362
1191
 
1363
1192
  // shared return
@@ -1370,9 +1199,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1370
1199
  // 1 step directly in all cases
1371
1200
 
1372
1201
  try {
1373
- if (objs[i] instanceof type[i]) {
1374
- return true;
1375
- }
1202
+ if (objs[i] instanceof type[i]) return true;
1376
1203
  } catch (error) {
1377
1204
  throw new TypeError(
1378
1205
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1382,9 +1209,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1382
1209
  // or using recursion if (one to one) enabled
1383
1210
  // 2 steps
1384
1211
 
1385
- // if (isinstances(objs[i], type[i], logic, match, strict)) {
1386
- // return true;
1387
- // }
1212
+ // if (isinstancesof(objs[i], type[i], logic, match, strict)) return true;
1388
1213
  }
1389
1214
 
1390
1215
  // shared return
@@ -1400,9 +1225,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1400
1225
  // 1 step directly in all cases
1401
1226
 
1402
1227
  try {
1403
- if (!(objs[i] instanceof type[i])) {
1404
- return false;
1405
- }
1228
+ if (!(objs[i] instanceof type[i])) return false;
1406
1229
  } catch (error) {
1407
1230
  throw new TypeError(
1408
1231
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1412,9 +1235,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1412
1235
  // or using recursion if (one to one) enabled
1413
1236
  // 2 steps
1414
1237
 
1415
- // if (!isinstances(objs[i], type[i], logic, match, strict)) {
1416
- // return false;
1417
- // }
1238
+ // if (!isinstancesof(objs[i], type[i], logic, match, strict)) return false;
1418
1239
  }
1419
1240
 
1420
1241
  // shared return
@@ -1427,9 +1248,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1427
1248
  // 1 step directly in all cases
1428
1249
 
1429
1250
  try {
1430
- if (objs[i] instanceof type[i]) {
1431
- return true;
1432
- }
1251
+ if (objs[i] instanceof type[i]) return true;
1433
1252
  } catch (error) {
1434
1253
  throw new TypeError(
1435
1254
  "second argument of 'instancesof' is not a type/class or array of types/classes"
@@ -1439,9 +1258,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1439
1258
  // or using recursion if (one to one) enabled
1440
1259
  // 2 steps
1441
1260
 
1442
- // if (isinstances(objs[i], type[i], logic, match, strict)) {
1443
- // return true;
1444
- // }
1261
+ // if (isinstancesof(objs[i], type[i], logic, match, strict)) return true;
1445
1262
  }
1446
1263
 
1447
1264
  // shared return
@@ -1461,10 +1278,7 @@ function isinstancesof(objs, type, logic, match, strict) {
1461
1278
  */
1462
1279
 
1463
1280
  function echo(data) {
1464
- if (arguments.length > 1) {
1465
- throw new TypeError('unexpected token ","');
1466
- }
1467
- process.stdout.write(`${data}`);
1281
+ printf(data);
1468
1282
  }
1469
1283
 
1470
1284
  /**
@@ -1495,37 +1309,43 @@ function instancesof(
1495
1309
 
1496
1310
  let len = arguments.length;
1497
1311
 
1498
- if (len < 2) {
1312
+ // ================================================================
1313
+
1314
+ if (len < 2)
1499
1315
  throw new TypeError(
1500
1316
  len === 1
1501
- ? "instancesof() missing 1 required arguments: 'type'"
1317
+ ? "instancesof() missing 1 required argument: 'type'"
1502
1318
  : "instancesof() missing 2 required arguments: 'objs' and 'type'"
1503
1319
  );
1504
- }
1505
1320
 
1506
- if (len > 5) {
1321
+ if (len > 5)
1507
1322
  throw new TypeError(
1508
- `instancesof() takes 5 positional arguments but ${len} were given`
1323
+ `instancesof() takes 5 arguments in total but ${len} were given`
1509
1324
  );
1510
- }
1511
1325
 
1512
- if (len === 3) {
1513
- if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1326
+ // ================================================================
1327
+
1328
+ // or we can use our useStrict function for checking
1329
+
1330
+ // ================================================================
1331
+
1332
+ // useStrict(instancesof, arguments, 3);
1333
+
1334
+ // ================================================================
1335
+
1336
+ if (len === 3)
1337
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean)
1514
1338
  return isinstancesof(objs, type, and, logic_or_match, strict);
1515
- }
1516
- }
1517
1339
 
1518
1340
  if (len === 4) {
1519
1341
  if (
1520
1342
  not(checkType(arguments[3], boolean)) &&
1521
1343
  not(arguments[3] instanceof Boolean)
1522
- ) {
1344
+ )
1523
1345
  throw new TypeError("forth argument must be true or false");
1524
- }
1525
1346
 
1526
- if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1347
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean)
1527
1348
  return isinstancesof(objs, type, and, logic_or_match, match_or_strict);
1528
- }
1529
1349
  }
1530
1350
 
1531
1351
  return isinstancesof(objs, type, logic_or_match, match_or_strict, strict);
@@ -1602,37 +1422,43 @@ function isType(
1602
1422
 
1603
1423
  let len = arguments.length;
1604
1424
 
1605
- if (len < 2) {
1425
+ // ================================================================
1426
+
1427
+ if (len < 2)
1606
1428
  throw new TypeError(
1607
1429
  len === 1
1608
- ? "isType() missing 1 required arguments: 'dataType'"
1430
+ ? "isType() missing 1 required argument: 'dataType'"
1609
1431
  : "isType() missing 2 required arguments: 'data' and 'dataType'"
1610
1432
  );
1611
- }
1612
1433
 
1613
- if (len > 5) {
1434
+ if (len > 5)
1614
1435
  throw new TypeError(
1615
- `isType() takes 5 positional arguments but ${len} were given`
1436
+ `isType() takes 5 arguments in total but ${len} were given`
1616
1437
  );
1617
- }
1618
1438
 
1619
- if (len === 3) {
1620
- if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1439
+ // ================================================================
1440
+
1441
+ // or we can use our useStrict function for checking
1442
+
1443
+ // ================================================================
1444
+
1445
+ // useStrict(isType, arguments, 3);
1446
+
1447
+ // ================================================================
1448
+
1449
+ if (len === 3)
1450
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean)
1621
1451
  return checkType(data, dataType, and, logic_or_match, strict);
1622
- }
1623
- }
1624
1452
 
1625
1453
  if (len === 4) {
1626
1454
  if (
1627
1455
  not(checkType(arguments[3], boolean)) &&
1628
1456
  not(arguments[3] instanceof Boolean)
1629
- ) {
1457
+ )
1630
1458
  throw new TypeError("forth argument must be true or false");
1631
- }
1632
1459
 
1633
- if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1460
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean)
1634
1461
  return checkType(data, dataType, and, logic_or_match, match_or_strict);
1635
- }
1636
1462
  }
1637
1463
 
1638
1464
  return checkType(data, dataType, logic_or_match, match_or_strict, strict);
@@ -1648,9 +1474,9 @@ function isType(
1648
1474
  */
1649
1475
 
1650
1476
  function len(iter) {
1651
- if (iter.length === undefined) {
1477
+ if (iter.length === undefined)
1652
1478
  throw new TypeError(`type '${typeof iter}' has no len()`);
1653
- }
1479
+
1654
1480
  return iter.length;
1655
1481
  }
1656
1482
 
@@ -1668,13 +1494,12 @@ function len(iter) {
1668
1494
  */
1669
1495
 
1670
1496
  function lengths(...objs) {
1671
- // use not(objs) to enable all cases including one argument only
1497
+ // use "if (not(objs))" to enable all cases including one argument only
1672
1498
 
1673
- if (objs.length < 2) {
1499
+ if (objs.length < 2)
1674
1500
  throw new TypeError(
1675
1501
  `lengths() takes at least two arguments (${objs.length} given)`
1676
1502
  );
1677
- }
1678
1503
 
1679
1504
  /** @type {Array<number>} */
1680
1505
 
@@ -1693,18 +1518,12 @@ function lengths(...objs) {
1693
1518
 
1694
1519
  lens.push(len);
1695
1520
 
1696
- if (!equal) {
1697
- continue;
1698
- }
1521
+ if (!equal) continue;
1699
1522
 
1700
- if (len !== lens[i - 1]) {
1701
- equal = false;
1702
- }
1523
+ if (len !== lens[i - 1]) equal = false;
1703
1524
  }
1704
1525
 
1705
- if (equal) {
1706
- return [lens[0], equal];
1707
- }
1526
+ if (equal) return [lens[0], equal];
1708
1527
 
1709
1528
  return [lens, equal];
1710
1529
  }
@@ -1747,13 +1566,10 @@ function log(...data) {
1747
1566
  */
1748
1567
 
1749
1568
  function not(obj) {
1750
- if (arguments.length === 0) {
1569
+ if (arguments.length === 0)
1751
1570
  throw new TypeError("not() takes exactly one argument (0 given)");
1752
- }
1753
1571
 
1754
- if (obj instanceof Boolean) {
1755
- return obj == false;
1756
- }
1572
+ if (obj instanceof Boolean) return obj == false;
1757
1573
 
1758
1574
  return obj?.length === 0 || !obj; // handling the object case
1759
1575
  }
@@ -1779,9 +1595,8 @@ function print(...data) {
1779
1595
  */
1780
1596
 
1781
1597
  function printf(data) {
1782
- if (arguments.length > 1) {
1783
- throw new TypeError('unexpected token ","');
1784
- }
1598
+ if (arguments.length > 1) throw new TypeError('unexpected token ","');
1599
+
1785
1600
  process.stdout.write(`${data}`);
1786
1601
  }
1787
1602
 
@@ -1852,13 +1667,12 @@ function types(...objs) {
1852
1667
  */
1853
1668
 
1854
1669
  function typesof(...objs) {
1855
- // use not(objs) to enable all cases including one argument only
1670
+ // use "if (not(objs))" to enable all cases including one argument only
1856
1671
 
1857
- if (objs.length < 2) {
1672
+ if (objs.length < 2)
1858
1673
  throw new TypeError(
1859
1674
  `typesof() takes at least two arguments (${objs.length} given)`
1860
1675
  );
1861
- }
1862
1676
 
1863
1677
  /** @type {Array<string>} */
1864
1678
 
@@ -1877,22 +1691,110 @@ function typesof(...objs) {
1877
1691
 
1878
1692
  types.push(type);
1879
1693
 
1880
- if (!equal) {
1881
- continue;
1882
- }
1694
+ if (!equal) continue;
1883
1695
 
1884
- if (type !== types[i - 1]) {
1885
- equal = false;
1886
- }
1696
+ if (type !== types[i - 1]) equal = false;
1887
1697
  }
1888
1698
 
1889
- if (equal) {
1890
- return [types[0], equal];
1891
- }
1699
+ if (equal) return [types[0], equal];
1892
1700
 
1893
1701
  return [types, equal];
1894
1702
  }
1895
1703
 
1704
+ /**
1705
+ * Validates function arguments strictly at runtime.
1706
+ *
1707
+ * Ensures that:
1708
+ * 1. `useStrict` is called with exactly three arguments:
1709
+ * - `func`: the function to validate against
1710
+ * - `args`: an array or array-like object of arguments intended for `func`
1711
+ * - `optional`: optional arguments number in the function
1712
+ * 2. `func` is a function.
1713
+ * 3. `args` is array-like.
1714
+ * 4. `optional` is a number.
1715
+ * 5. The number of elements in `args` greater than or equal the number of parameters `func` expects.
1716
+ * 6. The number of elements in `args` less than or equal the number of parameters `func` + `optional` expects.
1717
+ *
1718
+ * @param {Function} func - The function whose arguments are being validated.
1719
+ * @param {Array|IArguments} args - The array-like object of arguments to check against the function's parameter count.
1720
+ * @param {number} optional - default arguments number in the function.
1721
+ * @throws {TypeError} If called with a number of arguments less than 2.
1722
+ * @throws {TypeError} If called with a number of arguments greater than 3.
1723
+ * @throws {TypeError} If `func` is not a function.
1724
+ * @throws {TypeError} If `args` is not array-like.
1725
+ * @throws {TypeError} If `optional` is a negative number or not a number at all.
1726
+ * @throws {TypeError} If the length of `args` is less than the parameters number of `func`.
1727
+ * @throws {TypeError} If the length of `args` is greater than the parameters number of `func` + `optional`.
1728
+ * @returns {void} This function does not return a value.
1729
+ */
1730
+
1731
+ function useStrict(func, args, optional = 0) {
1732
+ /** @type {number} */
1733
+
1734
+ const len = arguments.length;
1735
+
1736
+ if (len < 2)
1737
+ throw new TypeError(
1738
+ len === 1
1739
+ ? "useStrict() missing 1 required argument: 'args'"
1740
+ : "useStrict() missing 2 required arguments: 'func' and 'args'"
1741
+ );
1742
+
1743
+ if (len > 3)
1744
+ throw TypeError(
1745
+ `useStrict() takes 3 arguments in total but ${len} were given`
1746
+ );
1747
+
1748
+ if (!(func instanceof Function))
1749
+ throw TypeError("first argument must be a function");
1750
+
1751
+ if (typeof args !== "object" || typeof args.length !== "number")
1752
+ throw TypeError("second argument must be array-like");
1753
+
1754
+ if (typeof optional !== "number" || optional < 0)
1755
+ throw TypeError("third argument must be a positive number");
1756
+
1757
+ /** @type {string} */
1758
+
1759
+ const funcName = func.name;
1760
+
1761
+ /** @type {number} */
1762
+
1763
+ const paramsNumber = func.length;
1764
+
1765
+ /** @type {number} */
1766
+
1767
+ const argsNumber = args.length;
1768
+
1769
+ if (argsNumber < paramsNumber)
1770
+ throw TypeError(
1771
+ `${funcName}() takes ${paramsNumber} positional argument(s) but ${argsNumber} were given`
1772
+ );
1773
+
1774
+ if (argsNumber > paramsNumber + optional) {
1775
+ if (paramsNumber > 0 && optional > 0)
1776
+ throw TypeError(
1777
+ `${funcName}() takes ${
1778
+ paramsNumber + optional
1779
+ } arguments in total but ${argsNumber} were given`
1780
+ );
1781
+
1782
+ if (paramsNumber > 0)
1783
+ throw TypeError(
1784
+ `${funcName}() takes ${paramsNumber} positional argument(s) in total but ${argsNumber} were given`
1785
+ );
1786
+
1787
+ if (optional > 0)
1788
+ throw TypeError(
1789
+ `${funcName}() takes ${optional} optional argument(s) in total but ${argsNumber} were given`
1790
+ );
1791
+
1792
+ throw TypeError(
1793
+ `${funcName}() takes no argument(s) but ${argsNumber} were given`
1794
+ );
1795
+ }
1796
+ }
1797
+
1896
1798
  /**
1897
1799
  * Evaluates the truthiness of a given value.
1898
1800
  * Works like the logical NOT operator (`!`), returning `true` if the value is falsy and `false` if it is truthy.
@@ -2148,6 +2050,7 @@ module.exports = {
2148
2050
  func,
2149
2051
  Func,
2150
2052
  nil,
2053
+ none,
2151
2054
  num,
2152
2055
  Num,
2153
2056
  number,
@@ -2180,5 +2083,6 @@ module.exports = {
2180
2083
  type,
2181
2084
  types,
2182
2085
  typesof,
2086
+ useStrict,
2183
2087
  $,
2184
2088
  };