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