typia 6.0.6 → 6.1.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.
package/lib/index.mjs CHANGED
@@ -1,4 +1,752 @@
1
- import RandExp from "randexp";
1
+ function getDefaultExportFromCjs(x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3
+ }
4
+
5
+ var lib$1 = {
6
+ exports: {}
7
+ };
8
+
9
+ var util$1 = {};
10
+
11
+ var types$4 = {
12
+ ROOT: 0,
13
+ GROUP: 1,
14
+ POSITION: 2,
15
+ SET: 3,
16
+ RANGE: 4,
17
+ REPETITION: 5,
18
+ REFERENCE: 6,
19
+ CHAR: 7
20
+ };
21
+
22
+ var sets$1 = {};
23
+
24
+ const types$3 = types$4;
25
+
26
+ const INTS = () => [ {
27
+ type: types$3.RANGE,
28
+ from: 48,
29
+ to: 57
30
+ } ];
31
+
32
+ const WORDS = () => [ {
33
+ type: types$3.CHAR,
34
+ value: 95
35
+ }, {
36
+ type: types$3.RANGE,
37
+ from: 97,
38
+ to: 122
39
+ }, {
40
+ type: types$3.RANGE,
41
+ from: 65,
42
+ to: 90
43
+ } ].concat(INTS());
44
+
45
+ const WHITESPACE = () => [ {
46
+ type: types$3.CHAR,
47
+ value: 9
48
+ }, {
49
+ type: types$3.CHAR,
50
+ value: 10
51
+ }, {
52
+ type: types$3.CHAR,
53
+ value: 11
54
+ }, {
55
+ type: types$3.CHAR,
56
+ value: 12
57
+ }, {
58
+ type: types$3.CHAR,
59
+ value: 13
60
+ }, {
61
+ type: types$3.CHAR,
62
+ value: 32
63
+ }, {
64
+ type: types$3.CHAR,
65
+ value: 160
66
+ }, {
67
+ type: types$3.CHAR,
68
+ value: 5760
69
+ }, {
70
+ type: types$3.RANGE,
71
+ from: 8192,
72
+ to: 8202
73
+ }, {
74
+ type: types$3.CHAR,
75
+ value: 8232
76
+ }, {
77
+ type: types$3.CHAR,
78
+ value: 8233
79
+ }, {
80
+ type: types$3.CHAR,
81
+ value: 8239
82
+ }, {
83
+ type: types$3.CHAR,
84
+ value: 8287
85
+ }, {
86
+ type: types$3.CHAR,
87
+ value: 12288
88
+ }, {
89
+ type: types$3.CHAR,
90
+ value: 65279
91
+ } ];
92
+
93
+ const NOTANYCHAR = () => [ {
94
+ type: types$3.CHAR,
95
+ value: 10
96
+ }, {
97
+ type: types$3.CHAR,
98
+ value: 13
99
+ }, {
100
+ type: types$3.CHAR,
101
+ value: 8232
102
+ }, {
103
+ type: types$3.CHAR,
104
+ value: 8233
105
+ } ];
106
+
107
+ sets$1.words = () => ({
108
+ type: types$3.SET,
109
+ set: WORDS(),
110
+ not: false
111
+ });
112
+
113
+ sets$1.notWords = () => ({
114
+ type: types$3.SET,
115
+ set: WORDS(),
116
+ not: true
117
+ });
118
+
119
+ sets$1.ints = () => ({
120
+ type: types$3.SET,
121
+ set: INTS(),
122
+ not: false
123
+ });
124
+
125
+ sets$1.notInts = () => ({
126
+ type: types$3.SET,
127
+ set: INTS(),
128
+ not: true
129
+ });
130
+
131
+ sets$1.whitespace = () => ({
132
+ type: types$3.SET,
133
+ set: WHITESPACE(),
134
+ not: false
135
+ });
136
+
137
+ sets$1.notWhitespace = () => ({
138
+ type: types$3.SET,
139
+ set: WHITESPACE(),
140
+ not: true
141
+ });
142
+
143
+ sets$1.anyChar = () => ({
144
+ type: types$3.SET,
145
+ set: NOTANYCHAR(),
146
+ not: true
147
+ });
148
+
149
+ (function(exports) {
150
+ const types = types$4;
151
+ const sets = sets$1;
152
+ const CTRL = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?";
153
+ const SLSH = {
154
+ 0: 0,
155
+ t: 9,
156
+ n: 10,
157
+ v: 11,
158
+ f: 12,
159
+ r: 13
160
+ };
161
+ exports.strToChars = function(str) {
162
+ var chars_regex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
163
+ str = str.replace(chars_regex, (function(s, b, lbs, a16, b16, c8, dctrl, eslsh) {
164
+ if (lbs) {
165
+ return s;
166
+ }
167
+ var code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : c8 ? parseInt(c8, 8) : dctrl ? CTRL.indexOf(dctrl) : SLSH[eslsh];
168
+ var c = String.fromCharCode(code);
169
+ if (/[[\]{}^$.|?*+()]/.test(c)) {
170
+ c = "\\" + c;
171
+ }
172
+ return c;
173
+ }));
174
+ return str;
175
+ };
176
+ exports.tokenizeClass = (str, regexpStr) => {
177
+ var tokens = [];
178
+ var regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g;
179
+ var rs, c;
180
+ while ((rs = regexp.exec(str)) != null) {
181
+ if (rs[1]) {
182
+ tokens.push(sets.words());
183
+ } else if (rs[2]) {
184
+ tokens.push(sets.ints());
185
+ } else if (rs[3]) {
186
+ tokens.push(sets.whitespace());
187
+ } else if (rs[4]) {
188
+ tokens.push(sets.notWords());
189
+ } else if (rs[5]) {
190
+ tokens.push(sets.notInts());
191
+ } else if (rs[6]) {
192
+ tokens.push(sets.notWhitespace());
193
+ } else if (rs[7]) {
194
+ tokens.push({
195
+ type: types.RANGE,
196
+ from: (rs[8] || rs[9]).charCodeAt(0),
197
+ to: rs[10].charCodeAt(0)
198
+ });
199
+ } else if (c = rs[12]) {
200
+ tokens.push({
201
+ type: types.CHAR,
202
+ value: c.charCodeAt(0)
203
+ });
204
+ } else {
205
+ return [ tokens, regexp.lastIndex ];
206
+ }
207
+ }
208
+ exports.error(regexpStr, "Unterminated character class");
209
+ };
210
+ exports.error = (regexp, msg) => {
211
+ throw new SyntaxError("Invalid regular expression: /" + regexp + "/: " + msg);
212
+ };
213
+ })(util$1);
214
+
215
+ var positions$1 = {};
216
+
217
+ const types$2 = types$4;
218
+
219
+ positions$1.wordBoundary = () => ({
220
+ type: types$2.POSITION,
221
+ value: "b"
222
+ });
223
+
224
+ positions$1.nonWordBoundary = () => ({
225
+ type: types$2.POSITION,
226
+ value: "B"
227
+ });
228
+
229
+ positions$1.begin = () => ({
230
+ type: types$2.POSITION,
231
+ value: "^"
232
+ });
233
+
234
+ positions$1.end = () => ({
235
+ type: types$2.POSITION,
236
+ value: "$"
237
+ });
238
+
239
+ const util = util$1;
240
+
241
+ const types$1 = types$4;
242
+
243
+ const sets = sets$1;
244
+
245
+ const positions = positions$1;
246
+
247
+ lib$1.exports = regexpStr => {
248
+ var i = 0, l, c, start = {
249
+ type: types$1.ROOT,
250
+ stack: []
251
+ }, lastGroup = start, last = start.stack, groupStack = [];
252
+ var repeatErr = i => {
253
+ util.error(regexpStr, `Nothing to repeat at column ${i - 1}`);
254
+ };
255
+ var str = util.strToChars(regexpStr);
256
+ l = str.length;
257
+ while (i < l) {
258
+ c = str[i++];
259
+ switch (c) {
260
+ case "\\":
261
+ c = str[i++];
262
+ switch (c) {
263
+ case "b":
264
+ last.push(positions.wordBoundary());
265
+ break;
266
+
267
+ case "B":
268
+ last.push(positions.nonWordBoundary());
269
+ break;
270
+
271
+ case "w":
272
+ last.push(sets.words());
273
+ break;
274
+
275
+ case "W":
276
+ last.push(sets.notWords());
277
+ break;
278
+
279
+ case "d":
280
+ last.push(sets.ints());
281
+ break;
282
+
283
+ case "D":
284
+ last.push(sets.notInts());
285
+ break;
286
+
287
+ case "s":
288
+ last.push(sets.whitespace());
289
+ break;
290
+
291
+ case "S":
292
+ last.push(sets.notWhitespace());
293
+ break;
294
+
295
+ default:
296
+ if (/\d/.test(c)) {
297
+ last.push({
298
+ type: types$1.REFERENCE,
299
+ value: parseInt(c, 10)
300
+ });
301
+ } else {
302
+ last.push({
303
+ type: types$1.CHAR,
304
+ value: c.charCodeAt(0)
305
+ });
306
+ }
307
+ }
308
+ break;
309
+
310
+ case "^":
311
+ last.push(positions.begin());
312
+ break;
313
+
314
+ case "$":
315
+ last.push(positions.end());
316
+ break;
317
+
318
+ case "[":
319
+ var not;
320
+ if (str[i] === "^") {
321
+ not = true;
322
+ i++;
323
+ } else {
324
+ not = false;
325
+ }
326
+ var classTokens = util.tokenizeClass(str.slice(i), regexpStr);
327
+ i += classTokens[1];
328
+ last.push({
329
+ type: types$1.SET,
330
+ set: classTokens[0],
331
+ not
332
+ });
333
+ break;
334
+
335
+ case ".":
336
+ last.push(sets.anyChar());
337
+ break;
338
+
339
+ case "(":
340
+ var group = {
341
+ type: types$1.GROUP,
342
+ stack: [],
343
+ remember: true
344
+ };
345
+ c = str[i];
346
+ if (c === "?") {
347
+ c = str[i + 1];
348
+ i += 2;
349
+ if (c === "=") {
350
+ group.followedBy = true;
351
+ } else if (c === "!") {
352
+ group.notFollowedBy = true;
353
+ } else if (c !== ":") {
354
+ util.error(regexpStr, `Invalid group, character '${c}'` + ` after '?' at column ${i - 1}`);
355
+ }
356
+ group.remember = false;
357
+ }
358
+ last.push(group);
359
+ groupStack.push(lastGroup);
360
+ lastGroup = group;
361
+ last = group.stack;
362
+ break;
363
+
364
+ case ")":
365
+ if (groupStack.length === 0) {
366
+ util.error(regexpStr, `Unmatched ) at column ${i - 1}`);
367
+ }
368
+ lastGroup = groupStack.pop();
369
+ last = lastGroup.options ? lastGroup.options[lastGroup.options.length - 1] : lastGroup.stack;
370
+ break;
371
+
372
+ case "|":
373
+ if (!lastGroup.options) {
374
+ lastGroup.options = [ lastGroup.stack ];
375
+ delete lastGroup.stack;
376
+ }
377
+ var stack = [];
378
+ lastGroup.options.push(stack);
379
+ last = stack;
380
+ break;
381
+
382
+ case "{":
383
+ var rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max;
384
+ if (rs !== null) {
385
+ if (last.length === 0) {
386
+ repeatErr(i);
387
+ }
388
+ min = parseInt(rs[1], 10);
389
+ max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min;
390
+ i += rs[0].length;
391
+ last.push({
392
+ type: types$1.REPETITION,
393
+ min,
394
+ max,
395
+ value: last.pop()
396
+ });
397
+ } else {
398
+ last.push({
399
+ type: types$1.CHAR,
400
+ value: 123
401
+ });
402
+ }
403
+ break;
404
+
405
+ case "?":
406
+ if (last.length === 0) {
407
+ repeatErr(i);
408
+ }
409
+ last.push({
410
+ type: types$1.REPETITION,
411
+ min: 0,
412
+ max: 1,
413
+ value: last.pop()
414
+ });
415
+ break;
416
+
417
+ case "+":
418
+ if (last.length === 0) {
419
+ repeatErr(i);
420
+ }
421
+ last.push({
422
+ type: types$1.REPETITION,
423
+ min: 1,
424
+ max: Infinity,
425
+ value: last.pop()
426
+ });
427
+ break;
428
+
429
+ case "*":
430
+ if (last.length === 0) {
431
+ repeatErr(i);
432
+ }
433
+ last.push({
434
+ type: types$1.REPETITION,
435
+ min: 0,
436
+ max: Infinity,
437
+ value: last.pop()
438
+ });
439
+ break;
440
+
441
+ default:
442
+ last.push({
443
+ type: types$1.CHAR,
444
+ value: c.charCodeAt(0)
445
+ });
446
+ }
447
+ }
448
+ if (groupStack.length !== 0) {
449
+ util.error(regexpStr, "Unterminated group");
450
+ }
451
+ return start;
452
+ };
453
+
454
+ lib$1.exports.types = types$1;
455
+
456
+ var libExports = lib$1.exports;
457
+
458
+ class SubRange {
459
+ constructor(low, high) {
460
+ this.low = low;
461
+ this.high = high;
462
+ this.length = 1 + high - low;
463
+ }
464
+ overlaps(range) {
465
+ return !(this.high < range.low || this.low > range.high);
466
+ }
467
+ touches(range) {
468
+ return !(this.high + 1 < range.low || this.low - 1 > range.high);
469
+ }
470
+ add(range) {
471
+ return new SubRange(Math.min(this.low, range.low), Math.max(this.high, range.high));
472
+ }
473
+ subtract(range) {
474
+ if (range.low <= this.low && range.high >= this.high) {
475
+ return [];
476
+ } else if (range.low > this.low && range.high < this.high) {
477
+ return [ new SubRange(this.low, range.low - 1), new SubRange(range.high + 1, this.high) ];
478
+ } else if (range.low <= this.low) {
479
+ return [ new SubRange(range.high + 1, this.high) ];
480
+ } else {
481
+ return [ new SubRange(this.low, range.low - 1) ];
482
+ }
483
+ }
484
+ toString() {
485
+ return this.low == this.high ? this.low.toString() : this.low + "-" + this.high;
486
+ }
487
+ }
488
+
489
+ let DRange$1 = class DRange {
490
+ constructor(a, b) {
491
+ this.ranges = [];
492
+ this.length = 0;
493
+ if (a != null) this.add(a, b);
494
+ }
495
+ _update_length() {
496
+ this.length = this.ranges.reduce(((previous, range) => previous + range.length), 0);
497
+ }
498
+ add(a, b) {
499
+ var _add = subrange => {
500
+ var i = 0;
501
+ while (i < this.ranges.length && !subrange.touches(this.ranges[i])) {
502
+ i++;
503
+ }
504
+ var newRanges = this.ranges.slice(0, i);
505
+ while (i < this.ranges.length && subrange.touches(this.ranges[i])) {
506
+ subrange = subrange.add(this.ranges[i]);
507
+ i++;
508
+ }
509
+ newRanges.push(subrange);
510
+ this.ranges = newRanges.concat(this.ranges.slice(i));
511
+ this._update_length();
512
+ };
513
+ if (a instanceof DRange) {
514
+ a.ranges.forEach(_add);
515
+ } else {
516
+ if (b == null) b = a;
517
+ _add(new SubRange(a, b));
518
+ }
519
+ return this;
520
+ }
521
+ subtract(a, b) {
522
+ var _subtract = subrange => {
523
+ var i = 0;
524
+ while (i < this.ranges.length && !subrange.overlaps(this.ranges[i])) {
525
+ i++;
526
+ }
527
+ var newRanges = this.ranges.slice(0, i);
528
+ while (i < this.ranges.length && subrange.overlaps(this.ranges[i])) {
529
+ newRanges = newRanges.concat(this.ranges[i].subtract(subrange));
530
+ i++;
531
+ }
532
+ this.ranges = newRanges.concat(this.ranges.slice(i));
533
+ this._update_length();
534
+ };
535
+ if (a instanceof DRange) {
536
+ a.ranges.forEach(_subtract);
537
+ } else {
538
+ if (b == null) b = a;
539
+ _subtract(new SubRange(a, b));
540
+ }
541
+ return this;
542
+ }
543
+ intersect(a, b) {
544
+ var newRanges = [];
545
+ var _intersect = subrange => {
546
+ var i = 0;
547
+ while (i < this.ranges.length && !subrange.overlaps(this.ranges[i])) {
548
+ i++;
549
+ }
550
+ while (i < this.ranges.length && subrange.overlaps(this.ranges[i])) {
551
+ var low = Math.max(this.ranges[i].low, subrange.low);
552
+ var high = Math.min(this.ranges[i].high, subrange.high);
553
+ newRanges.push(new SubRange(low, high));
554
+ i++;
555
+ }
556
+ };
557
+ if (a instanceof DRange) {
558
+ a.ranges.forEach(_intersect);
559
+ } else {
560
+ if (b == null) b = a;
561
+ _intersect(new SubRange(a, b));
562
+ }
563
+ this.ranges = newRanges;
564
+ this._update_length();
565
+ return this;
566
+ }
567
+ index(index) {
568
+ var i = 0;
569
+ while (i < this.ranges.length && this.ranges[i].length <= index) {
570
+ index -= this.ranges[i].length;
571
+ i++;
572
+ }
573
+ return this.ranges[i].low + index;
574
+ }
575
+ toString() {
576
+ return "[ " + this.ranges.join(", ") + " ]";
577
+ }
578
+ clone() {
579
+ return new DRange(this);
580
+ }
581
+ numbers() {
582
+ return this.ranges.reduce(((result, subrange) => {
583
+ var i = subrange.low;
584
+ while (i <= subrange.high) {
585
+ result.push(i);
586
+ i++;
587
+ }
588
+ return result;
589
+ }), []);
590
+ }
591
+ subranges() {
592
+ return this.ranges.map((subrange => ({
593
+ low: subrange.low,
594
+ high: subrange.high,
595
+ length: 1 + subrange.high - subrange.low
596
+ })));
597
+ }
598
+ };
599
+
600
+ var lib = DRange$1;
601
+
602
+ const ret = libExports;
603
+
604
+ const DRange = lib;
605
+
606
+ const types = ret.types;
607
+
608
+ var randexp = class RandExp {
609
+ constructor(regexp, m) {
610
+ this._setDefaults(regexp);
611
+ if (regexp instanceof RegExp) {
612
+ this.ignoreCase = regexp.ignoreCase;
613
+ this.multiline = regexp.multiline;
614
+ regexp = regexp.source;
615
+ } else if (typeof regexp === "string") {
616
+ this.ignoreCase = m && m.indexOf("i") !== -1;
617
+ this.multiline = m && m.indexOf("m") !== -1;
618
+ } else {
619
+ throw new Error("Expected a regexp or string");
620
+ }
621
+ this.tokens = ret(regexp);
622
+ }
623
+ _setDefaults(regexp) {
624
+ this.max = regexp.max != null ? regexp.max : RandExp.prototype.max != null ? RandExp.prototype.max : 100;
625
+ this.defaultRange = regexp.defaultRange ? regexp.defaultRange : this.defaultRange.clone();
626
+ if (regexp.randInt) {
627
+ this.randInt = regexp.randInt;
628
+ }
629
+ }
630
+ gen() {
631
+ return this._gen(this.tokens, []);
632
+ }
633
+ _gen(token, groups) {
634
+ var stack, str, n, i, l;
635
+ switch (token.type) {
636
+ case types.ROOT:
637
+ case types.GROUP:
638
+ if (token.followedBy || token.notFollowedBy) {
639
+ return "";
640
+ }
641
+ if (token.remember && token.groupNumber === undefined) {
642
+ token.groupNumber = groups.push(null) - 1;
643
+ }
644
+ stack = token.options ? this._randSelect(token.options) : token.stack;
645
+ str = "";
646
+ for (i = 0, l = stack.length; i < l; i++) {
647
+ str += this._gen(stack[i], groups);
648
+ }
649
+ if (token.remember) {
650
+ groups[token.groupNumber] = str;
651
+ }
652
+ return str;
653
+
654
+ case types.POSITION:
655
+ return "";
656
+
657
+ case types.SET:
658
+ var expandedSet = this._expand(token);
659
+ if (!expandedSet.length) {
660
+ return "";
661
+ }
662
+ return String.fromCharCode(this._randSelect(expandedSet));
663
+
664
+ case types.REPETITION:
665
+ n = this.randInt(token.min, token.max === Infinity ? token.min + this.max : token.max);
666
+ str = "";
667
+ for (i = 0; i < n; i++) {
668
+ str += this._gen(token.value, groups);
669
+ }
670
+ return str;
671
+
672
+ case types.REFERENCE:
673
+ return groups[token.value - 1] || "";
674
+
675
+ case types.CHAR:
676
+ var code = this.ignoreCase && this._randBool() ? this._toOtherCase(token.value) : token.value;
677
+ return String.fromCharCode(code);
678
+ }
679
+ }
680
+ _toOtherCase(code) {
681
+ return code + (97 <= code && code <= 122 ? -32 : 65 <= code && code <= 90 ? 32 : 0);
682
+ }
683
+ _randBool() {
684
+ return !this.randInt(0, 1);
685
+ }
686
+ _randSelect(arr) {
687
+ if (arr instanceof DRange) {
688
+ return arr.index(this.randInt(0, arr.length - 1));
689
+ }
690
+ return arr[this.randInt(0, arr.length - 1)];
691
+ }
692
+ _expand(token) {
693
+ if (token.type === ret.types.CHAR) {
694
+ return new DRange(token.value);
695
+ } else if (token.type === ret.types.RANGE) {
696
+ return new DRange(token.from, token.to);
697
+ } else {
698
+ let drange = new DRange;
699
+ for (let i = 0; i < token.set.length; i++) {
700
+ let subrange = this._expand(token.set[i]);
701
+ drange.add(subrange);
702
+ if (this.ignoreCase) {
703
+ for (let j = 0; j < subrange.length; j++) {
704
+ let code = subrange.index(j);
705
+ let otherCaseCode = this._toOtherCase(code);
706
+ if (code !== otherCaseCode) {
707
+ drange.add(otherCaseCode);
708
+ }
709
+ }
710
+ }
711
+ }
712
+ if (token.not) {
713
+ return this.defaultRange.clone().subtract(drange);
714
+ } else {
715
+ return this.defaultRange.clone().intersect(drange);
716
+ }
717
+ }
718
+ }
719
+ randInt(a, b) {
720
+ return a + Math.floor(Math.random() * (1 + b - a));
721
+ }
722
+ get defaultRange() {
723
+ return this._range = this._range || new DRange(32, 126);
724
+ }
725
+ set defaultRange(range) {
726
+ this._range = range;
727
+ }
728
+ static randexp(regexp, m) {
729
+ var randexp;
730
+ if (typeof regexp === "string") {
731
+ regexp = new RegExp(regexp, m);
732
+ }
733
+ if (regexp._randexp === undefined) {
734
+ randexp = new RandExp(regexp, m);
735
+ regexp._randexp = randexp;
736
+ } else {
737
+ randexp = regexp._randexp;
738
+ randexp._setDefaults(regexp);
739
+ }
740
+ return randexp.gen();
741
+ }
742
+ static sugar() {
743
+ RegExp.prototype.gen = function() {
744
+ return RandExp.randexp(this);
745
+ };
746
+ }
747
+ };
748
+
749
+ var RandExp = getDefaultExportFromCjs(randexp);
2
750
 
3
751
  const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
4
752