pythonlib 0.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.
Files changed (66) hide show
  1. package/README.md +183 -0
  2. package/dist/chunk-3CSEXTA7.js +376 -0
  3. package/dist/chunk-3CSEXTA7.js.map +1 -0
  4. package/dist/chunk-HA5Y7PKO.js +680 -0
  5. package/dist/chunk-HA5Y7PKO.js.map +1 -0
  6. package/dist/chunk-IVYYI2VR.js +261 -0
  7. package/dist/chunk-IVYYI2VR.js.map +1 -0
  8. package/dist/chunk-OMQNGE6T.js +245 -0
  9. package/dist/chunk-OMQNGE6T.js.map +1 -0
  10. package/dist/chunk-P3SGIF72.js +107 -0
  11. package/dist/chunk-P3SGIF72.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-TJFGYXBJ.js +310 -0
  15. package/dist/chunk-TJFGYXBJ.js.map +1 -0
  16. package/dist/chunk-TOI6IG3T.js +337 -0
  17. package/dist/chunk-TOI6IG3T.js.map +1 -0
  18. package/dist/chunk-UFMTN4T4.js +215 -0
  19. package/dist/chunk-UFMTN4T4.js.map +1 -0
  20. package/dist/chunk-V63LKSA3.js +423 -0
  21. package/dist/chunk-V63LKSA3.js.map +1 -0
  22. package/dist/chunk-WAONBJE5.js +236 -0
  23. package/dist/chunk-WAONBJE5.js.map +1 -0
  24. package/dist/collections-xN9Gi0TA.d.ts +113 -0
  25. package/dist/collections.d.ts +1 -0
  26. package/dist/collections.js +12 -0
  27. package/dist/collections.js.map +1 -0
  28. package/dist/datetime-DRwFAiGV.d.ts +139 -0
  29. package/dist/datetime.d.ts +1 -0
  30. package/dist/datetime.js +22 -0
  31. package/dist/datetime.js.map +1 -0
  32. package/dist/functools-St5GqpKG.d.ts +125 -0
  33. package/dist/functools.d.ts +1 -0
  34. package/dist/functools.js +32 -0
  35. package/dist/functools.js.map +1 -0
  36. package/dist/index.d.ts +624 -0
  37. package/dist/index.js +1332 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/itertools-Bj8XivI6.d.ts +138 -0
  40. package/dist/itertools.d.ts +1 -0
  41. package/dist/itertools.js +44 -0
  42. package/dist/itertools.js.map +1 -0
  43. package/dist/json-Xpk0kwSd.d.ts +77 -0
  44. package/dist/json.d.ts +1 -0
  45. package/dist/json.js +14 -0
  46. package/dist/json.js.map +1 -0
  47. package/dist/math-BrT4Aw3E.d.ts +147 -0
  48. package/dist/math.d.ts +1 -0
  49. package/dist/math.js +96 -0
  50. package/dist/math.js.map +1 -0
  51. package/dist/os-FRSJbEUH.d.ts +143 -0
  52. package/dist/os.d.ts +1 -0
  53. package/dist/os.js +58 -0
  54. package/dist/os.js.map +1 -0
  55. package/dist/random-D5S5iSV3.d.ts +72 -0
  56. package/dist/random.d.ts +1 -0
  57. package/dist/random.js +42 -0
  58. package/dist/random.js.map +1 -0
  59. package/dist/re-DSxiURqN.d.ts +148 -0
  60. package/dist/re.d.ts +1 -0
  61. package/dist/re.js +52 -0
  62. package/dist/re.js.map +1 -0
  63. package/dist/string.d.ts +166 -0
  64. package/dist/string.js +30 -0
  65. package/dist/string.js.map +1 -0
  66. package/package.json +85 -0
package/dist/index.js ADDED
@@ -0,0 +1,1332 @@
1
+ import {
2
+ random_exports
3
+ } from "./chunk-WAONBJE5.js";
4
+ import {
5
+ re_exports
6
+ } from "./chunk-V63LKSA3.js";
7
+ import {
8
+ Template,
9
+ ascii_letters,
10
+ ascii_lowercase,
11
+ ascii_uppercase,
12
+ capwords,
13
+ digits,
14
+ hexdigits,
15
+ octdigits,
16
+ printable,
17
+ punctuation,
18
+ string,
19
+ whitespace
20
+ } from "./chunk-3CSEXTA7.js";
21
+ import {
22
+ Counter,
23
+ collections_exports,
24
+ defaultdict,
25
+ deque
26
+ } from "./chunk-UFMTN4T4.js";
27
+ import {
28
+ datetime_exports
29
+ } from "./chunk-HA5Y7PKO.js";
30
+ import {
31
+ functools_exports
32
+ } from "./chunk-OMQNGE6T.js";
33
+ import {
34
+ itertools_exports
35
+ } from "./chunk-TOI6IG3T.js";
36
+ import {
37
+ json_exports
38
+ } from "./chunk-P3SGIF72.js";
39
+ import {
40
+ math_exports
41
+ } from "./chunk-IVYYI2VR.js";
42
+ import {
43
+ os_exports
44
+ } from "./chunk-TJFGYXBJ.js";
45
+ import "./chunk-PZ5AY32C.js";
46
+
47
+ // src/core.ts
48
+ function floordiv(a, b) {
49
+ return Math.floor(a / b);
50
+ }
51
+ function pow(base, exp) {
52
+ return Math.pow(base, exp);
53
+ }
54
+ function mod(a, b) {
55
+ return (a % b + b) % b;
56
+ }
57
+ function divmod(a, b) {
58
+ return [floordiv(a, b), mod(a, b)];
59
+ }
60
+ function sprintf(template, args) {
61
+ const values = Array.isArray(args) ? args : [args];
62
+ let index = 0;
63
+ return template.replace(
64
+ /%([+-]?\d*\.?\d*)([sdifxXorec%])/g,
65
+ (match, flags, type3) => {
66
+ if (type3 === "%") return "%";
67
+ if (index >= values.length) return match;
68
+ const value = values[index++];
69
+ switch (type3) {
70
+ case "s":
71
+ return String(value);
72
+ case "d":
73
+ case "i":
74
+ return String(Math.floor(Number(value)));
75
+ case "f":
76
+ if (flags && flags.includes(".")) {
77
+ const precision = parseInt(flags.split(".")[1] ?? "6", 10);
78
+ return Number(value).toFixed(precision);
79
+ }
80
+ return String(Number(value));
81
+ case "x":
82
+ return Math.floor(Number(value)).toString(16);
83
+ case "X":
84
+ return Math.floor(Number(value)).toString(16).toUpperCase();
85
+ case "o":
86
+ return Math.floor(Number(value)).toString(8);
87
+ case "r":
88
+ return JSON.stringify(value);
89
+ case "e":
90
+ return Number(value).toExponential();
91
+ case "c":
92
+ return String.fromCharCode(Number(value));
93
+ default:
94
+ return String(value);
95
+ }
96
+ }
97
+ );
98
+ }
99
+ function strFormat(template, ...args) {
100
+ let positionalIndex = 0;
101
+ const lastArg = args[args.length - 1];
102
+ const namedParams = lastArg && typeof lastArg === "object" && !Array.isArray(lastArg) ? lastArg : {};
103
+ return template.replace(/\{([^}]*)\}/g, (match, key) => {
104
+ if (key === "") {
105
+ if (positionalIndex < args.length) {
106
+ return String(args[positionalIndex++]);
107
+ }
108
+ return match;
109
+ }
110
+ const numIndex = parseInt(key, 10);
111
+ if (!isNaN(numIndex) && numIndex < args.length) {
112
+ return String(args[numIndex]);
113
+ }
114
+ if (key in namedParams) {
115
+ return String(namedParams[key]);
116
+ }
117
+ return match;
118
+ });
119
+ }
120
+ function normalizeIndex(index, length, forNegativeStep = false) {
121
+ if (index < 0) {
122
+ index = length + index;
123
+ }
124
+ if (forNegativeStep) {
125
+ return Math.max(-1, Math.min(length - 1, index));
126
+ }
127
+ return Math.max(0, Math.min(length, index));
128
+ }
129
+ function slice(obj, start, stop, step) {
130
+ const len3 = obj.length;
131
+ const actualStep = step ?? 1;
132
+ if (actualStep === 0) {
133
+ throw new Error("slice step cannot be zero");
134
+ }
135
+ let actualStart;
136
+ let actualStop;
137
+ if (actualStep > 0) {
138
+ actualStart = start === void 0 ? 0 : normalizeIndex(start, len3);
139
+ actualStop = stop === void 0 ? len3 : normalizeIndex(stop, len3);
140
+ } else {
141
+ actualStart = start === void 0 ? len3 - 1 : normalizeIndex(start, len3, true);
142
+ actualStop = stop === void 0 ? -1 : normalizeIndex(stop, len3, true);
143
+ }
144
+ const result = [];
145
+ if (actualStep > 0) {
146
+ for (let i = actualStart; i < actualStop; i += actualStep) {
147
+ if (i >= 0 && i < len3) {
148
+ result.push(obj[i]);
149
+ }
150
+ }
151
+ } else {
152
+ for (let i = actualStart; i > actualStop; i += actualStep) {
153
+ if (i >= 0 && i < len3) {
154
+ result.push(obj[i]);
155
+ }
156
+ }
157
+ }
158
+ if (typeof obj === "string") {
159
+ return result.join("");
160
+ }
161
+ return result;
162
+ }
163
+ function at(obj, index) {
164
+ const len3 = obj.length;
165
+ const normalizedIndex = index < 0 ? len3 + index : index;
166
+ if (normalizedIndex < 0 || normalizedIndex >= len3) {
167
+ throw new Error("IndexError: list index out of range");
168
+ }
169
+ return obj[normalizedIndex];
170
+ }
171
+ function repeat(obj, count) {
172
+ if (count <= 0) {
173
+ return typeof obj === "string" ? "" : [];
174
+ }
175
+ if (typeof obj === "string") {
176
+ return obj.repeat(count);
177
+ }
178
+ const result = [];
179
+ for (let i = 0; i < count; i++) {
180
+ result.push(...obj);
181
+ }
182
+ return result;
183
+ }
184
+ function contains(item, container) {
185
+ if (typeof container === "string") {
186
+ return container.includes(item);
187
+ }
188
+ if (container instanceof Map) {
189
+ return container.has(item);
190
+ }
191
+ if (container instanceof Set) {
192
+ return container.has(item);
193
+ }
194
+ if (Array.isArray(container)) {
195
+ return container.includes(item);
196
+ }
197
+ for (const element of container) {
198
+ if (element === item) {
199
+ return true;
200
+ }
201
+ }
202
+ return false;
203
+ }
204
+ function is(a, b) {
205
+ return a === b;
206
+ }
207
+
208
+ // src/builtins.ts
209
+ var py;
210
+ function _setPyRef(pyRef) {
211
+ py = pyRef;
212
+ }
213
+ function range(startOrStop, stop, step) {
214
+ let start;
215
+ let end;
216
+ let stepVal;
217
+ if (stop === void 0) {
218
+ start = 0;
219
+ end = startOrStop;
220
+ stepVal = 1;
221
+ } else {
222
+ start = startOrStop;
223
+ end = stop;
224
+ stepVal = step ?? 1;
225
+ }
226
+ if (stepVal === 0) {
227
+ throw new Error("range() arg 3 must not be zero");
228
+ }
229
+ return {
230
+ *[Symbol.iterator]() {
231
+ if (stepVal > 0) {
232
+ for (let i = start; i < end; i += stepVal) {
233
+ yield i;
234
+ }
235
+ } else {
236
+ for (let i = start; i > end; i += stepVal) {
237
+ yield i;
238
+ }
239
+ }
240
+ }
241
+ };
242
+ }
243
+ function enumerate(iterable, start = 0) {
244
+ return {
245
+ *[Symbol.iterator]() {
246
+ let index = start;
247
+ for (const item of iterable) {
248
+ yield [index++, item];
249
+ }
250
+ }
251
+ };
252
+ }
253
+ function zip(...iterables) {
254
+ return {
255
+ *[Symbol.iterator]() {
256
+ const iterators = iterables.map((it) => it[Symbol.iterator]());
257
+ for (; ; ) {
258
+ const results = iterators.map((it) => it.next());
259
+ if (results.some((r) => r.done)) {
260
+ break;
261
+ }
262
+ yield results.map((r) => r.value);
263
+ }
264
+ }
265
+ };
266
+ }
267
+ function iter(obj) {
268
+ if (obj === null || obj === void 0) {
269
+ return [];
270
+ }
271
+ if (typeof obj[Symbol.iterator] === "function") {
272
+ return obj;
273
+ }
274
+ if (typeof obj === "object") {
275
+ return Object.keys(obj);
276
+ }
277
+ return [];
278
+ }
279
+ function reversed(iterable) {
280
+ const arr = Array.from(iterable);
281
+ return {
282
+ *[Symbol.iterator]() {
283
+ for (let i = arr.length - 1; i >= 0; i--) {
284
+ yield arr[i];
285
+ }
286
+ }
287
+ };
288
+ }
289
+ function sorted(iterable, options) {
290
+ const arr = Array.from(iterable);
291
+ const key = options?.key ?? ((x) => x);
292
+ const reverse = options?.reverse ?? false;
293
+ arr.sort((a, b) => {
294
+ const aKey = key(a);
295
+ const bKey = key(b);
296
+ let cmp;
297
+ if (typeof aKey === "string" && typeof bKey === "string") {
298
+ cmp = aKey.localeCompare(bKey);
299
+ } else {
300
+ cmp = aKey - bKey;
301
+ }
302
+ return reverse ? -cmp : cmp;
303
+ });
304
+ return arr;
305
+ }
306
+ function map(fn, iterable) {
307
+ return {
308
+ *[Symbol.iterator]() {
309
+ for (const item of iterable) {
310
+ yield fn(item);
311
+ }
312
+ }
313
+ };
314
+ }
315
+ function filter(fn, iterable) {
316
+ return {
317
+ *[Symbol.iterator]() {
318
+ for (const item of iterable) {
319
+ if (fn === null ? bool(item) : fn(item)) {
320
+ yield item;
321
+ }
322
+ }
323
+ }
324
+ };
325
+ }
326
+ function list(iterable) {
327
+ if (iterable === void 0) {
328
+ return [];
329
+ }
330
+ return Array.from(iterable);
331
+ }
332
+ function dict(entries) {
333
+ return new Map(entries);
334
+ }
335
+ function set(iterable) {
336
+ return new Set(iterable);
337
+ }
338
+ function tuple(...items) {
339
+ return Object.freeze([...items]);
340
+ }
341
+ function len(obj) {
342
+ if (typeof obj === "string" || Array.isArray(obj)) {
343
+ return obj.length;
344
+ }
345
+ if (obj instanceof Map || obj instanceof Set) {
346
+ return obj.size;
347
+ }
348
+ if (typeof obj === "object" && obj !== null && "length" in obj) {
349
+ return obj.length;
350
+ }
351
+ throw new TypeError("object has no len()");
352
+ }
353
+ function abs(x) {
354
+ return Math.abs(x);
355
+ }
356
+ function min(...args) {
357
+ const first = args[0];
358
+ if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
359
+ const arr = [...first];
360
+ if (arr.length === 0) {
361
+ throw new Error("min() arg is an empty sequence");
362
+ }
363
+ return arr.reduce((a, b) => a < b ? a : b);
364
+ }
365
+ if (args.length === 0) {
366
+ throw new Error("min expected at least 1 argument, got 0");
367
+ }
368
+ return args.reduce((a, b) => a < b ? a : b);
369
+ }
370
+ function max(...args) {
371
+ const first = args[0];
372
+ if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
373
+ const arr = [...first];
374
+ if (arr.length === 0) {
375
+ throw new Error("max() arg is an empty sequence");
376
+ }
377
+ return arr.reduce((a, b) => a > b ? a : b);
378
+ }
379
+ if (args.length === 0) {
380
+ throw new Error("max expected at least 1 argument, got 0");
381
+ }
382
+ return args.reduce((a, b) => a > b ? a : b);
383
+ }
384
+ function sum(iterable, start = 0) {
385
+ let total = start;
386
+ for (const item of iterable) {
387
+ total += item;
388
+ }
389
+ return total;
390
+ }
391
+ function all(iterable) {
392
+ for (const item of iterable) {
393
+ if (!bool(item)) return false;
394
+ }
395
+ return true;
396
+ }
397
+ function any(iterable) {
398
+ for (const item of iterable) {
399
+ if (bool(item)) return true;
400
+ }
401
+ return false;
402
+ }
403
+ function round(number, ndigits) {
404
+ if (ndigits === void 0 || ndigits === 0) {
405
+ const rounded = Math.round(number);
406
+ if (Math.abs(number % 1) === 0.5) {
407
+ return rounded % 2 === 0 ? rounded : rounded - Math.sign(number);
408
+ }
409
+ return rounded;
410
+ }
411
+ const factor = Math.pow(10, ndigits);
412
+ return Math.round(number * factor) / factor;
413
+ }
414
+ function ord(char) {
415
+ if (char.length !== 1) {
416
+ throw new Error("ord() expected a character");
417
+ }
418
+ return char.charCodeAt(0);
419
+ }
420
+ function chr(code) {
421
+ return String.fromCharCode(code);
422
+ }
423
+ function hex(x) {
424
+ const prefix = x < 0 ? "-0x" : "0x";
425
+ return prefix + Math.abs(Math.trunc(x)).toString(16);
426
+ }
427
+ function oct(x) {
428
+ const prefix = x < 0 ? "-0o" : "0o";
429
+ return prefix + Math.abs(Math.trunc(x)).toString(8);
430
+ }
431
+ function bin(x) {
432
+ const prefix = x < 0 ? "-0b" : "0b";
433
+ return prefix + Math.abs(Math.trunc(x)).toString(2);
434
+ }
435
+ function int(x, base) {
436
+ if (typeof x === "boolean") {
437
+ return x ? 1 : 0;
438
+ }
439
+ if (typeof x === "number") {
440
+ return Math.trunc(x);
441
+ }
442
+ const parsed = base !== void 0 ? parseInt(x, base) : parseInt(x, 10);
443
+ if (isNaN(parsed)) {
444
+ throw new Error(`invalid literal for int(): '${x}'`);
445
+ }
446
+ return parsed;
447
+ }
448
+ function float(x) {
449
+ if (typeof x === "number") {
450
+ return x;
451
+ }
452
+ const parsed = parseFloat(x);
453
+ if (isNaN(parsed)) {
454
+ throw new Error(`could not convert string to float: '${x}'`);
455
+ }
456
+ return parsed;
457
+ }
458
+ function str(x) {
459
+ if (x === null) {
460
+ return "None";
461
+ }
462
+ if (x === void 0) {
463
+ return "None";
464
+ }
465
+ if (typeof x === "boolean") {
466
+ return x ? "True" : "False";
467
+ }
468
+ if (Array.isArray(x)) {
469
+ return "[" + x.map((item) => py.repr(item)).join(", ") + "]";
470
+ }
471
+ if (x instanceof Map) {
472
+ const entries = Array.from(x.entries()).map(([k, v]) => `${py.repr(k)}: ${py.repr(v)}`).join(", ");
473
+ return "{" + entries + "}";
474
+ }
475
+ if (x instanceof Set) {
476
+ if (x.size === 0) {
477
+ return "set()";
478
+ }
479
+ return "{" + Array.from(x).map((item) => py.repr(item)).join(", ") + "}";
480
+ }
481
+ return String(x);
482
+ }
483
+ function repr(x) {
484
+ if (typeof x === "string") {
485
+ return `'${x}'`;
486
+ }
487
+ return str(x);
488
+ }
489
+ function bool(x) {
490
+ if (x === null || x === void 0) {
491
+ return false;
492
+ }
493
+ if (typeof x === "boolean") {
494
+ return x;
495
+ }
496
+ if (typeof x === "number") {
497
+ return x !== 0;
498
+ }
499
+ if (typeof x === "string") {
500
+ return x.length > 0;
501
+ }
502
+ if (Array.isArray(x)) {
503
+ return x.length > 0;
504
+ }
505
+ if (x instanceof Map || x instanceof Set) {
506
+ return x.size > 0;
507
+ }
508
+ return true;
509
+ }
510
+ function ascii(x) {
511
+ const s = repr(x);
512
+ let result = "";
513
+ for (const char of s) {
514
+ const code = char.charCodeAt(0);
515
+ if (code > 127) {
516
+ if (code > 65535) {
517
+ result += `\\U${code.toString(16).padStart(8, "0")}`;
518
+ } else {
519
+ result += `\\u${code.toString(16).padStart(4, "0")}`;
520
+ }
521
+ } else {
522
+ result += char;
523
+ }
524
+ }
525
+ return result;
526
+ }
527
+ function isinstance(obj, classInfo) {
528
+ if (classInfo === Number || classInfo === "int" || classInfo === "float") {
529
+ return typeof obj === "number";
530
+ }
531
+ if (classInfo === String || classInfo === "str") {
532
+ return typeof obj === "string";
533
+ }
534
+ if (classInfo === Boolean || classInfo === "bool") {
535
+ return typeof obj === "boolean";
536
+ }
537
+ if (classInfo === Array || classInfo === "list") {
538
+ return Array.isArray(obj);
539
+ }
540
+ if (classInfo === Map || classInfo === "dict") {
541
+ return obj instanceof Map;
542
+ }
543
+ if (classInfo === Set || classInfo === "set") {
544
+ return obj instanceof Set;
545
+ }
546
+ if (typeof classInfo === "function") {
547
+ return obj instanceof classInfo;
548
+ }
549
+ return false;
550
+ }
551
+ function type(obj) {
552
+ if (obj === null) return "NoneType";
553
+ if (typeof obj === "number") {
554
+ return Number.isInteger(obj) ? "int" : "float";
555
+ }
556
+ if (typeof obj === "string") return "str";
557
+ if (typeof obj === "boolean") return "bool";
558
+ if (Array.isArray(obj)) return "list";
559
+ if (obj instanceof Map) return "dict";
560
+ if (obj instanceof Set) return "set";
561
+ return typeof obj;
562
+ }
563
+ function input(prompt) {
564
+ if (prompt) {
565
+ process.stdout.write(prompt);
566
+ }
567
+ throw new Error("input() requires async implementation");
568
+ }
569
+ function formatNumber(num, sign, _hash, grouping, precision, isInteger = true) {
570
+ let result;
571
+ if (isInteger) {
572
+ result = Math.trunc(num).toString();
573
+ } else {
574
+ result = num.toFixed(precision ?? 6);
575
+ }
576
+ if (grouping) {
577
+ const sep = grouping === "_" ? "_" : ",";
578
+ const parts = result.split(".");
579
+ const intPart = parts[0];
580
+ const signChar = intPart[0] === "-" ? "-" : "";
581
+ const digits2 = signChar ? intPart.slice(1) : intPart;
582
+ const grouped = digits2.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
583
+ parts[0] = signChar + grouped;
584
+ result = parts.join(".");
585
+ }
586
+ if (num >= 0) {
587
+ if (sign === "+") {
588
+ result = "+" + result;
589
+ } else if (sign === " ") {
590
+ result = " " + result;
591
+ }
592
+ }
593
+ return result;
594
+ }
595
+ function format(value, spec) {
596
+ if (spec === "") {
597
+ return str(value);
598
+ }
599
+ const match = spec.match(
600
+ /^(.?[<>=^])?([+\- ])?([#])?(0)?(\d+)?([,_])?(?:\.(\d+))?([bcdeEfFgGnosxX%])?$/
601
+ );
602
+ if (!match) {
603
+ return str(value);
604
+ }
605
+ const [, alignPart, sign, hash, zero, widthStr, grouping, precisionStr, typeChar] = match;
606
+ let fill = " ";
607
+ let align = "";
608
+ if (alignPart) {
609
+ if (alignPart.length === 2) {
610
+ fill = alignPart[0];
611
+ align = alignPart[1];
612
+ } else {
613
+ align = alignPart;
614
+ }
615
+ }
616
+ const width = widthStr ? parseInt(widthStr, 10) : 0;
617
+ const precision = precisionStr !== void 0 ? parseInt(precisionStr, 10) : void 0;
618
+ if (zero && !alignPart) {
619
+ fill = "0";
620
+ align = "=";
621
+ }
622
+ let result;
623
+ if (typeChar === "s" || !typeChar && typeof value === "string") {
624
+ result = str(value);
625
+ if (precision !== void 0) {
626
+ result = result.slice(0, precision);
627
+ }
628
+ } else if (typeChar === "d" || !typeChar && typeof value === "number" && Number.isInteger(value)) {
629
+ const num = typeof value === "number" ? value : int(value);
630
+ result = formatNumber(num, sign, "", grouping);
631
+ } else if (typeChar === "f" || typeChar === "F") {
632
+ const num = typeof value === "number" ? value : float(value);
633
+ const prec = precision ?? 6;
634
+ result = formatNumber(num, sign, "", grouping, prec, false);
635
+ if (typeChar === "F") result = result.toUpperCase();
636
+ } else if (typeChar === "e" || typeChar === "E") {
637
+ const num = typeof value === "number" ? value : float(value);
638
+ const prec = precision ?? 6;
639
+ result = num.toExponential(prec);
640
+ if (sign === "+" && num >= 0) result = "+" + result;
641
+ else if (sign === " " && num >= 0) result = " " + result;
642
+ if (typeChar === "E") result = result.toUpperCase();
643
+ } else if (typeChar === "g" || typeChar === "G") {
644
+ const num = typeof value === "number" ? value : float(value);
645
+ const prec = precision ?? 6;
646
+ result = num.toPrecision(prec);
647
+ if (sign === "+" && num >= 0) result = "+" + result;
648
+ else if (sign === " " && num >= 0) result = " " + result;
649
+ if (typeChar === "G") result = result.toUpperCase();
650
+ } else if (typeChar === "x" || typeChar === "X") {
651
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
652
+ result = Math.abs(num).toString(16);
653
+ if (hash) result = "0x" + result;
654
+ if (num < 0) result = "-" + result;
655
+ else if (sign === "+") result = "+" + result;
656
+ else if (sign === " ") result = " " + result;
657
+ if (typeChar === "X") result = result.toUpperCase();
658
+ } else if (typeChar === "o") {
659
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
660
+ result = Math.abs(num).toString(8);
661
+ if (hash) result = "0o" + result;
662
+ if (num < 0) result = "-" + result;
663
+ else if (sign === "+") result = "+" + result;
664
+ else if (sign === " ") result = " " + result;
665
+ } else if (typeChar === "b") {
666
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
667
+ result = Math.abs(num).toString(2);
668
+ if (hash) result = "0b" + result;
669
+ if (num < 0) result = "-" + result;
670
+ else if (sign === "+") result = "+" + result;
671
+ else if (sign === " ") result = " " + result;
672
+ } else if (typeChar === "c") {
673
+ const code = typeof value === "number" ? value : int(value);
674
+ result = String.fromCharCode(code);
675
+ } else if (typeChar === "%") {
676
+ const num = typeof value === "number" ? value : float(value);
677
+ const prec = precision ?? 6;
678
+ result = (num * 100).toFixed(prec) + "%";
679
+ if (sign === "+" && num >= 0) result = "+" + result;
680
+ else if (sign === " " && num >= 0) result = " " + result;
681
+ } else if (typeChar === "n") {
682
+ const num = typeof value === "number" ? value : float(value);
683
+ result = num.toLocaleString();
684
+ } else {
685
+ result = str(value);
686
+ }
687
+ if (width > result.length) {
688
+ const padding = fill.repeat(width - result.length);
689
+ if (align === "<") {
690
+ result = result + padding;
691
+ } else if (align === ">" || align === "") {
692
+ result = padding + result;
693
+ } else if (align === "^") {
694
+ const leftPad = Math.floor((width - result.length) / 2);
695
+ const rightPad = width - result.length - leftPad;
696
+ result = fill.repeat(leftPad) + result + fill.repeat(rightPad);
697
+ } else if (align === "=") {
698
+ const signMatch = result.match(/^([+\- ]|0[xXoObB])?(.*)$/);
699
+ if (signMatch) {
700
+ const signPart = signMatch[1] ?? "";
701
+ const numPart = signMatch[2] ?? "";
702
+ result = signPart + padding + numPart;
703
+ }
704
+ }
705
+ }
706
+ return result;
707
+ }
708
+
709
+ // src/list.ts
710
+ var list2 = {
711
+ /**
712
+ * Python list.append() - modifies array in place
713
+ */
714
+ append(arr, item) {
715
+ arr.push(item);
716
+ },
717
+ /**
718
+ * Python list.extend() - modifies array in place
719
+ */
720
+ extend(arr, items) {
721
+ arr.push(...items);
722
+ },
723
+ /**
724
+ * Python list.insert() - modifies array in place
725
+ */
726
+ insert(arr, index, item) {
727
+ arr.splice(index, 0, item);
728
+ },
729
+ /**
730
+ * Python list.remove() - removes first occurrence, modifies in place
731
+ */
732
+ remove(arr, value) {
733
+ const index = arr.indexOf(value);
734
+ if (index === -1) {
735
+ throw new Error("list.remove(x): x not in list");
736
+ }
737
+ arr.splice(index, 1);
738
+ },
739
+ /**
740
+ * Python list.pop() - removes and returns item at index
741
+ */
742
+ pop(arr, index) {
743
+ if (arr.length === 0) {
744
+ throw new Error("pop from empty list");
745
+ }
746
+ const i = index ?? arr.length - 1;
747
+ const normalizedIndex = i < 0 ? arr.length + i : i;
748
+ if (normalizedIndex < 0 || normalizedIndex >= arr.length) {
749
+ throw new Error("pop index out of range");
750
+ }
751
+ return arr.splice(normalizedIndex, 1)[0];
752
+ },
753
+ /**
754
+ * Python list.clear() - removes all items
755
+ */
756
+ clear(arr) {
757
+ arr.length = 0;
758
+ },
759
+ /**
760
+ * Python list.index() - finds first occurrence
761
+ */
762
+ index(arr, value, start, end) {
763
+ const searchStart = start ?? 0;
764
+ const searchEnd = end ?? arr.length;
765
+ for (let i = searchStart; i < searchEnd; i++) {
766
+ if (arr[i] === value) {
767
+ return i;
768
+ }
769
+ }
770
+ throw new Error("x not in list");
771
+ },
772
+ /**
773
+ * Python list.count() - counts occurrences
774
+ */
775
+ count(arr, value) {
776
+ let count = 0;
777
+ for (const item of arr) {
778
+ if (item === value) count++;
779
+ }
780
+ return count;
781
+ },
782
+ /**
783
+ * Python list.sort() with key function - modifies in place
784
+ */
785
+ sort(arr, options) {
786
+ const key = options?.key ?? ((x) => x);
787
+ const reverse = options?.reverse ?? false;
788
+ arr.sort((a, b) => {
789
+ const aKey = key(a);
790
+ const bKey = key(b);
791
+ let cmp = 0;
792
+ if (aKey < bKey) cmp = -1;
793
+ else if (aKey > bKey) cmp = 1;
794
+ return reverse ? -cmp : cmp;
795
+ });
796
+ },
797
+ /**
798
+ * Python list.reverse() - reverses in place
799
+ */
800
+ reverse(arr) {
801
+ arr.reverse();
802
+ },
803
+ /**
804
+ * Python list.copy() - shallow copy
805
+ */
806
+ copy(arr) {
807
+ return [...arr];
808
+ },
809
+ /**
810
+ * Python slice assignment: arr[start:end:step] = values
811
+ * Replaces a slice of the array with new values, modifying in place
812
+ */
813
+ sliceAssign(arr, start, end, step, values) {
814
+ const len3 = arr.length;
815
+ const actualStep = step ?? 1;
816
+ let actualStart = start ?? (actualStep > 0 ? 0 : len3 - 1);
817
+ let actualEnd = end ?? (actualStep > 0 ? len3 : -len3 - 1);
818
+ if (actualStart < 0) actualStart = Math.max(0, len3 + actualStart);
819
+ if (actualEnd < 0) actualEnd = Math.max(0, len3 + actualEnd);
820
+ actualStart = Math.min(actualStart, len3);
821
+ actualEnd = Math.min(actualEnd, len3);
822
+ if (actualStep === 1) {
823
+ const deleteCount = Math.max(0, actualEnd - actualStart);
824
+ arr.splice(actualStart, deleteCount, ...values);
825
+ } else {
826
+ const indices = [];
827
+ if (actualStep > 0) {
828
+ for (let i = actualStart; i < actualEnd; i += actualStep) {
829
+ indices.push(i);
830
+ }
831
+ } else {
832
+ for (let i = actualStart; i > actualEnd; i += actualStep) {
833
+ indices.push(i);
834
+ }
835
+ }
836
+ if (indices.length !== values.length) {
837
+ throw new Error(
838
+ `attempt to assign sequence of size ${String(values.length)} to extended slice of size ${String(indices.length)}`
839
+ );
840
+ }
841
+ for (let i = 0; i < indices.length; i++) {
842
+ const idx = indices[i];
843
+ if (idx !== void 0) {
844
+ arr[idx] = values[i];
845
+ }
846
+ }
847
+ }
848
+ }
849
+ };
850
+
851
+ // src/dict.ts
852
+ var dict2 = {
853
+ /**
854
+ * Python dict.get() - get value with optional default
855
+ */
856
+ get(obj, key, defaultValue) {
857
+ return key in obj ? obj[key] : defaultValue;
858
+ },
859
+ /**
860
+ * Python dict.setdefault() - get value or set default
861
+ */
862
+ setdefault(obj, key, defaultValue) {
863
+ if (!(key in obj)) {
864
+ obj[key] = defaultValue;
865
+ }
866
+ return obj[key];
867
+ },
868
+ /**
869
+ * Python dict.pop() - remove and return value
870
+ */
871
+ pop(obj, key, defaultValue) {
872
+ if (key in obj) {
873
+ const value = obj[key];
874
+ delete obj[key];
875
+ return value;
876
+ }
877
+ if (defaultValue !== void 0) {
878
+ return defaultValue;
879
+ }
880
+ throw new Error("KeyError");
881
+ },
882
+ /**
883
+ * Python dict.popitem() - remove and return last item
884
+ */
885
+ popitem(obj) {
886
+ const keys = Object.keys(obj);
887
+ if (keys.length === 0) {
888
+ throw new Error("dictionary is empty");
889
+ }
890
+ const key = keys[keys.length - 1];
891
+ const value = obj[key];
892
+ delete obj[key];
893
+ return [key, value];
894
+ },
895
+ /**
896
+ * Python dict.update() - update with another dict
897
+ */
898
+ update(obj, other) {
899
+ if (Symbol.iterator in other) {
900
+ for (const [k, v] of other) {
901
+ obj[k] = v;
902
+ }
903
+ } else {
904
+ Object.assign(obj, other);
905
+ }
906
+ },
907
+ /**
908
+ * Python dict.clear() - remove all items
909
+ */
910
+ clear(obj) {
911
+ for (const key of Object.keys(obj)) {
912
+ delete obj[key];
913
+ }
914
+ },
915
+ /**
916
+ * Python dict.copy() - shallow copy
917
+ */
918
+ copy(obj) {
919
+ return { ...obj };
920
+ },
921
+ /**
922
+ * Python dict.keys() - returns iterable of keys
923
+ */
924
+ keys(obj) {
925
+ return Object.keys(obj);
926
+ },
927
+ /**
928
+ * Python dict.values() - returns iterable of values
929
+ */
930
+ values(obj) {
931
+ return Object.values(obj);
932
+ },
933
+ /**
934
+ * Python dict.items() - returns iterable of [key, value] pairs
935
+ */
936
+ items(obj) {
937
+ return Object.entries(obj);
938
+ },
939
+ /**
940
+ * Python dict.fromkeys() - create dict from keys
941
+ */
942
+ fromkeys(keys, value) {
943
+ const result = {};
944
+ for (const key of keys) {
945
+ result[key] = value;
946
+ }
947
+ return result;
948
+ }
949
+ };
950
+
951
+ // src/set.ts
952
+ var set2 = {
953
+ /**
954
+ * Python set.add() - add element
955
+ */
956
+ add(s, item) {
957
+ s.add(item);
958
+ },
959
+ /**
960
+ * Python set.remove() - remove element, raises error if not found
961
+ */
962
+ remove(s, item) {
963
+ if (!s.has(item)) {
964
+ throw new Error("KeyError");
965
+ }
966
+ s.delete(item);
967
+ },
968
+ /**
969
+ * Python set.discard() - remove element if present
970
+ */
971
+ discard(s, item) {
972
+ s.delete(item);
973
+ },
974
+ /**
975
+ * Python set.pop() - remove and return arbitrary element
976
+ */
977
+ pop(s) {
978
+ if (s.size === 0) {
979
+ throw new Error("pop from an empty set");
980
+ }
981
+ const item = s.values().next().value;
982
+ s.delete(item);
983
+ return item;
984
+ },
985
+ /**
986
+ * Python set.clear() - remove all elements
987
+ */
988
+ clear(s) {
989
+ s.clear();
990
+ },
991
+ /**
992
+ * Python set.copy() - shallow copy
993
+ */
994
+ copy(s) {
995
+ return new Set(s);
996
+ },
997
+ /**
998
+ * Python set.update() - add elements from iterable
999
+ */
1000
+ update(s, ...iterables) {
1001
+ for (const iterable of iterables) {
1002
+ for (const item of iterable) {
1003
+ s.add(item);
1004
+ }
1005
+ }
1006
+ },
1007
+ /**
1008
+ * Python set.union() - returns new set with all elements
1009
+ */
1010
+ union(a, ...others) {
1011
+ const result = new Set(a);
1012
+ for (const other of others) {
1013
+ for (const item of other) {
1014
+ result.add(item);
1015
+ }
1016
+ }
1017
+ return result;
1018
+ },
1019
+ /**
1020
+ * Python set.intersection() - returns new set with common elements
1021
+ */
1022
+ intersection(a, b) {
1023
+ const result = /* @__PURE__ */ new Set();
1024
+ for (const item of a) {
1025
+ if (b.has(item)) result.add(item);
1026
+ }
1027
+ return result;
1028
+ },
1029
+ /**
1030
+ * Python set.intersection_update() - keep only common elements
1031
+ */
1032
+ intersectionUpdate(a, b) {
1033
+ for (const item of a) {
1034
+ if (!b.has(item)) a.delete(item);
1035
+ }
1036
+ },
1037
+ /**
1038
+ * Python set.difference() - returns new set with elements in a but not in b
1039
+ */
1040
+ difference(a, b) {
1041
+ const result = /* @__PURE__ */ new Set();
1042
+ for (const item of a) {
1043
+ if (!b.has(item)) result.add(item);
1044
+ }
1045
+ return result;
1046
+ },
1047
+ /**
1048
+ * Python set.difference_update() - remove elements found in b
1049
+ */
1050
+ differenceUpdate(a, b) {
1051
+ for (const item of b) {
1052
+ a.delete(item);
1053
+ }
1054
+ },
1055
+ /**
1056
+ * Python set.symmetric_difference() - returns new set with elements in either but not both
1057
+ */
1058
+ symmetricDifference(a, b) {
1059
+ const result = /* @__PURE__ */ new Set();
1060
+ for (const item of a) {
1061
+ if (!b.has(item)) result.add(item);
1062
+ }
1063
+ for (const item of b) {
1064
+ if (!a.has(item)) result.add(item);
1065
+ }
1066
+ return result;
1067
+ },
1068
+ /**
1069
+ * Python set.symmetric_difference_update() - update with symmetric difference
1070
+ */
1071
+ symmetricDifferenceUpdate(a, b) {
1072
+ const toAdd = [];
1073
+ const toRemove = [];
1074
+ for (const item of a) {
1075
+ if (b.has(item)) toRemove.push(item);
1076
+ }
1077
+ for (const item of b) {
1078
+ if (!a.has(item)) toAdd.push(item);
1079
+ }
1080
+ for (const item of toRemove) a.delete(item);
1081
+ for (const item of toAdd) a.add(item);
1082
+ },
1083
+ /**
1084
+ * Python set.issubset() - test if all elements are in other
1085
+ */
1086
+ issubset(a, b) {
1087
+ for (const item of a) {
1088
+ if (!b.has(item)) return false;
1089
+ }
1090
+ return true;
1091
+ },
1092
+ /**
1093
+ * Python set.issuperset() - test if all other elements are in this set
1094
+ */
1095
+ issuperset(a, b) {
1096
+ for (const item of b) {
1097
+ if (!a.has(item)) return false;
1098
+ }
1099
+ return true;
1100
+ },
1101
+ /**
1102
+ * Python set.isdisjoint() - test if no common elements
1103
+ */
1104
+ isdisjoint(a, b) {
1105
+ for (const item of a) {
1106
+ if (b.has(item)) return false;
1107
+ }
1108
+ return true;
1109
+ }
1110
+ };
1111
+
1112
+ // src/index.ts
1113
+ var itertools = itertools_exports;
1114
+ var functools = functools_exports;
1115
+ var collections = collections_exports;
1116
+ var math = math_exports;
1117
+ var random = random_exports;
1118
+ var json = json_exports;
1119
+ var os = os_exports;
1120
+ var datetime = datetime_exports;
1121
+ var re = re_exports;
1122
+ var string2 = {
1123
+ ...string,
1124
+ ascii_lowercase,
1125
+ ascii_uppercase,
1126
+ ascii_letters,
1127
+ digits,
1128
+ hexdigits,
1129
+ octdigits,
1130
+ punctuation,
1131
+ whitespace,
1132
+ printable,
1133
+ capwords,
1134
+ Template
1135
+ };
1136
+ var list3 = Object.assign(
1137
+ (iterable) => list(iterable),
1138
+ list2
1139
+ );
1140
+ var dict3 = Object.assign(
1141
+ (entries) => dict(entries),
1142
+ dict2
1143
+ );
1144
+ var set3 = Object.assign(
1145
+ (iterable) => set(iterable),
1146
+ set2
1147
+ );
1148
+ var floordiv2 = floordiv;
1149
+ var mod2 = mod;
1150
+ var divmod2 = divmod;
1151
+ var sprintf2 = sprintf;
1152
+ var strFormat2 = strFormat;
1153
+ var slice2 = slice;
1154
+ var at2 = at;
1155
+ var contains2 = contains;
1156
+ var is2 = is;
1157
+ var range2 = range;
1158
+ var enumerate2 = enumerate;
1159
+ var zip2 = zip;
1160
+ var iter2 = iter;
1161
+ var reversed2 = reversed;
1162
+ var sorted2 = sorted;
1163
+ var map2 = map;
1164
+ var filter2 = filter;
1165
+ var tuple2 = tuple;
1166
+ var len2 = len;
1167
+ var abs2 = abs;
1168
+ var min2 = min;
1169
+ var max2 = max;
1170
+ var sum2 = sum;
1171
+ var all2 = all;
1172
+ var any2 = any;
1173
+ var round2 = round;
1174
+ var ord2 = ord;
1175
+ var chr2 = chr;
1176
+ var hex2 = hex;
1177
+ var oct2 = oct;
1178
+ var bin2 = bin;
1179
+ var int2 = int;
1180
+ var float2 = float;
1181
+ var str2 = str;
1182
+ var repr2 = repr;
1183
+ var bool2 = bool;
1184
+ var ascii2 = ascii;
1185
+ var isinstance2 = isinstance;
1186
+ var type2 = type;
1187
+ var input2 = input;
1188
+ var format2 = format;
1189
+ var py2 = {
1190
+ // Namespaced methods
1191
+ string,
1192
+ list: list3,
1193
+ dict: dict3,
1194
+ set: set3,
1195
+ // Core operations
1196
+ floordiv,
1197
+ pow,
1198
+ mod,
1199
+ divmod,
1200
+ sprintf,
1201
+ strFormat,
1202
+ slice,
1203
+ at,
1204
+ repeat,
1205
+ in: contains,
1206
+ is,
1207
+ // Iterables
1208
+ range,
1209
+ enumerate,
1210
+ zip,
1211
+ iter,
1212
+ reversed,
1213
+ sorted,
1214
+ map,
1215
+ filter,
1216
+ // Collection constructors
1217
+ tuple,
1218
+ // Built-in functions
1219
+ len,
1220
+ abs,
1221
+ min,
1222
+ max,
1223
+ sum,
1224
+ all,
1225
+ any,
1226
+ round,
1227
+ ord,
1228
+ chr,
1229
+ hex,
1230
+ oct,
1231
+ bin,
1232
+ // Type conversions
1233
+ int,
1234
+ float,
1235
+ str,
1236
+ repr,
1237
+ bool,
1238
+ ascii,
1239
+ // Type checking
1240
+ isinstance,
1241
+ type,
1242
+ input,
1243
+ format,
1244
+ // Modules
1245
+ itertools: itertools_exports,
1246
+ functools: functools_exports,
1247
+ math: math_exports,
1248
+ random: random_exports,
1249
+ json: json_exports,
1250
+ os: os_exports,
1251
+ datetime: datetime_exports,
1252
+ re: re_exports,
1253
+ // collections
1254
+ Counter,
1255
+ defaultdict,
1256
+ deque,
1257
+ // string module
1258
+ Template,
1259
+ ascii_lowercase,
1260
+ ascii_uppercase,
1261
+ ascii_letters,
1262
+ digits,
1263
+ hexdigits,
1264
+ octdigits,
1265
+ punctuation,
1266
+ whitespace,
1267
+ printable,
1268
+ capwords
1269
+ };
1270
+ _setPyRef(py2);
1271
+ var index_default = py2;
1272
+ export {
1273
+ abs2 as abs,
1274
+ all2 as all,
1275
+ any2 as any,
1276
+ ascii2 as ascii,
1277
+ at2 as at,
1278
+ bin2 as bin,
1279
+ bool2 as bool,
1280
+ chr2 as chr,
1281
+ collections,
1282
+ contains2 as contains,
1283
+ datetime,
1284
+ index_default as default,
1285
+ dict3 as dict,
1286
+ divmod2 as divmod,
1287
+ enumerate2 as enumerate,
1288
+ filter2 as filter,
1289
+ float2 as float,
1290
+ floordiv2 as floordiv,
1291
+ format2 as format,
1292
+ functools,
1293
+ hex2 as hex,
1294
+ input2 as input,
1295
+ int2 as int,
1296
+ is2 as is,
1297
+ isinstance2 as isinstance,
1298
+ iter2 as iter,
1299
+ itertools,
1300
+ json,
1301
+ len2 as len,
1302
+ list3 as list,
1303
+ map2 as map,
1304
+ math,
1305
+ max2 as max,
1306
+ min2 as min,
1307
+ mod2 as mod,
1308
+ oct2 as oct,
1309
+ ord2 as ord,
1310
+ os,
1311
+ pow,
1312
+ py2 as py,
1313
+ random,
1314
+ range2 as range,
1315
+ re,
1316
+ repeat as repeatValue,
1317
+ repr2 as repr,
1318
+ reversed2 as reversed,
1319
+ round2 as round,
1320
+ set3 as set,
1321
+ slice2 as slice,
1322
+ sorted2 as sorted,
1323
+ sprintf2 as sprintf,
1324
+ str2 as str,
1325
+ strFormat2 as strFormat,
1326
+ string2 as string,
1327
+ sum2 as sum,
1328
+ tuple2 as tuple,
1329
+ type2 as type,
1330
+ zip2 as zip
1331
+ };
1332
+ //# sourceMappingURL=index.js.map