@leyyo/common 1.0.0

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/dist/aliases.d.ts +139 -0
  4. package/dist/aliases.js +4 -0
  5. package/dist/assertion/assert.d.ts +6 -0
  6. package/dist/assertion/assert.js +13 -0
  7. package/dist/assertion/common-assertion-impl.d.ts +34 -0
  8. package/dist/assertion/common-assertion-impl.js +210 -0
  9. package/dist/assertion/index-types.d.ts +79 -0
  10. package/dist/assertion/index-types.js +2 -0
  11. package/dist/assertion/index.d.ts +3 -0
  12. package/dist/assertion/index.js +19 -0
  13. package/dist/callback/common-callback-impl.d.ts +31 -0
  14. package/dist/callback/common-callback-impl.js +134 -0
  15. package/dist/callback/index-types.d.ts +75 -0
  16. package/dist/callback/index-types.js +2 -0
  17. package/dist/callback/index.d.ts +2 -0
  18. package/dist/callback/index.js +18 -0
  19. package/dist/constants.d.ts +7 -0
  20. package/dist/constants.js +10 -0
  21. package/dist/error/assertion-exception.d.ts +5 -0
  22. package/dist/error/assertion-exception.js +11 -0
  23. package/dist/error/caused-exception.d.ts +5 -0
  24. package/dist/error/caused-exception.js +12 -0
  25. package/dist/error/common-error-impl.d.ts +24 -0
  26. package/dist/error/common-error-impl.js +88 -0
  27. package/dist/error/developer-exception.d.ts +5 -0
  28. package/dist/error/developer-exception.js +11 -0
  29. package/dist/error/exception.d.ts +33 -0
  30. package/dist/error/exception.js +124 -0
  31. package/dist/error/index-types.d.ts +70 -0
  32. package/dist/error/index-types.js +2 -0
  33. package/dist/error/index.d.ts +7 -0
  34. package/dist/error/index.js +23 -0
  35. package/dist/error/multiple-exception.d.ts +8 -0
  36. package/dist/error/multiple-exception.js +33 -0
  37. package/dist/index.d.ts +7 -0
  38. package/dist/index.js +26 -0
  39. package/dist/internal.d.ts +1 -0
  40. package/dist/internal.js +4 -0
  41. package/dist/is/common-is-impl.d.ts +22 -0
  42. package/dist/is/common-is-impl.js +66 -0
  43. package/dist/is/index-types.d.ts +22 -0
  44. package/dist/is/index-types.js +2 -0
  45. package/dist/is/index.d.ts +2 -0
  46. package/dist/is/index.js +18 -0
  47. package/dist/leyyo/index-types.d.ts +16 -0
  48. package/dist/leyyo/index-types.js +2 -0
  49. package/dist/leyyo/index.d.ts +2 -0
  50. package/dist/leyyo/index.js +18 -0
  51. package/dist/leyyo/leyyo-impl.d.ts +24 -0
  52. package/dist/leyyo/leyyo-impl.js +71 -0
  53. package/dist/literals.d.ts +98 -0
  54. package/dist/literals.js +77 -0
  55. package/dist/log/common-log-impl.d.ts +13 -0
  56. package/dist/log/common-log-impl.js +59 -0
  57. package/dist/log/index-types.d.ts +58 -0
  58. package/dist/log/index-types.js +3 -0
  59. package/dist/log/index.d.ts +3 -0
  60. package/dist/log/index.js +19 -0
  61. package/dist/log/logger-impl.d.ts +23 -0
  62. package/dist/log/logger-impl.js +73 -0
  63. package/dist/storage/common-storage-impl.d.ts +46 -0
  64. package/dist/storage/common-storage-impl.js +150 -0
  65. package/dist/storage/index-types.d.ts +102 -0
  66. package/dist/storage/index-types.js +2 -0
  67. package/dist/storage/index.d.ts +3 -0
  68. package/dist/storage/index.js +19 -0
  69. package/dist/storage/list.d.ts +9 -0
  70. package/dist/storage/list.js +16 -0
  71. package/dist/to/common-to-impl.d.ts +38 -0
  72. package/dist/to/common-to-impl.js +553 -0
  73. package/dist/to/index-types.d.ts +50 -0
  74. package/dist/to/index-types.js +2 -0
  75. package/dist/to/index.d.ts +2 -0
  76. package/dist/to/index.js +18 -0
  77. package/package.json +53 -0
@@ -0,0 +1,553 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonToImpl = void 0;
4
+ const literals_1 = require("../literals");
5
+ const error_1 = require("../error");
6
+ // noinspection JSUnusedGlobalSymbols
7
+ class CommonToImpl {
8
+ constructor() {
9
+ // region properties
10
+ this._EXPECTED_ANY = ['string', 'boolean', 'bigint', 'object', 'number', 'array'];
11
+ this._EXPECTED_ARRAY = ['array'];
12
+ this._EXPECTED_BOOL = ['boolean', 'string', 'number'];
13
+ this._EXPECTED_CLASS = ['string', 'function', 'object'];
14
+ this._EXPECTED_DATE = ['string', 'number', 'date', 'moment'];
15
+ this._EXPECTED_ENUM = ['string', 'number'];
16
+ this._EXPECTED_NUMBER = ['string', 'number', 'bigint'];
17
+ this._EXPECTED_STRING = ['boolean', 'string', 'number'];
18
+ // endregion secure
19
+ }
20
+ // endregion properties
21
+ // region private
22
+ _enumInMap(value, map) {
23
+ // regular, in values
24
+ if (Object.values(map).includes(value)) {
25
+ return value;
26
+ }
27
+ // ir-regular, in keys
28
+ if (Object.keys(map).includes(value)) {
29
+ return map[value];
30
+ }
31
+ if (typeof value === 'string') {
32
+ // regular, in lower-case
33
+ let str = value.toLowerCase();
34
+ let v = this._enumInMap(str, map);
35
+ if (v !== null) {
36
+ return v;
37
+ }
38
+ // regular, in upper-case
39
+ str = str.toUpperCase();
40
+ v = this._enumInMap(str, map);
41
+ if (v !== null) {
42
+ return v;
43
+ }
44
+ if (/^[0-9]+$/.test(value)) {
45
+ try {
46
+ return this._enumInMap(parseInt(value, 10), map);
47
+ }
48
+ catch (e) {
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ return null;
54
+ }
55
+ _enumInArray(value, arr) {
56
+ // regular, in values
57
+ if (arr.includes(value)) {
58
+ return value;
59
+ }
60
+ if (typeof value === 'string') {
61
+ // regular, in lower-case
62
+ let str = value.toLowerCase();
63
+ let v = this._enumInArray(str, arr);
64
+ if (v !== null) {
65
+ return v;
66
+ }
67
+ // regular, in upper-case
68
+ str = str.toUpperCase();
69
+ v = this._enumInArray(str, arr);
70
+ if (v !== null) {
71
+ return v;
72
+ }
73
+ if (/^[0-9]+$/.test(value)) {
74
+ try {
75
+ return this._enumInArray(parseInt(value, 10), arr);
76
+ }
77
+ catch (e) {
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+ return null;
83
+ }
84
+ // noinspection JSMethodCanBeStatic
85
+ _enumInAlteration(value, alt) {
86
+ // ir-regular, in keys
87
+ if (Object.keys(alt).includes(value)) {
88
+ return alt[value];
89
+ }
90
+ if (typeof value === 'string') {
91
+ // regular, in lower-case
92
+ let str = value.toLowerCase();
93
+ let v = this._enumInAlteration(str, alt);
94
+ if (v !== null) {
95
+ return v;
96
+ }
97
+ // regular, in upper-case
98
+ str = str.toUpperCase();
99
+ v = this._enumInAlteration(str, alt);
100
+ if (v !== null) {
101
+ return v;
102
+ }
103
+ if (/^[0-9]+$/.test(value)) {
104
+ try {
105
+ return this._enumInAlteration(parseInt(value, 10), alt);
106
+ }
107
+ catch (e) {
108
+ }
109
+ }
110
+ return null;
111
+ }
112
+ return null;
113
+ }
114
+ // endregion private
115
+ // region utility
116
+ runFn(fn, value, opt) {
117
+ try {
118
+ return fn(value());
119
+ }
120
+ catch (e) {
121
+ if (!opt.silent) {
122
+ delete opt.silent;
123
+ let indicator;
124
+ if (opt.indicator !== undefined) {
125
+ indicator = opt.indicator;
126
+ }
127
+ else {
128
+ indicator = 'assertion.error';
129
+ }
130
+ this.assertion.raise(opt, value.name, indicator);
131
+ }
132
+ }
133
+ return null;
134
+ }
135
+ runSave(fn, value, opt) {
136
+ try {
137
+ return fn(value);
138
+ }
139
+ catch (e) {
140
+ error_1.Exception.cast(e).raise(!(opt === null || opt === void 0 ? void 0 : opt.silent));
141
+ }
142
+ return null;
143
+ }
144
+ raiseInvalidValue(value, expected, opt, params) {
145
+ let indicator;
146
+ if (opt.indicator !== undefined) {
147
+ indicator = opt.indicator;
148
+ }
149
+ else {
150
+ indicator = 'type.invalid-value';
151
+ }
152
+ opt = Object.assign(Object.assign(Object.assign({}, opt), params), { expected, value });
153
+ new error_1.DeveloperException(indicator, opt)
154
+ .with(this)
155
+ .raise(!(opt === null || opt === void 0 ? void 0 : opt.silent));
156
+ return null;
157
+ }
158
+ // endregion utility
159
+ // region types
160
+ any(value, opt) {
161
+ if (this.is.empty(value)) {
162
+ return null;
163
+ }
164
+ switch (typeof value) {
165
+ case 'string':
166
+ case 'boolean':
167
+ case 'bigint':
168
+ case 'object':
169
+ return value;
170
+ case 'number':
171
+ return this.assertion.realNumber(value, opt);
172
+ case 'function':
173
+ return this.runFn(v => this.any(v, opt), value, opt);
174
+ }
175
+ return this.raiseInvalidValue(value, this._EXPECTED_ANY, opt);
176
+ }
177
+ array(value, opt) {
178
+ var _a, _b;
179
+ if (this.is.empty(value)) {
180
+ return null;
181
+ }
182
+ switch (typeof value) {
183
+ case "string":
184
+ case "boolean":
185
+ case "number":
186
+ case "bigint":
187
+ return this.array([value], opt);
188
+ case 'object':
189
+ if (Array.isArray(value)) {
190
+ opt = opt !== null && opt !== void 0 ? opt : {};
191
+ const result = [];
192
+ const valueFn = (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.children) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.fn;
193
+ if (typeof valueFn !== "function") {
194
+ result.push(...value);
195
+ }
196
+ else {
197
+ const clonedOpt = Object.assign({}, opt);
198
+ value.forEach((v, index) => {
199
+ clonedOpt.param = opt.param ? `${opt.param}#${index}` : `#${index}`;
200
+ try {
201
+ result.push(valueFn(v, clonedOpt));
202
+ }
203
+ catch (e) {
204
+ error_1.Exception.cast(e).raise(!opt.silent);
205
+ result.push(null);
206
+ }
207
+ });
208
+ }
209
+ return result;
210
+ }
211
+ return this.array([value], opt);
212
+ case 'function':
213
+ return this.runFn(v => this.array(v, opt), value, opt);
214
+ }
215
+ return this.raiseInvalidValue(value, this._EXPECTED_ARRAY, opt);
216
+ }
217
+ boolean(value, opt) {
218
+ if (this.is.empty(value)) {
219
+ return null;
220
+ }
221
+ switch (typeof value) {
222
+ case 'boolean':
223
+ return value;
224
+ case 'string':
225
+ value = value.trim().toLowerCase();
226
+ if (value === '') {
227
+ return null;
228
+ }
229
+ if (literals_1.WeakTrueItems.includes(value)) {
230
+ return true;
231
+ }
232
+ if (literals_1.WeakFalseItems.includes(value)) {
233
+ return false;
234
+ }
235
+ return this.raiseInvalidValue(value, this._EXPECTED_BOOL, opt);
236
+ case 'number':
237
+ return value > 0;
238
+ case 'object':
239
+ if (Array.isArray(value) && value.length === 1) {
240
+ return this.boolean(value[0], opt);
241
+ }
242
+ break;
243
+ case 'function':
244
+ return this.runFn(v => this.boolean(v, opt), value, opt);
245
+ }
246
+ return this.raiseInvalidValue(value, this._EXPECTED_BOOL, opt);
247
+ }
248
+ clazz(value, opt) {
249
+ if (this.is.empty(value)) {
250
+ return null;
251
+ }
252
+ switch (typeof value) {
253
+ case 'string':
254
+ value = value.trim();
255
+ if (value === '') {
256
+ return null;
257
+ }
258
+ return value;
259
+ case 'object':
260
+ case 'function':
261
+ return this.callback.fqnName(value);
262
+ }
263
+ return this.raiseInvalidValue(value, this._EXPECTED_CLASS, opt);
264
+ }
265
+ date(value, opt) {
266
+ if (this.is.empty(value)) {
267
+ return null;
268
+ }
269
+ switch (typeof value) {
270
+ case 'object':
271
+ if (value instanceof Date) {
272
+ return value;
273
+ }
274
+ else if (typeof value['toDate'] === 'function') {
275
+ return this.date(this.runSave(v => v.toDate(), value, opt), opt);
276
+ }
277
+ if (Array.isArray(value)) {
278
+ const arr = value;
279
+ if (arr.length === 1) {
280
+ return this.date(arr[0], opt);
281
+ }
282
+ if (arr.length > 1 && arr.length < 8) {
283
+ return this.date(this.runSave(v => new Date(v[0], v[1], v[2], v[3], v[4], v[5], v[6]), value, opt), opt);
284
+ }
285
+ }
286
+ else if (value.id !== undefined) {
287
+ return this.date(value.id, opt);
288
+ }
289
+ break;
290
+ case 'string':
291
+ if (value.trim() === '') {
292
+ return null;
293
+ }
294
+ return this.date(this.runSave(v => new Date(v), value.trim(), opt), opt);
295
+ case 'bigint':
296
+ return this.date(this.runSave(v => new Date(Number(v)), value, opt), opt);
297
+ case 'number':
298
+ return this.date(this.runSave(v => new Date(v), value, opt), opt);
299
+ case 'function':
300
+ return this.runFn(v => this.date(v, opt), value, opt);
301
+ }
302
+ return this.raiseInvalidValue(value, this._EXPECTED_DATE, opt);
303
+ }
304
+ enumeration(value, opt) {
305
+ if (this.is.empty(value)) {
306
+ return null;
307
+ }
308
+ opt = opt !== null && opt !== void 0 ? opt : {};
309
+ let mapType = null;
310
+ if (this.is.object(opt.map)) {
311
+ mapType = 'object';
312
+ }
313
+ else if (this.is.array(opt.map)) {
314
+ mapType = 'array';
315
+ }
316
+ if (!mapType) {
317
+ throw new error_1.DeveloperException('type.invalid-enum-items', { map: opt.map });
318
+ }
319
+ let v;
320
+ switch (typeof value) {
321
+ case 'string':
322
+ value = value.trim();
323
+ if (value === '') {
324
+ return null;
325
+ }
326
+ if (mapType === 'object') {
327
+ v = this._enumInMap(value, opt.map);
328
+ }
329
+ else {
330
+ v = this._enumInArray(value, opt.map);
331
+ }
332
+ if (v !== null) {
333
+ return v;
334
+ }
335
+ if (this.is.object(opt.alt)) {
336
+ v = this._enumInAlteration(value, opt.alt);
337
+ if (v !== null) {
338
+ return v;
339
+ }
340
+ }
341
+ return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
342
+ case 'number':
343
+ const num = this.assertion.realNumber(value, opt);
344
+ if (num === null) {
345
+ return null;
346
+ }
347
+ if (mapType === 'object') {
348
+ v = this._enumInMap(value, opt.map);
349
+ }
350
+ else {
351
+ v = this._enumInArray(value, opt.map);
352
+ }
353
+ if (v !== null) {
354
+ return v;
355
+ }
356
+ if (this.is.object(opt.alt)) {
357
+ v = this._enumInAlteration(value, opt.alt);
358
+ if (v !== null) {
359
+ return v;
360
+ }
361
+ }
362
+ return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
363
+ case 'object':
364
+ if (Array.isArray(value) && value.length === 1) {
365
+ return this.enumeration(value[0], opt);
366
+ }
367
+ return this.enumeration(value.id, opt);
368
+ case 'function':
369
+ return this.runFn(v => this.enumeration(v, opt), value, opt);
370
+ }
371
+ return this.raiseInvalidValue(value, this._EXPECTED_ENUM, opt);
372
+ }
373
+ float(value, opt) {
374
+ if (this.is.empty(value)) {
375
+ return null;
376
+ }
377
+ switch (typeof value) {
378
+ case 'string':
379
+ return this.float(this.runSave(parseFloat, value.trim(), opt), opt);
380
+ case 'number':
381
+ return this.assertion.realNumber(value, opt);
382
+ case 'bigint':
383
+ return this.float(this.runSave(Number, value, opt), opt);
384
+ case 'boolean':
385
+ return value ? 1 : 0;
386
+ case 'object':
387
+ if (Array.isArray(value) && value.length === 1) {
388
+ return this.float(value[0], opt);
389
+ }
390
+ return this.float(value.id, opt);
391
+ case 'function':
392
+ return this.runFn(v => this.float(v, opt), value, opt);
393
+ }
394
+ return this.raiseInvalidValue(value, this._EXPECTED_NUMBER, opt);
395
+ }
396
+ func(value, opt) {
397
+ if (this.is.empty(value)) {
398
+ return null;
399
+ }
400
+ switch (typeof value) {
401
+ case "function":
402
+ return value;
403
+ case 'object':
404
+ if (Array.isArray(value) && value.length === 1) {
405
+ return this.func(value[0], opt);
406
+ }
407
+ break;
408
+ }
409
+ return this.raiseInvalidValue(value, ['function'], opt);
410
+ }
411
+ integer(value, opt) {
412
+ if (this.is.empty(value)) {
413
+ return null;
414
+ }
415
+ switch (typeof value) {
416
+ case 'string':
417
+ return this.integer(this.runSave(parseFloat, value.trim(), opt), opt);
418
+ case 'number':
419
+ let num = this.assertion.realNumber(value, opt);
420
+ if (num !== null && !Number.isSafeInteger(num)) {
421
+ num = Math.floor(num);
422
+ }
423
+ return num;
424
+ case 'bigint':
425
+ return this.integer(this.runSave(Number, value, opt), opt);
426
+ case 'boolean':
427
+ return value ? 1 : 0;
428
+ case 'object':
429
+ if (Array.isArray(value) && value.length === 1) {
430
+ return this.integer(value[0], opt);
431
+ }
432
+ return this.integer(value.id, opt);
433
+ case 'function':
434
+ return this.runFn(v => this.integer(v, opt), value, opt);
435
+ }
436
+ return this.raiseInvalidValue(value, this._EXPECTED_NUMBER, opt);
437
+ }
438
+ object(value, opt) {
439
+ return this.dict(value, opt);
440
+ }
441
+ dict(value, opt) {
442
+ var _a, _b, _c, _d;
443
+ if (this.is.empty(value)) {
444
+ return null;
445
+ }
446
+ switch (typeof value) {
447
+ case 'object':
448
+ if (Array.isArray(value)) {
449
+ if (value.length === 1) {
450
+ return this.object(value[0], opt);
451
+ }
452
+ }
453
+ else {
454
+ opt = opt !== null && opt !== void 0 ? opt : {};
455
+ const keyOpt = Object.assign(Object.assign({}, ((_b = (_a = opt === null || opt === void 0 ? void 0 : opt.children) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : {})), opt);
456
+ if (typeof keyOpt.fn !== 'function') {
457
+ keyOpt.fn = (k, o) => {
458
+ if (!this.is.key(k)) {
459
+ this.raiseInvalidValue(k, ['string', 'number'], o, { key: k });
460
+ }
461
+ return k;
462
+ };
463
+ }
464
+ const valueOpt = Object.assign(Object.assign({}, ((_d = (_c = opt === null || opt === void 0 ? void 0 : opt.children) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : {})), opt);
465
+ if (typeof valueOpt.fn !== 'function') {
466
+ valueOpt.fn = (v) => {
467
+ return v;
468
+ };
469
+ }
470
+ const result = {};
471
+ for (const [k, v] of Object.entries(value)) {
472
+ keyOpt.param = opt.param ? `${opt.param}.${k}` : `${k}`;
473
+ valueOpt.param = opt.param ? `${opt.param}.${k}` : `${k}`;
474
+ try {
475
+ result[keyOpt.fn(k, keyOpt)] = valueOpt.fn(v, valueOpt);
476
+ }
477
+ catch (e) {
478
+ error_1.Exception.cast(e).raise(!opt.silent);
479
+ result[k] = null;
480
+ }
481
+ }
482
+ return result;
483
+ }
484
+ break;
485
+ case 'function':
486
+ return this.runFn(v => this.object(v, opt), value, opt);
487
+ }
488
+ return this.raiseInvalidValue(value, ['object'], opt);
489
+ }
490
+ string(value, opt) {
491
+ if (this.is.empty(value)) {
492
+ return null;
493
+ }
494
+ switch (typeof value) {
495
+ case 'string':
496
+ return value;
497
+ case 'number':
498
+ const num = this.assertion.realNumber(value, opt);
499
+ return num !== null ? num.toString(10) : null;
500
+ case 'bigint':
501
+ return value.toString();
502
+ case 'boolean':
503
+ return value ? 'true' : 'false';
504
+ case 'object':
505
+ if (Array.isArray(value) && value.length === 1) {
506
+ return this.string(value[0], opt);
507
+ }
508
+ return this.string(value.id, opt);
509
+ case 'function':
510
+ return this.runFn(v => this.string(v, opt), value, opt);
511
+ }
512
+ return this.raiseInvalidValue(value, this._EXPECTED_STRING, opt);
513
+ }
514
+ text(value, opt) {
515
+ if (this.is.empty(value)) {
516
+ return null;
517
+ }
518
+ switch (typeof value) {
519
+ case 'string':
520
+ const str = value.trim();
521
+ return str ? str : null;
522
+ case 'number':
523
+ const num = this.assertion.realNumber(value, opt);
524
+ return num !== null ? num.toString(10) : null;
525
+ case 'bigint':
526
+ return value.toString();
527
+ case 'boolean':
528
+ return value ? 'true' : 'false';
529
+ case 'object':
530
+ if (Array.isArray(value) && value.length === 1) {
531
+ return this.text(value[0], opt);
532
+ }
533
+ return this.text(value.id, opt);
534
+ case 'function':
535
+ return this.runFn(v => this.text(v, opt), value, opt);
536
+ }
537
+ return this.raiseInvalidValue(value, this._EXPECTED_STRING, opt);
538
+ }
539
+ // endregion types
540
+ // region secure
541
+ $init(leyyo) {
542
+ this.is = leyyo.is;
543
+ this.callback = leyyo.callback;
544
+ this.assertion = leyyo.assertion;
545
+ }
546
+ get $back() {
547
+ return this;
548
+ }
549
+ get $secure() {
550
+ return this;
551
+ }
552
+ }
553
+ exports.CommonToImpl = CommonToImpl;
@@ -0,0 +1,50 @@
1
+ import { Dict, KeyValue, OneOrMore, ShiftMain, ShiftSecure } from "../aliases";
2
+ import { Leyyo } from "../leyyo";
3
+ import { AssertionOpt } from "../assertion";
4
+ export interface CommonTo extends ShiftSecure<CommonToSecure> {
5
+ runFn<T = unknown>(fn: Function, value: Function, opt?: TypeOpt): T;
6
+ raiseInvalidValue<T = unknown>(value: unknown, expected: OneOrMore<string>, opt?: TypeOpt, params?: Dict): T;
7
+ any(value: unknown, opt?: TypeOpt): unknown;
8
+ array<T = unknown>(value: unknown, opt?: TypeArrayOpt): Array<T>;
9
+ boolean(value: unknown, opt?: TypeOpt): boolean;
10
+ clazz(value: unknown, opt?: TypeOpt): string;
11
+ date(value: unknown, opt?: TypeOpt): Date;
12
+ enumeration<T extends KeyValue = KeyValue>(value: unknown, opt?: TypeEnumOpt<T>): T;
13
+ float(value: unknown, opt?: TypeOpt): number | null;
14
+ func<T = Function>(value: unknown, opt?: TypeOpt): T | null;
15
+ integer(value: unknown, opt?: TypeOpt): number | null;
16
+ object<T = unknown>(value: unknown, opt?: TypeObjectOpt): Dict<T>;
17
+ dict<T = unknown>(value: unknown, opt?: TypeObjectOpt): Dict<T>;
18
+ string(value: unknown, opt?: TypeOpt): string;
19
+ text(value: unknown, opt?: TypeOpt): string;
20
+ }
21
+ export interface CommonToSecure extends ShiftMain<CommonTo> {
22
+ $init(leyyo: Leyyo): void;
23
+ }
24
+ export interface TypeOpt extends AssertionOpt {
25
+ silent?: true;
26
+ children?: unknown;
27
+ }
28
+ export type TypeFnLambda<T = unknown, O extends TypeOpt = TypeOpt> = (value: unknown, opt?: O) => T;
29
+ export interface TypeChildOpt<T = unknown> extends TypeOpt {
30
+ fn?: TypeFnLambda<T>;
31
+ }
32
+ export interface TypeArrayChildOpt<V extends TypeChildOpt = TypeChildOpt> extends Dict<TypeChildOpt> {
33
+ value?: V;
34
+ }
35
+ export interface TypeArrayOpt<V extends TypeChildOpt = TypeChildOpt> extends TypeOpt {
36
+ children?: TypeArrayChildOpt<V>;
37
+ }
38
+ export interface TypeDictChildOpt<K extends TypeChildOpt = TypeChildOpt, V extends TypeChildOpt = TypeChildOpt> extends Record<string, TypeChildOpt> {
39
+ key?: K;
40
+ value?: V;
41
+ }
42
+ export interface TypeObjectOpt<K extends TypeChildOpt = TypeChildOpt, V extends TypeChildOpt = TypeChildOpt> extends TypeOpt {
43
+ children?: TypeDictChildOpt<K, V>;
44
+ }
45
+ export interface TypeEnumOpt<E extends KeyValue = KeyValue> extends TypeOpt {
46
+ map: EnumerationMap<E>;
47
+ alt?: EnumerationAlt<E>;
48
+ }
49
+ export type EnumerationMap<E extends KeyValue = KeyValue> = Dict<E>;
50
+ export type EnumerationAlt<E extends KeyValue = KeyValue> = Dict<E>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './index-types';
2
+ export * from './common-to-impl';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index-types"), exports);
18
+ __exportStar(require("./common-to-impl"), exports);
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@leyyo/common",
3
+ "version": "1.0.0",
4
+ "description": "Common library",
5
+ "keywords": [
6
+ "common"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/leyyonet/common.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/leyyonet/common.git/issues",
14
+ "email": "mustafayelmer@gmail.com"
15
+ },
16
+ "homepage": "https://github.com/leyyonet/common.git/#readme",
17
+ "author": "Mustafa Yelmer <mustafayelmer@gmail.com>",
18
+ "main": "dist/index.js",
19
+ "scripts": {
20
+ "clear": "rimraf dist",
21
+ "lint": "eslint src/**/*.ts",
22
+ "asset": "node -r ts-node/register commands/assets.ts",
23
+ "build": "npm run clear && tsc && npm run asset",
24
+ "test": "jest --config=jest.json",
25
+ "test:watch": "jest --watch --config=jest.json",
26
+ "test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
27
+ "~publish": "npm run build && npm publish -access=public"
28
+ },
29
+ "files": [
30
+ "dist/*"
31
+ ],
32
+ "license": "ISC",
33
+ "devDependencies": {
34
+ "@babel/preset-typescript": "^7.18.6",
35
+ "@types/jest": "^29.2.5",
36
+ "@types/node": "^22.13.4",
37
+ "@typescript-eslint/eslint-plugin": "^8.24.0",
38
+ "@typescript-eslint/parser": "^8.24.0",
39
+ "eslint": "^8.0.1",
40
+ "eslint-config-prettier": "^10.0.1",
41
+ "eslint-config-standard": "^17.0.0",
42
+ "eslint-plugin-node": "^11.1.0",
43
+ "javascript-obfuscator": "^4.1.1",
44
+ "jest": "^29.3.1",
45
+ "prettier": "^3.5.1",
46
+ "rimraf": "^6.0.1",
47
+ "ts-jest": "^29.0.3",
48
+ "ts-node": "^10.8.1",
49
+ "typescript": "^5.7.3"
50
+ },
51
+ "dependencies": {
52
+ }
53
+ }