jsfunx 1.0.0 → 1.0.1

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 (4) hide show
  1. package/README.md +2 -2
  2. package/jsfunx.cjs +150 -52
  3. package/jsfunx.mjs +143 -52
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -30,7 +30,7 @@ function add(num1, num2) {
30
30
  return num1 + num2;
31
31
  }
32
32
 
33
- throw TypeError("invalid arguments");
33
+ throw new TypeError("invalid arguments");
34
34
  }
35
35
 
36
36
  console.log(add(1, 3));
@@ -156,7 +156,7 @@ function add(num1, num2) {
156
156
  return num1 + num2;
157
157
  }
158
158
 
159
- throw TypeError("invalid arguments");
159
+ throw new TypeError("invalid arguments");
160
160
  }
161
161
 
162
162
  console.log(add(new Number(1), new Number(3)));
package/jsfunx.cjs CHANGED
@@ -44,18 +44,42 @@ const func = "function";
44
44
 
45
45
  /** @type {string} */
46
46
 
47
+ const fun = "function";
48
+
49
+ /** @type {string} */
50
+
51
+ const fn = "function";
52
+
53
+ /** @type {string} */
54
+
47
55
  const number = "number";
48
56
 
49
57
  /** @type {string} */
50
58
 
59
+ const num = "number";
60
+
61
+ /** @type {string} */
62
+
51
63
  const object = "object";
52
64
 
53
65
  /** @type {string} */
54
66
 
67
+ const obj = "object";
68
+
69
+ /** @type {string} */
70
+
71
+ const nil = "object"; // don't use this with objects, use it only with the null primitive.
72
+
73
+ /** @type {string} */
74
+
55
75
  const string = "string";
56
76
 
57
77
  /** @type {string} */
58
78
 
79
+ const str = "string";
80
+
81
+ /** @type {string} */
82
+
59
83
  const symbol = "symbol";
60
84
 
61
85
  /** @type {string} */
@@ -64,6 +88,10 @@ const boolean = "boolean";
64
88
 
65
89
  /** @type {string} */
66
90
 
91
+ const bool = "boolean";
92
+
93
+ /** @type {string} */
94
+
67
95
  const undef = "undefined";
68
96
 
69
97
  /**
@@ -82,14 +110,35 @@ const undef = "undefined";
82
110
  */
83
111
 
84
112
  function checkType(data, dataType, logic, match, strict) {
85
- // if data or dataType is Array must be nested Array
113
+ /** @type {Set<string>} */
114
+
115
+ let setOfTypes = new Set([
116
+ and,
117
+ or,
118
+ bigint,
119
+ func,
120
+ number,
121
+ object,
122
+ string,
123
+ symbol,
124
+ boolean,
125
+ undef,
126
+ ]);
86
127
 
87
128
  if (!(dataType instanceof Array)) {
129
+ if (!setOfTypes.has(dataType)) {
130
+ throw new TypeError("type undefined !");
131
+ }
132
+
88
133
  if (!(data instanceof Array)) {
89
134
  return typeof data === dataType;
90
135
  }
91
136
 
92
- if (logic === and) {
137
+ if (data.length === 0) {
138
+ data[0] = [];
139
+ }
140
+
141
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
93
142
  for (let dt of data) {
94
143
  // 1 step directly in all cases
95
144
 
@@ -108,7 +157,7 @@ function checkType(data, dataType, logic, match, strict) {
108
157
  return true;
109
158
  }
110
159
 
111
- if (logic === or) {
160
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
112
161
  for (let dt of data) {
113
162
  // 1 step directly in all cases
114
163
 
@@ -134,6 +183,10 @@ function checkType(data, dataType, logic, match, strict) {
134
183
  for (let dtype of dataType) {
135
184
  // 1 step directly in all cases
136
185
 
186
+ if (!setOfTypes.has(dtype)) {
187
+ throw new TypeError(`type ${dtype} undefined !`);
188
+ }
189
+
137
190
  if (typeof data === dtype) {
138
191
  return true;
139
192
  }
@@ -149,10 +202,18 @@ function checkType(data, dataType, logic, match, strict) {
149
202
  return false;
150
203
  }
151
204
 
152
- if (!match) {
153
- if (logic === and) {
205
+ if (data.length === 0) {
206
+ data[0] = [];
207
+ }
208
+
209
+ if (not(match)) {
210
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
154
211
  outerLoop: for (let dt of data) {
155
212
  for (let dtype of dataType) {
213
+ if (!setOfTypes.has(dtype)) {
214
+ throw new TypeError(`type ${dtype} undefined !`);
215
+ }
216
+
156
217
  if (typeof dt === dtype) {
157
218
  continue outerLoop;
158
219
  }
@@ -190,6 +251,10 @@ function checkType(data, dataType, logic, match, strict) {
190
251
 
191
252
  // // // the same as this
192
253
 
254
+ // // // if (!setOfTypes.has(dtype)) {
255
+ // // // throw new TypeError(`type ${dtype} undefined !`);
256
+ // // // }
257
+
193
258
  // // // if (typeof data[0] === dtype) {
194
259
  // // // return true;
195
260
  // // // }
@@ -222,6 +287,10 @@ function checkType(data, dataType, logic, match, strict) {
222
287
 
223
288
  // // // the same as this
224
289
 
290
+ // // // if (!setOfTypes.has(dataType[0])) {
291
+ // // // throw new TypeError("type undefined !");
292
+ // // // }
293
+
225
294
  // // // if (!(typeof dt === dataType[0])) {
226
295
  // // // return false;
227
296
  // // // }
@@ -277,9 +346,13 @@ function checkType(data, dataType, logic, match, strict) {
277
346
  // return true;
278
347
  }
279
348
 
280
- if (logic === or) {
349
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
281
350
  for (let dt of data) {
282
351
  for (let dtype of dataType) {
352
+ if (!setOfTypes.has(dtype)) {
353
+ throw new TypeError(`type ${dtype} undefined !`);
354
+ }
355
+
283
356
  if (typeof dt === dtype) {
284
357
  return true;
285
358
  }
@@ -313,6 +386,10 @@ function checkType(data, dataType, logic, match, strict) {
313
386
 
314
387
  // // // the same as this
315
388
 
389
+ // // // if (!setOfTypes.has(dtype)) {
390
+ // // // throw new TypeError(`type ${dtype} undefined !`);
391
+ // // // }
392
+
316
393
  // // // if (typeof data[0] === dtype) {
317
394
  // // // return true;
318
395
  // // // }
@@ -347,9 +424,13 @@ function checkType(data, dataType, logic, match, strict) {
347
424
 
348
425
  // // // the same as this
349
426
 
350
- // // if (typeof dt === dataType[0]) {
351
- // // return true;
352
- // // }
427
+ // // // if (!setOfTypes.has(dataType[0])) {
428
+ // // // throw new TypeError("type undefined !");
429
+ // // // }
430
+
431
+ // // // if (typeof dt === dataType[0]) {
432
+ // // // return true;
433
+ // // // }
353
434
  // // }
354
435
 
355
436
  // // shared return
@@ -458,10 +539,14 @@ function checkType(data, dataType, logic, match, strict) {
458
539
  min = dataType.length;
459
540
  }
460
541
 
461
- if (logic === and) {
542
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
462
543
  for (let i = 0; i < min; ++i) {
463
544
  // 1 step directly in all cases
464
545
 
546
+ if (!setOfTypes.has(dataType[i])) {
547
+ throw new TypeError(`type ${dataType[i]} undefined !`);
548
+ }
549
+
465
550
  if (!(typeof data[i] === dataType[i])) {
466
551
  return false;
467
552
  }
@@ -479,10 +564,14 @@ function checkType(data, dataType, logic, match, strict) {
479
564
  return true;
480
565
  }
481
566
 
482
- if (logic === or) {
567
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
483
568
  for (let i = 0; i < min; ++i) {
484
569
  // 1 step directly in all cases
485
570
 
571
+ if (!setOfTypes.has(dataType[i])) {
572
+ throw new TypeError(`type ${dataType[i]} undefined !`);
573
+ }
574
+
486
575
  if (typeof data[i] === dataType[i]) {
487
576
  return true;
488
577
  }
@@ -503,10 +592,14 @@ function checkType(data, dataType, logic, match, strict) {
503
592
  throw new TypeError("logic type undefined !");
504
593
  }
505
594
 
506
- if (logic === and) {
595
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
507
596
  for (let i = 0; i < data.length; ++i) {
508
597
  // 1 step directly in all cases
509
598
 
599
+ if (!setOfTypes.has(dataType[i])) {
600
+ throw new TypeError(`type ${dataType[i]} undefined !`);
601
+ }
602
+
510
603
  if (!(typeof data[i] === dataType[i])) {
511
604
  return false;
512
605
  }
@@ -524,10 +617,14 @@ function checkType(data, dataType, logic, match, strict) {
524
617
  return true;
525
618
  }
526
619
 
527
- if (logic === or) {
620
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
528
621
  for (let i = 0; i < data.length; ++i) {
529
622
  // 1 step directly in all cases
530
623
 
624
+ if (!setOfTypes.has(dataType[i])) {
625
+ throw new TypeError(`type ${dataType[i]} undefined !`);
626
+ }
627
+
531
628
  if (typeof data[i] === dataType[i]) {
532
629
  return true;
533
630
  }
@@ -586,7 +683,7 @@ function isinstances(objs, type, logic, match, strict) {
586
683
  );
587
684
  }
588
685
 
589
- if (logic === and) {
686
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
590
687
  for (let obj of objs) {
591
688
  // 1 step directly in all cases
592
689
 
@@ -611,7 +708,7 @@ function isinstances(objs, type, logic, match, strict) {
611
708
  return true;
612
709
  }
613
710
 
614
- if (logic === or) {
711
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
615
712
  for (let obj of objs) {
616
713
  // 1 step directly in all cases
617
714
 
@@ -680,8 +777,12 @@ function isinstances(objs, type, logic, match, strict) {
680
777
  );
681
778
  }
682
779
 
683
- if (!match) {
684
- if (logic === and) {
780
+ if (not(match)) {
781
+ if (objs.length === 0) {
782
+ objs[0] = [];
783
+ }
784
+
785
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
685
786
  outerLoop: for (let obj of objs) {
686
787
  for (let dt of type) {
687
788
  try {
@@ -814,7 +915,7 @@ function isinstances(objs, type, logic, match, strict) {
814
915
  // return true;
815
916
  }
816
917
 
817
- if (logic === or) {
918
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
818
919
  for (let obj of objs) {
819
920
  for (let dt of type) {
820
921
  try {
@@ -1001,7 +1102,7 @@ function isinstances(objs, type, logic, match, strict) {
1001
1102
  min = type.length;
1002
1103
  }
1003
1104
 
1004
- if (logic === and) {
1105
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
1005
1106
  for (let i = 0; i < min; ++i) {
1006
1107
  // 1 step directly in all cases
1007
1108
 
@@ -1028,7 +1129,7 @@ function isinstances(objs, type, logic, match, strict) {
1028
1129
  return true;
1029
1130
  }
1030
1131
 
1031
- if (logic === or) {
1132
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
1032
1133
  for (let i = 0; i < min; ++i) {
1033
1134
  // 1 step directly in all cases
1034
1135
 
@@ -1058,7 +1159,7 @@ function isinstances(objs, type, logic, match, strict) {
1058
1159
  throw new TypeError("logic type undefined !");
1059
1160
  }
1060
1161
 
1061
- if (logic === and) {
1162
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
1062
1163
  for (let i = 0; i < objs.length; ++i) {
1063
1164
  // 1 step directly in all cases
1064
1165
 
@@ -1085,7 +1186,7 @@ function isinstances(objs, type, logic, match, strict) {
1085
1186
  return true;
1086
1187
  }
1087
1188
 
1088
- if (logic === or) {
1189
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
1089
1190
  for (let i = 0; i < objs.length; ++i) {
1090
1191
  // 1 step directly in all cases
1091
1192
 
@@ -1145,7 +1246,7 @@ function instancesof(
1145
1246
 
1146
1247
  if (len < 2) {
1147
1248
  throw new TypeError(
1148
- len == 1
1249
+ len === 1
1149
1250
  ? "instancesof() missing 1 required arguments: 'type'"
1150
1251
  : "instancesof() missing 2 required arguments: 'objs' and 'type'"
1151
1252
  );
@@ -1158,26 +1259,21 @@ function instancesof(
1158
1259
  }
1159
1260
 
1160
1261
  if (len === 3) {
1161
- switch (arguments[2]) {
1162
- case true:
1163
- case false:
1164
- return isinstances(objs, type, and, logic_or_match, strict);
1262
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1263
+ return isinstances(objs, type, and, logic_or_match, strict);
1165
1264
  }
1166
1265
  }
1167
1266
 
1168
1267
  if (len === 4) {
1169
- switch (arguments[3]) {
1170
- case true:
1171
- case false:
1172
- break;
1173
- default:
1174
- throw new TypeError("forth argument must be true or false");
1268
+ if (
1269
+ not(checkType(arguments[3], boolean)) &&
1270
+ not(arguments[3] instanceof Boolean)
1271
+ ) {
1272
+ throw new TypeError("forth argument must be true or false");
1175
1273
  }
1176
1274
 
1177
- switch (arguments[2]) {
1178
- case true:
1179
- case false:
1180
- return isinstances(objs, type, and, logic_or_match, match_or_strict);
1275
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1276
+ return isinstances(objs, type, and, logic_or_match, match_or_strict);
1181
1277
  }
1182
1278
  }
1183
1279
 
@@ -1212,7 +1308,7 @@ function isType(
1212
1308
 
1213
1309
  if (len < 2) {
1214
1310
  throw new TypeError(
1215
- len == 1
1311
+ len === 1
1216
1312
  ? "isType() missing 1 required arguments: 'dataType'"
1217
1313
  : "isType() missing 2 required arguments: 'data' and 'dataType'"
1218
1314
  );
@@ -1225,26 +1321,21 @@ function isType(
1225
1321
  }
1226
1322
 
1227
1323
  if (len === 3) {
1228
- switch (arguments[2]) {
1229
- case true:
1230
- case false:
1231
- return checkType(data, dataType, and, logic_or_match, strict);
1324
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1325
+ return checkType(data, dataType, and, logic_or_match, strict);
1232
1326
  }
1233
1327
  }
1234
1328
 
1235
1329
  if (len === 4) {
1236
- switch (arguments[3]) {
1237
- case true:
1238
- case false:
1239
- break;
1240
- default:
1241
- throw new TypeError("forth argument must be true or false");
1330
+ if (
1331
+ not(checkType(arguments[3], boolean)) &&
1332
+ not(arguments[3] instanceof Boolean)
1333
+ ) {
1334
+ throw new TypeError("forth argument must be true or false");
1242
1335
  }
1243
1336
 
1244
- switch (arguments[2]) {
1245
- case true:
1246
- case false:
1247
- return checkType(data, dataType, and, logic_or_match, match_or_strict);
1337
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1338
+ return checkType(data, dataType, and, logic_or_match, match_or_strict);
1248
1339
  }
1249
1340
  }
1250
1341
 
@@ -1626,11 +1717,18 @@ module.exports = {
1626
1717
  or,
1627
1718
  bigint,
1628
1719
  func,
1720
+ fun,
1721
+ fn,
1629
1722
  number,
1723
+ num,
1630
1724
  object,
1725
+ obj,
1726
+ nil,
1631
1727
  string,
1728
+ str,
1632
1729
  symbol,
1633
1730
  boolean,
1731
+ bool,
1634
1732
  undef,
1635
1733
  instancesof,
1636
1734
  isType,
package/jsfunx.mjs CHANGED
@@ -50,18 +50,42 @@ export const func = "function";
50
50
 
51
51
  /** @type {string} */
52
52
 
53
+ export const fun = "function";
54
+
55
+ /** @type {string} */
56
+
57
+ export const fn = "function";
58
+
59
+ /** @type {string} */
60
+
53
61
  export const number = "number";
54
62
 
55
63
  /** @type {string} */
56
64
 
65
+ export const num = "number";
66
+
67
+ /** @type {string} */
68
+
57
69
  export const object = "object";
58
70
 
59
71
  /** @type {string} */
60
72
 
73
+ export const obj = "object";
74
+
75
+ /** @type {string} */
76
+
77
+ export const nil = "object"; // don't use this with objects, use it only with the null primitive.
78
+
79
+ /** @type {string} */
80
+
61
81
  export const string = "string";
62
82
 
63
83
  /** @type {string} */
64
84
 
85
+ export const str = "string";
86
+
87
+ /** @type {string} */
88
+
65
89
  export const symbol = "symbol";
66
90
 
67
91
  /** @type {string} */
@@ -70,6 +94,10 @@ export const boolean = "boolean";
70
94
 
71
95
  /** @type {string} */
72
96
 
97
+ export const bool = "boolean";
98
+
99
+ /** @type {string} */
100
+
73
101
  export const undef = "undefined";
74
102
 
75
103
  /**
@@ -88,14 +116,35 @@ export const undef = "undefined";
88
116
  */
89
117
 
90
118
  function checkType(data, dataType, logic, match, strict) {
91
- // if data or dataType is Array must be nested Array
119
+ /** @type {Set<string>} */
120
+
121
+ let setOfTypes = new Set([
122
+ and,
123
+ or,
124
+ bigint,
125
+ func,
126
+ number,
127
+ object,
128
+ string,
129
+ symbol,
130
+ boolean,
131
+ undef,
132
+ ]);
92
133
 
93
134
  if (!(dataType instanceof Array)) {
135
+ if (!setOfTypes.has(dataType)) {
136
+ throw new TypeError("type undefined !");
137
+ }
138
+
94
139
  if (!(data instanceof Array)) {
95
140
  return typeof data === dataType;
96
141
  }
97
142
 
98
- if (logic === and) {
143
+ if (data.length === 0) {
144
+ data[0] = [];
145
+ }
146
+
147
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
99
148
  for (let dt of data) {
100
149
  // 1 step directly in all cases
101
150
 
@@ -114,7 +163,7 @@ function checkType(data, dataType, logic, match, strict) {
114
163
  return true;
115
164
  }
116
165
 
117
- if (logic === or) {
166
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
118
167
  for (let dt of data) {
119
168
  // 1 step directly in all cases
120
169
 
@@ -140,6 +189,10 @@ function checkType(data, dataType, logic, match, strict) {
140
189
  for (let dtype of dataType) {
141
190
  // 1 step directly in all cases
142
191
 
192
+ if (!setOfTypes.has(dtype)) {
193
+ throw new TypeError(`type ${dtype} undefined !`);
194
+ }
195
+
143
196
  if (typeof data === dtype) {
144
197
  return true;
145
198
  }
@@ -155,10 +208,18 @@ function checkType(data, dataType, logic, match, strict) {
155
208
  return false;
156
209
  }
157
210
 
158
- if (!match) {
159
- if (logic === and) {
211
+ if (data.length === 0) {
212
+ data[0] = [];
213
+ }
214
+
215
+ if (not(match)) {
216
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
160
217
  outerLoop: for (let dt of data) {
161
218
  for (let dtype of dataType) {
219
+ if (!setOfTypes.has(dtype)) {
220
+ throw new TypeError(`type ${dtype} undefined !`);
221
+ }
222
+
162
223
  if (typeof dt === dtype) {
163
224
  continue outerLoop;
164
225
  }
@@ -196,6 +257,10 @@ function checkType(data, dataType, logic, match, strict) {
196
257
 
197
258
  // // // the same as this
198
259
 
260
+ // // // if (!setOfTypes.has(dtype)) {
261
+ // // // throw new TypeError(`type ${dtype} undefined !`);
262
+ // // // }
263
+
199
264
  // // // if (typeof data[0] === dtype) {
200
265
  // // // return true;
201
266
  // // // }
@@ -228,6 +293,10 @@ function checkType(data, dataType, logic, match, strict) {
228
293
 
229
294
  // // // the same as this
230
295
 
296
+ // // // if (!setOfTypes.has(dataType[0])) {
297
+ // // // throw new TypeError("type undefined !");
298
+ // // // }
299
+
231
300
  // // // if (!(typeof dt === dataType[0])) {
232
301
  // // // return false;
233
302
  // // // }
@@ -283,9 +352,13 @@ function checkType(data, dataType, logic, match, strict) {
283
352
  // return true;
284
353
  }
285
354
 
286
- if (logic === or) {
355
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
287
356
  for (let dt of data) {
288
357
  for (let dtype of dataType) {
358
+ if (!setOfTypes.has(dtype)) {
359
+ throw new TypeError(`type ${dtype} undefined !`);
360
+ }
361
+
289
362
  if (typeof dt === dtype) {
290
363
  return true;
291
364
  }
@@ -319,6 +392,10 @@ function checkType(data, dataType, logic, match, strict) {
319
392
 
320
393
  // // // the same as this
321
394
 
395
+ // // // if (!setOfTypes.has(dtype)) {
396
+ // // // throw new TypeError(`type ${dtype} undefined !`);
397
+ // // // }
398
+
322
399
  // // // if (typeof data[0] === dtype) {
323
400
  // // // return true;
324
401
  // // // }
@@ -353,9 +430,13 @@ function checkType(data, dataType, logic, match, strict) {
353
430
 
354
431
  // // // the same as this
355
432
 
356
- // // if (typeof dt === dataType[0]) {
357
- // // return true;
358
- // // }
433
+ // // // if (!setOfTypes.has(dataType[0])) {
434
+ // // // throw new TypeError("type undefined !");
435
+ // // // }
436
+
437
+ // // // if (typeof dt === dataType[0]) {
438
+ // // // return true;
439
+ // // // }
359
440
  // // }
360
441
 
361
442
  // // shared return
@@ -464,10 +545,14 @@ function checkType(data, dataType, logic, match, strict) {
464
545
  min = dataType.length;
465
546
  }
466
547
 
467
- if (logic === and) {
548
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
468
549
  for (let i = 0; i < min; ++i) {
469
550
  // 1 step directly in all cases
470
551
 
552
+ if (!setOfTypes.has(dataType[i])) {
553
+ throw new TypeError(`type ${dataType[i]} undefined !`);
554
+ }
555
+
471
556
  if (!(typeof data[i] === dataType[i])) {
472
557
  return false;
473
558
  }
@@ -485,10 +570,14 @@ function checkType(data, dataType, logic, match, strict) {
485
570
  return true;
486
571
  }
487
572
 
488
- if (logic === or) {
573
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
489
574
  for (let i = 0; i < min; ++i) {
490
575
  // 1 step directly in all cases
491
576
 
577
+ if (!setOfTypes.has(dataType[i])) {
578
+ throw new TypeError(`type ${dataType[i]} undefined !`);
579
+ }
580
+
492
581
  if (typeof data[i] === dataType[i]) {
493
582
  return true;
494
583
  }
@@ -509,10 +598,14 @@ function checkType(data, dataType, logic, match, strict) {
509
598
  throw new TypeError("logic type undefined !");
510
599
  }
511
600
 
512
- if (logic === and) {
601
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
513
602
  for (let i = 0; i < data.length; ++i) {
514
603
  // 1 step directly in all cases
515
604
 
605
+ if (!setOfTypes.has(dataType[i])) {
606
+ throw new TypeError(`type ${dataType[i]} undefined !`);
607
+ }
608
+
516
609
  if (!(typeof data[i] === dataType[i])) {
517
610
  return false;
518
611
  }
@@ -530,10 +623,14 @@ function checkType(data, dataType, logic, match, strict) {
530
623
  return true;
531
624
  }
532
625
 
533
- if (logic === or) {
626
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
534
627
  for (let i = 0; i < data.length; ++i) {
535
628
  // 1 step directly in all cases
536
629
 
630
+ if (!setOfTypes.has(dataType[i])) {
631
+ throw new TypeError(`type ${dataType[i]} undefined !`);
632
+ }
633
+
537
634
  if (typeof data[i] === dataType[i]) {
538
635
  return true;
539
636
  }
@@ -592,7 +689,7 @@ function isinstances(objs, type, logic, match, strict) {
592
689
  );
593
690
  }
594
691
 
595
- if (logic === and) {
692
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
596
693
  for (let obj of objs) {
597
694
  // 1 step directly in all cases
598
695
 
@@ -617,7 +714,7 @@ function isinstances(objs, type, logic, match, strict) {
617
714
  return true;
618
715
  }
619
716
 
620
- if (logic === or) {
717
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
621
718
  for (let obj of objs) {
622
719
  // 1 step directly in all cases
623
720
 
@@ -686,8 +783,12 @@ function isinstances(objs, type, logic, match, strict) {
686
783
  );
687
784
  }
688
785
 
689
- if (!match) {
690
- if (logic === and) {
786
+ if (not(match)) {
787
+ if (objs.length === 0) {
788
+ objs[0] = [];
789
+ }
790
+
791
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
691
792
  outerLoop: for (let obj of objs) {
692
793
  for (let dt of type) {
693
794
  try {
@@ -820,7 +921,7 @@ function isinstances(objs, type, logic, match, strict) {
820
921
  // return true;
821
922
  }
822
923
 
823
- if (logic === or) {
924
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
824
925
  for (let obj of objs) {
825
926
  for (let dt of type) {
826
927
  try {
@@ -1007,7 +1108,7 @@ function isinstances(objs, type, logic, match, strict) {
1007
1108
  min = type.length;
1008
1109
  }
1009
1110
 
1010
- if (logic === and) {
1111
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
1011
1112
  for (let i = 0; i < min; ++i) {
1012
1113
  // 1 step directly in all cases
1013
1114
 
@@ -1034,7 +1135,7 @@ function isinstances(objs, type, logic, match, strict) {
1034
1135
  return true;
1035
1136
  }
1036
1137
 
1037
- if (logic === or) {
1138
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
1038
1139
  for (let i = 0; i < min; ++i) {
1039
1140
  // 1 step directly in all cases
1040
1141
 
@@ -1064,7 +1165,7 @@ function isinstances(objs, type, logic, match, strict) {
1064
1165
  throw new TypeError("logic type undefined !");
1065
1166
  }
1066
1167
 
1067
- if (logic === and) {
1168
+ if (logic === and || (logic instanceof String && logic.valueOf() === and)) {
1068
1169
  for (let i = 0; i < objs.length; ++i) {
1069
1170
  // 1 step directly in all cases
1070
1171
 
@@ -1091,7 +1192,7 @@ function isinstances(objs, type, logic, match, strict) {
1091
1192
  return true;
1092
1193
  }
1093
1194
 
1094
- if (logic === or) {
1195
+ if (logic === or || (logic instanceof String && logic.valueOf() === or)) {
1095
1196
  for (let i = 0; i < objs.length; ++i) {
1096
1197
  // 1 step directly in all cases
1097
1198
 
@@ -1151,7 +1252,7 @@ export function instancesof(
1151
1252
 
1152
1253
  if (len < 2) {
1153
1254
  throw new TypeError(
1154
- len == 1
1255
+ len === 1
1155
1256
  ? "instancesof() missing 1 required arguments: 'type'"
1156
1257
  : "instancesof() missing 2 required arguments: 'objs' and 'type'"
1157
1258
  );
@@ -1164,26 +1265,21 @@ export function instancesof(
1164
1265
  }
1165
1266
 
1166
1267
  if (len === 3) {
1167
- switch (arguments[2]) {
1168
- case true:
1169
- case false:
1170
- return isinstances(objs, type, and, logic_or_match, strict);
1268
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1269
+ return isinstances(objs, type, and, logic_or_match, strict);
1171
1270
  }
1172
1271
  }
1173
1272
 
1174
1273
  if (len === 4) {
1175
- switch (arguments[3]) {
1176
- case true:
1177
- case false:
1178
- break;
1179
- default:
1180
- throw new TypeError("forth argument must be true or false");
1274
+ if (
1275
+ not(checkType(arguments[3], boolean)) &&
1276
+ not(arguments[3] instanceof Boolean)
1277
+ ) {
1278
+ throw new TypeError("forth argument must be true or false");
1181
1279
  }
1182
1280
 
1183
- switch (arguments[2]) {
1184
- case true:
1185
- case false:
1186
- return isinstances(objs, type, and, logic_or_match, match_or_strict);
1281
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1282
+ return isinstances(objs, type, and, logic_or_match, match_or_strict);
1187
1283
  }
1188
1284
  }
1189
1285
 
@@ -1218,7 +1314,7 @@ export function isType(
1218
1314
 
1219
1315
  if (len < 2) {
1220
1316
  throw new TypeError(
1221
- len == 1
1317
+ len === 1
1222
1318
  ? "isType() missing 1 required arguments: 'dataType'"
1223
1319
  : "isType() missing 2 required arguments: 'data' and 'dataType'"
1224
1320
  );
@@ -1231,26 +1327,21 @@ export function isType(
1231
1327
  }
1232
1328
 
1233
1329
  if (len === 3) {
1234
- switch (arguments[2]) {
1235
- case true:
1236
- case false:
1237
- return checkType(data, dataType, and, logic_or_match, strict);
1330
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1331
+ return checkType(data, dataType, and, logic_or_match, strict);
1238
1332
  }
1239
1333
  }
1240
1334
 
1241
1335
  if (len === 4) {
1242
- switch (arguments[3]) {
1243
- case true:
1244
- case false:
1245
- break;
1246
- default:
1247
- throw new TypeError("forth argument must be true or false");
1336
+ if (
1337
+ not(checkType(arguments[3], boolean)) &&
1338
+ not(arguments[3] instanceof Boolean)
1339
+ ) {
1340
+ throw new TypeError("forth argument must be true or false");
1248
1341
  }
1249
1342
 
1250
- switch (arguments[2]) {
1251
- case true:
1252
- case false:
1253
- return checkType(data, dataType, and, logic_or_match, match_or_strict);
1343
+ if (checkType(arguments[2], boolean) || arguments[2] instanceof Boolean) {
1344
+ return checkType(data, dataType, and, logic_or_match, match_or_strict);
1254
1345
  }
1255
1346
  }
1256
1347
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfunx",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "JavaScript utility functions for cleaner, more readable code",
5
5
  "main": "./jsfunx.cjs",
6
6
  "module": "./jsfunx.mjs",