pythonlib 1.0.2 → 2.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 (133) hide show
  1. package/README.md +123 -49
  2. package/dist/base64-C_am75Sv.d.ts +165 -0
  3. package/dist/base64.d.ts +1 -0
  4. package/dist/base64.js +37 -0
  5. package/dist/chunk-2QEMKE7U.js +252 -0
  6. package/dist/chunk-2YTO24B5.js +78 -0
  7. package/dist/chunk-3HQSBCEC.js +348 -0
  8. package/dist/{chunk-7BZB2TQF.js → chunk-3M3PB4RO.js} +4 -6
  9. package/dist/chunk-5OKGPZBQ.js +1106 -0
  10. package/dist/chunk-B5LQJODJ.js +37 -0
  11. package/dist/{chunk-CUP6EPDB.js → chunk-BCMGGBWG.js} +2 -5
  12. package/dist/chunk-BCVIH2BN.js +175 -0
  13. package/dist/chunk-CANUXHVB.js +349 -0
  14. package/dist/{chunk-QURVRHY2.js → chunk-D35YI363.js} +15 -12
  15. package/dist/{chunk-RSBRI27Z.js → chunk-ETBW6XNR.js} +3 -4
  16. package/dist/chunk-HSTC277I.js +255 -0
  17. package/dist/chunk-HTCQ4OO5.js +238 -0
  18. package/dist/chunk-IANXD4D4.js +250 -0
  19. package/dist/{chunk-G6PUQTVZ.js → chunk-JAUU3HMH.js} +1 -2
  20. package/dist/chunk-JVTQM7CI.js +195 -0
  21. package/dist/chunk-KKJHGY4C.js +551 -0
  22. package/dist/chunk-LHPQS75Z.js +192 -0
  23. package/dist/{chunk-OSX7QZAW.js → chunk-LK2L2TFG.js} +5 -6
  24. package/dist/{chunk-CEZSBJJV.js → chunk-LWYBTWBZ.js} +2 -3
  25. package/dist/chunk-MEEU4SH5.js +362 -0
  26. package/dist/{chunk-TAYRRHJ3.js → chunk-MFKIEN7N.js} +1 -2
  27. package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
  28. package/dist/chunk-OZRS5PC4.js +312 -0
  29. package/dist/chunk-PVK4F3ME.js +194 -0
  30. package/dist/{chunk-56DGFWIJ.js → chunk-QKJBQKPY.js} +1 -2
  31. package/dist/chunk-RB6BYCIQ.js +141 -0
  32. package/dist/chunk-RRSOZXZE.js +155 -0
  33. package/dist/chunk-THMJVAK6.js +282 -0
  34. package/dist/chunk-UGZ5OY5Z.js +165 -0
  35. package/dist/chunk-WTZSAITC.js +82 -0
  36. package/dist/chunk-YONWJHJU.js +265 -0
  37. package/dist/collections.js +2 -3
  38. package/dist/copy-6ZaZ__ge.d.ts +59 -0
  39. package/dist/copy.d.ts +1 -0
  40. package/dist/copy.js +9 -0
  41. package/dist/datetime.js +2 -3
  42. package/dist/functools.js +2 -3
  43. package/dist/glob.browser-B6d_YdV5.d.ts +50 -0
  44. package/dist/glob.browser.d.ts +1 -0
  45. package/dist/glob.browser.js +15 -0
  46. package/dist/glob.node-wn5ehtyM.d.ts +80 -0
  47. package/dist/glob.node.d.ts +1 -0
  48. package/dist/glob.node.js +15 -0
  49. package/dist/hashlib-vKP511NY.d.ts +205 -0
  50. package/dist/hashlib.d.ts +1 -0
  51. package/dist/hashlib.js +39 -0
  52. package/dist/index.browser.d.ts +172 -0
  53. package/dist/index.browser.js +305 -0
  54. package/dist/index.d.ts +36 -602
  55. package/dist/index.js +138 -1073
  56. package/dist/itertools.js +2 -3
  57. package/dist/json.js +2 -3
  58. package/dist/logging.browser-Dux4L5kz.d.ts +185 -0
  59. package/dist/logging.browser.d.ts +1 -0
  60. package/dist/logging.browser.js +63 -0
  61. package/dist/logging.node-CH75bVdE.d.ts +185 -0
  62. package/dist/logging.node.d.ts +1 -0
  63. package/dist/logging.node.js +61 -0
  64. package/dist/math.js +2 -3
  65. package/dist/{os-CqGKe872.d.ts → os.browser-krjSx5kF.d.ts} +32 -55
  66. package/dist/os.browser.d.ts +2 -0
  67. package/dist/{os.js → os.browser.js} +41 -16
  68. package/dist/os.node-CQjch8Ht.d.ts +124 -0
  69. package/dist/os.node.d.ts +2 -0
  70. package/dist/os.node.js +83 -0
  71. package/dist/os.shared-C3x70nhO.d.ts +59 -0
  72. package/dist/pathlib.browser-NC7kKQYe.d.ts +91 -0
  73. package/dist/pathlib.browser.d.ts +1 -0
  74. package/dist/pathlib.browser.js +17 -0
  75. package/dist/pathlib.node-CY3yUFdT.d.ts +331 -0
  76. package/dist/pathlib.node.d.ts +2 -0
  77. package/dist/pathlib.node.js +17 -0
  78. package/dist/random.js +2 -3
  79. package/dist/re.js +2 -3
  80. package/dist/set-JQbLAq8B.d.ts +592 -0
  81. package/dist/shutil.browser-Ck5oWhnP.d.ts +113 -0
  82. package/dist/shutil.browser.d.ts +1 -0
  83. package/dist/shutil.browser.js +33 -0
  84. package/dist/shutil.node-C9kwvhAf.d.ts +160 -0
  85. package/dist/shutil.node.d.ts +2 -0
  86. package/dist/shutil.node.js +33 -0
  87. package/dist/string.js +2 -3
  88. package/dist/subprocess-CZVYzQ3V.d.ts +214 -0
  89. package/dist/subprocess.d.ts +1 -0
  90. package/dist/subprocess.js +29 -0
  91. package/dist/sys-IL8LgI_W.d.ts +212 -0
  92. package/dist/sys.d.ts +1 -0
  93. package/dist/sys.js +51 -0
  94. package/dist/tempfile.browser-DciOKfNm.d.ts +78 -0
  95. package/dist/tempfile.browser.d.ts +1 -0
  96. package/dist/tempfile.browser.js +19 -0
  97. package/dist/tempfile.node-bVMY60Cu.d.ts +195 -0
  98. package/dist/tempfile.node.d.ts +2 -0
  99. package/dist/tempfile.node.js +23 -0
  100. package/dist/time-CcYhdiSu.d.ts +245 -0
  101. package/dist/time.d.ts +1 -0
  102. package/dist/time.js +49 -0
  103. package/dist/urllib-DJtkj-0f.d.ts +198 -0
  104. package/dist/urllib.d.ts +1 -0
  105. package/dist/urllib.js +37 -0
  106. package/dist/uuid-C0ypmn56.d.ts +160 -0
  107. package/dist/uuid.d.ts +1 -0
  108. package/dist/uuid.js +23 -0
  109. package/package.json +128 -5
  110. package/dist/chunk-56DGFWIJ.js.map +0 -1
  111. package/dist/chunk-5AOJFFYN.js +0 -313
  112. package/dist/chunk-5AOJFFYN.js.map +0 -1
  113. package/dist/chunk-7BZB2TQF.js.map +0 -1
  114. package/dist/chunk-CEZSBJJV.js.map +0 -1
  115. package/dist/chunk-CUP6EPDB.js.map +0 -1
  116. package/dist/chunk-G6PUQTVZ.js.map +0 -1
  117. package/dist/chunk-OSX7QZAW.js.map +0 -1
  118. package/dist/chunk-PZ5AY32C.js.map +0 -1
  119. package/dist/chunk-QURVRHY2.js.map +0 -1
  120. package/dist/chunk-RSBRI27Z.js.map +0 -1
  121. package/dist/chunk-TAYRRHJ3.js.map +0 -1
  122. package/dist/collections.js.map +0 -1
  123. package/dist/datetime.js.map +0 -1
  124. package/dist/functools.js.map +0 -1
  125. package/dist/index.js.map +0 -1
  126. package/dist/itertools.js.map +0 -1
  127. package/dist/json.js.map +0 -1
  128. package/dist/math.js.map +0 -1
  129. package/dist/os.d.ts +0 -1
  130. package/dist/os.js.map +0 -1
  131. package/dist/random.js.map +0 -1
  132. package/dist/re.js.map +0 -1
  133. package/dist/string.js.map +0 -1
@@ -0,0 +1,1106 @@
1
+ // src/core.ts
2
+ function floorDiv(a, b) {
3
+ return Math.floor(a / b);
4
+ }
5
+ function pow(base, exp) {
6
+ return Math.pow(base, exp);
7
+ }
8
+ function mod(a, b) {
9
+ return (a % b + b) % b;
10
+ }
11
+ function divMod(a, b) {
12
+ return [floorDiv(a, b), mod(a, b)];
13
+ }
14
+ function sprintf(template, args) {
15
+ const values = Array.isArray(args) ? args : [args];
16
+ let index = 0;
17
+ return template.replace(
18
+ /%([+-]?\d*\.?\d*)([sdifxXorec%])/g,
19
+ (match, flags, type2) => {
20
+ if (type2 === "%") return "%";
21
+ if (index >= values.length) return match;
22
+ const value = values[index++];
23
+ switch (type2) {
24
+ case "s":
25
+ return String(value);
26
+ case "d":
27
+ case "i":
28
+ return String(Math.floor(Number(value)));
29
+ case "f":
30
+ if (flags.includes(".")) {
31
+ const precision = parseInt(flags.split(".")[1] ?? "6", 10);
32
+ return Number(value).toFixed(precision);
33
+ }
34
+ return String(Number(value));
35
+ case "x":
36
+ return Math.floor(Number(value)).toString(16);
37
+ case "X":
38
+ return Math.floor(Number(value)).toString(16).toUpperCase();
39
+ case "o":
40
+ return Math.floor(Number(value)).toString(8);
41
+ case "r":
42
+ return JSON.stringify(value);
43
+ case "e":
44
+ return Number(value).toExponential();
45
+ case "c":
46
+ return String.fromCharCode(Number(value));
47
+ /* v8 ignore next 2 -- unreachable: regex only matches handled cases @preserve */
48
+ default:
49
+ return String(value);
50
+ }
51
+ }
52
+ );
53
+ }
54
+ function strFormat(template, ...args) {
55
+ let positionalIndex = 0;
56
+ const lastArg = args[args.length - 1];
57
+ const namedParams = lastArg && typeof lastArg === "object" && !Array.isArray(lastArg) ? lastArg : {};
58
+ return template.replace(/\{([^}]*)\}/g, (match, key) => {
59
+ if (key === "") {
60
+ if (positionalIndex < args.length) {
61
+ return String(args[positionalIndex++]);
62
+ }
63
+ return match;
64
+ }
65
+ const numIndex = parseInt(key, 10);
66
+ if (!isNaN(numIndex) && numIndex < args.length) {
67
+ return String(args[numIndex]);
68
+ }
69
+ if (key in namedParams) {
70
+ return String(namedParams[key]);
71
+ }
72
+ return match;
73
+ });
74
+ }
75
+ function normalizeIndex(index, length, forNegativeStep = false) {
76
+ if (index < 0) {
77
+ index = length + index;
78
+ }
79
+ if (forNegativeStep) {
80
+ return Math.max(-1, Math.min(length - 1, index));
81
+ }
82
+ return Math.max(0, Math.min(length, index));
83
+ }
84
+ function slice(obj, start, stop, step) {
85
+ const len2 = obj.length;
86
+ const actualStep = step ?? 1;
87
+ if (actualStep === 0) {
88
+ throw new Error("slice step cannot be zero");
89
+ }
90
+ let actualStart;
91
+ let actualStop;
92
+ if (actualStep > 0) {
93
+ actualStart = start === void 0 ? 0 : normalizeIndex(start, len2);
94
+ actualStop = stop === void 0 ? len2 : normalizeIndex(stop, len2);
95
+ } else {
96
+ actualStart = start === void 0 ? len2 - 1 : normalizeIndex(start, len2, true);
97
+ actualStop = stop === void 0 ? -1 : normalizeIndex(stop, len2, true);
98
+ }
99
+ const result = [];
100
+ if (actualStep > 0) {
101
+ for (let i = actualStart; i < actualStop; i += actualStep) {
102
+ if (i >= 0 && i < len2) {
103
+ result.push(obj[i]);
104
+ }
105
+ }
106
+ } else {
107
+ for (let i = actualStart; i > actualStop; i += actualStep) {
108
+ if (i >= 0 && i < len2) {
109
+ result.push(obj[i]);
110
+ }
111
+ }
112
+ }
113
+ if (typeof obj === "string") {
114
+ return result.join("");
115
+ }
116
+ return result;
117
+ }
118
+ function at(obj, index) {
119
+ const len2 = obj.length;
120
+ const normalizedIndex = index < 0 ? len2 + index : index;
121
+ if (normalizedIndex < 0 || normalizedIndex >= len2) {
122
+ throw new Error("IndexError: list index out of range");
123
+ }
124
+ return obj[normalizedIndex];
125
+ }
126
+ function repeat(obj, count) {
127
+ if (count <= 0) {
128
+ return typeof obj === "string" ? "" : [];
129
+ }
130
+ if (typeof obj === "string") {
131
+ return obj.repeat(count);
132
+ }
133
+ const result = [];
134
+ for (let i = 0; i < count; i++) {
135
+ result.push(...obj);
136
+ }
137
+ return result;
138
+ }
139
+ function contains(item, container) {
140
+ if (typeof container === "string") {
141
+ return container.includes(item);
142
+ }
143
+ if (container instanceof Map) {
144
+ return container.has(item);
145
+ }
146
+ if (container instanceof Set) {
147
+ return container.has(item);
148
+ }
149
+ if (Array.isArray(container)) {
150
+ return container.includes(item);
151
+ }
152
+ for (const element of container) {
153
+ if (element === item) {
154
+ return true;
155
+ }
156
+ }
157
+ return false;
158
+ }
159
+ function is(a, b) {
160
+ return a === b;
161
+ }
162
+
163
+ // src/builtins.ts
164
+ function range(startOrStop, stop, step) {
165
+ let start;
166
+ let end;
167
+ let stepVal;
168
+ if (stop === void 0) {
169
+ start = 0;
170
+ end = startOrStop;
171
+ stepVal = 1;
172
+ } else {
173
+ start = startOrStop;
174
+ end = stop;
175
+ stepVal = step ?? 1;
176
+ }
177
+ if (stepVal === 0) {
178
+ throw new Error("range() arg 3 must not be zero");
179
+ }
180
+ return {
181
+ *[Symbol.iterator]() {
182
+ if (stepVal > 0) {
183
+ for (let i = start; i < end; i += stepVal) {
184
+ yield i;
185
+ }
186
+ } else {
187
+ for (let i = start; i > end; i += stepVal) {
188
+ yield i;
189
+ }
190
+ }
191
+ }
192
+ };
193
+ }
194
+ function enumerate(iterable, start = 0) {
195
+ return {
196
+ *[Symbol.iterator]() {
197
+ let index = start;
198
+ for (const item of iterable) {
199
+ yield [index++, item];
200
+ }
201
+ }
202
+ };
203
+ }
204
+ function zip(...iterables) {
205
+ return {
206
+ *[Symbol.iterator]() {
207
+ const iterators = iterables.map((it) => it[Symbol.iterator]());
208
+ for (; ; ) {
209
+ const results = iterators.map((it) => it.next());
210
+ if (results.some((r) => r.done)) {
211
+ break;
212
+ }
213
+ yield results.map((r) => r.value);
214
+ }
215
+ }
216
+ };
217
+ }
218
+ function iter(obj) {
219
+ if (obj === null || obj === void 0) {
220
+ return [];
221
+ }
222
+ if (typeof obj[Symbol.iterator] === "function") {
223
+ return obj;
224
+ }
225
+ if (typeof obj === "object") {
226
+ return Object.keys(obj);
227
+ }
228
+ return [];
229
+ }
230
+ function reversed(iterable) {
231
+ const arr = Array.isArray(iterable) ? iterable : Array.from(iterable);
232
+ return arr.toReversed();
233
+ }
234
+ function sorted(iterable, options) {
235
+ const key = options?.key ?? ((x) => x);
236
+ const reverse = options?.reverse ?? false;
237
+ const arr = Array.isArray(iterable) ? iterable : Array.from(iterable);
238
+ return arr.toSorted((a, b) => {
239
+ const aKey = key(a);
240
+ const bKey = key(b);
241
+ let cmp;
242
+ if (typeof aKey === "string" && typeof bKey === "string") {
243
+ cmp = aKey.localeCompare(bKey);
244
+ } else {
245
+ cmp = aKey - bKey;
246
+ }
247
+ return reverse ? -cmp : cmp;
248
+ });
249
+ }
250
+ function getIterator(iterable) {
251
+ return iterable[Symbol.iterator]();
252
+ }
253
+ function map(fn, iterable) {
254
+ return getIterator(iterable).map(fn);
255
+ }
256
+ function filter(fn, iterable) {
257
+ const predicate = fn ?? ((x) => bool(x));
258
+ return getIterator(iterable).filter(predicate);
259
+ }
260
+ function list(iterable) {
261
+ if (iterable === void 0) {
262
+ return [];
263
+ }
264
+ return Array.from(iterable);
265
+ }
266
+ function dict(entries) {
267
+ return new Map(entries);
268
+ }
269
+ function set(iterable) {
270
+ return new Set(iterable);
271
+ }
272
+ function tuple(...items) {
273
+ return Object.freeze([...items]);
274
+ }
275
+ function len(obj) {
276
+ if (typeof obj === "string" || Array.isArray(obj)) {
277
+ return obj.length;
278
+ }
279
+ if (obj instanceof Map || obj instanceof Set) {
280
+ return obj.size;
281
+ }
282
+ if (typeof obj === "object" && obj !== null && "length" in obj) {
283
+ return obj.length;
284
+ }
285
+ throw new TypeError("object has no len()");
286
+ }
287
+ function abs(x) {
288
+ return Math.abs(x);
289
+ }
290
+ function min(...args) {
291
+ const first = args[0];
292
+ if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
293
+ const arr = [...first];
294
+ if (arr.length === 0) {
295
+ throw new Error("min() arg is an empty sequence");
296
+ }
297
+ return arr.reduce((a, b) => a < b ? a : b);
298
+ }
299
+ if (args.length === 0) {
300
+ throw new Error("min expected at least 1 argument, got 0");
301
+ }
302
+ return args.reduce((a, b) => a < b ? a : b);
303
+ }
304
+ function max(...args) {
305
+ const first = args[0];
306
+ if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
307
+ const arr = [...first];
308
+ if (arr.length === 0) {
309
+ throw new Error("max() arg is an empty sequence");
310
+ }
311
+ return arr.reduce((a, b) => a > b ? a : b);
312
+ }
313
+ if (args.length === 0) {
314
+ throw new Error("max expected at least 1 argument, got 0");
315
+ }
316
+ return args.reduce((a, b) => a > b ? a : b);
317
+ }
318
+ function sum(iterable, start = 0) {
319
+ let total = start;
320
+ for (const item of iterable) {
321
+ total += item;
322
+ }
323
+ return total;
324
+ }
325
+ function all(iterable) {
326
+ for (const item of iterable) {
327
+ if (!bool(item)) return false;
328
+ }
329
+ return true;
330
+ }
331
+ function any(iterable) {
332
+ for (const item of iterable) {
333
+ if (bool(item)) return true;
334
+ }
335
+ return false;
336
+ }
337
+ function round(number, ndigits) {
338
+ if (ndigits === void 0 || ndigits === 0) {
339
+ const rounded = Math.round(number);
340
+ if (Math.abs(number % 1) === 0.5) {
341
+ return rounded % 2 === 0 ? rounded : rounded - Math.sign(number);
342
+ }
343
+ return rounded;
344
+ }
345
+ const factor = Math.pow(10, ndigits);
346
+ return Math.round(number * factor) / factor;
347
+ }
348
+ function ord(char) {
349
+ if (char.length !== 1) {
350
+ throw new Error("ord() expected a character");
351
+ }
352
+ return char.charCodeAt(0);
353
+ }
354
+ function chr(code) {
355
+ return String.fromCharCode(code);
356
+ }
357
+ function hex(x) {
358
+ const prefix = x < 0 ? "-0x" : "0x";
359
+ return prefix + Math.abs(Math.trunc(x)).toString(16);
360
+ }
361
+ function oct(x) {
362
+ const prefix = x < 0 ? "-0o" : "0o";
363
+ return prefix + Math.abs(Math.trunc(x)).toString(8);
364
+ }
365
+ function bin(x) {
366
+ const prefix = x < 0 ? "-0b" : "0b";
367
+ return prefix + Math.abs(Math.trunc(x)).toString(2);
368
+ }
369
+ function int(x, base) {
370
+ if (typeof x === "boolean") {
371
+ return x ? 1 : 0;
372
+ }
373
+ if (typeof x === "number") {
374
+ return Math.trunc(x);
375
+ }
376
+ const parsed = base !== void 0 ? parseInt(x, base) : parseInt(x, 10);
377
+ if (isNaN(parsed)) {
378
+ throw new Error(`invalid literal for int(): '${x}'`);
379
+ }
380
+ return parsed;
381
+ }
382
+ function float(x) {
383
+ if (typeof x === "number") {
384
+ return x;
385
+ }
386
+ const parsed = parseFloat(x);
387
+ if (isNaN(parsed)) {
388
+ throw new Error(`could not convert string to float: '${x}'`);
389
+ }
390
+ return parsed;
391
+ }
392
+ function str(x) {
393
+ if (x === null) {
394
+ return "None";
395
+ }
396
+ if (x === void 0) {
397
+ return "None";
398
+ }
399
+ if (typeof x === "boolean") {
400
+ return x ? "True" : "False";
401
+ }
402
+ if (Array.isArray(x)) {
403
+ return "[" + x.map((item) => repr(item)).join(", ") + "]";
404
+ }
405
+ if (x instanceof Map) {
406
+ const entries = Array.from(x.entries()).map(([k, v]) => `${repr(k)}: ${repr(v)}`).join(", ");
407
+ return "{" + entries + "}";
408
+ }
409
+ if (x instanceof Set) {
410
+ if (x.size === 0) {
411
+ return "set()";
412
+ }
413
+ return "{" + Array.from(x).map((item) => repr(item)).join(", ") + "}";
414
+ }
415
+ return String(x);
416
+ }
417
+ function repr(x) {
418
+ if (typeof x === "string") {
419
+ return `'${x}'`;
420
+ }
421
+ return str(x);
422
+ }
423
+ function bool(x) {
424
+ if (x === null || x === void 0) {
425
+ return false;
426
+ }
427
+ if (typeof x === "boolean") {
428
+ return x;
429
+ }
430
+ if (typeof x === "number") {
431
+ return x !== 0;
432
+ }
433
+ if (typeof x === "string") {
434
+ return x.length > 0;
435
+ }
436
+ if (Array.isArray(x)) {
437
+ return x.length > 0;
438
+ }
439
+ if (x instanceof Map || x instanceof Set) {
440
+ return x.size > 0;
441
+ }
442
+ return true;
443
+ }
444
+ function ascii(x) {
445
+ const s = repr(x);
446
+ let result = "";
447
+ for (const char of s) {
448
+ const code = char.charCodeAt(0);
449
+ if (code > 127) {
450
+ if (code > 65535) {
451
+ result += `\\U${code.toString(16).padStart(8, "0")}`;
452
+ } else {
453
+ result += `\\u${code.toString(16).padStart(4, "0")}`;
454
+ }
455
+ } else {
456
+ result += char;
457
+ }
458
+ }
459
+ return result;
460
+ }
461
+ function isinstance(obj, classInfo) {
462
+ if (classInfo === Number || classInfo === "int" || classInfo === "float") {
463
+ return typeof obj === "number";
464
+ }
465
+ if (classInfo === String || classInfo === "str") {
466
+ return typeof obj === "string";
467
+ }
468
+ if (classInfo === Boolean || classInfo === "bool") {
469
+ return typeof obj === "boolean";
470
+ }
471
+ if (classInfo === Array || classInfo === "list") {
472
+ return Array.isArray(obj);
473
+ }
474
+ if (classInfo === Map || classInfo === "dict") {
475
+ return obj instanceof Map;
476
+ }
477
+ if (classInfo === Set || classInfo === "set") {
478
+ return obj instanceof Set;
479
+ }
480
+ if (typeof classInfo === "function") {
481
+ return obj instanceof classInfo;
482
+ }
483
+ return false;
484
+ }
485
+ function type(obj) {
486
+ if (obj === null) return "NoneType";
487
+ if (typeof obj === "number") {
488
+ return Number.isInteger(obj) ? "int" : "float";
489
+ }
490
+ if (typeof obj === "string") return "str";
491
+ if (typeof obj === "boolean") return "bool";
492
+ if (Array.isArray(obj)) return "list";
493
+ if (obj instanceof Map) return "dict";
494
+ if (obj instanceof Set) return "set";
495
+ return typeof obj;
496
+ }
497
+ function input(prompt) {
498
+ if (prompt) {
499
+ process.stdout.write(prompt);
500
+ }
501
+ throw new Error("input() requires async implementation");
502
+ }
503
+ function formatNumber(num, sign, _hash, grouping, precision, isInteger = true) {
504
+ let result;
505
+ if (isInteger) {
506
+ result = Math.trunc(num).toString();
507
+ } else {
508
+ result = num.toFixed(precision ?? 6);
509
+ }
510
+ if (grouping) {
511
+ const sep = grouping === "_" ? "_" : ",";
512
+ const parts = result.split(".");
513
+ const [intPart = ""] = parts;
514
+ const signChar = intPart.startsWith("-") ? "-" : "";
515
+ const digits = signChar ? intPart.slice(1) : intPart;
516
+ const grouped = digits.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
517
+ parts[0] = signChar + grouped;
518
+ result = parts.join(".");
519
+ }
520
+ if (num >= 0) {
521
+ if (sign === "+") {
522
+ result = "+" + result;
523
+ } else if (sign === " ") {
524
+ result = " " + result;
525
+ }
526
+ }
527
+ return result;
528
+ }
529
+ function format(value, spec) {
530
+ if (spec === "") {
531
+ return str(value);
532
+ }
533
+ const match = /^(.?[<>=^])?([+\- ])?([#])?(0)?(\d+)?([,_])?(?:\.(\d+))?([bcdeEfFgGnosxX%])?$/.exec(spec);
534
+ if (!match) {
535
+ return str(value);
536
+ }
537
+ const [, alignPart, sign, hash, zero, widthStr, grouping, precisionStr, typeChar] = match;
538
+ let fill = " ";
539
+ let align = "";
540
+ if (alignPart) {
541
+ if (alignPart.length === 2) {
542
+ fill = alignPart.charAt(0);
543
+ align = alignPart.charAt(1);
544
+ } else {
545
+ align = alignPart;
546
+ }
547
+ }
548
+ const width = widthStr ? parseInt(widthStr, 10) : 0;
549
+ const precision = precisionStr !== void 0 ? parseInt(precisionStr, 10) : void 0;
550
+ if (zero && !alignPart) {
551
+ fill = "0";
552
+ align = "=";
553
+ }
554
+ let result;
555
+ if (typeChar === "s" || !typeChar && typeof value === "string") {
556
+ result = str(value);
557
+ if (precision !== void 0) {
558
+ result = result.slice(0, precision);
559
+ }
560
+ } else if (typeChar === "d" || !typeChar && typeof value === "number" && Number.isInteger(value)) {
561
+ const num = typeof value === "number" ? value : int(value);
562
+ result = formatNumber(num, sign, "", grouping);
563
+ } else if (typeChar === "f" || typeChar === "F") {
564
+ const num = typeof value === "number" ? value : float(value);
565
+ const prec = precision ?? 6;
566
+ result = formatNumber(num, sign, "", grouping, prec, false);
567
+ if (typeChar === "F") result = result.toUpperCase();
568
+ } else if (typeChar === "e" || typeChar === "E") {
569
+ const num = typeof value === "number" ? value : float(value);
570
+ const prec = precision ?? 6;
571
+ result = num.toExponential(prec);
572
+ if (sign === "+" && num >= 0) result = "+" + result;
573
+ else if (sign === " " && num >= 0) result = " " + result;
574
+ if (typeChar === "E") result = result.toUpperCase();
575
+ } else if (typeChar === "g" || typeChar === "G") {
576
+ const num = typeof value === "number" ? value : float(value);
577
+ const prec = precision ?? 6;
578
+ result = num.toPrecision(prec);
579
+ if (sign === "+" && num >= 0) result = "+" + result;
580
+ else if (sign === " " && num >= 0) result = " " + result;
581
+ if (typeChar === "G") result = result.toUpperCase();
582
+ } else if (typeChar === "x" || typeChar === "X") {
583
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
584
+ result = Math.abs(num).toString(16);
585
+ if (hash) result = "0x" + result;
586
+ if (num < 0) result = "-" + result;
587
+ else if (sign === "+") result = "+" + result;
588
+ else if (sign === " ") result = " " + result;
589
+ if (typeChar === "X") result = result.toUpperCase();
590
+ } else if (typeChar === "o") {
591
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
592
+ result = Math.abs(num).toString(8);
593
+ if (hash) result = "0o" + result;
594
+ if (num < 0) result = "-" + result;
595
+ else if (sign === "+") result = "+" + result;
596
+ else if (sign === " ") result = " " + result;
597
+ } else if (typeChar === "b") {
598
+ const num = typeof value === "number" ? Math.trunc(value) : int(value);
599
+ result = Math.abs(num).toString(2);
600
+ if (hash) result = "0b" + result;
601
+ if (num < 0) result = "-" + result;
602
+ else if (sign === "+") result = "+" + result;
603
+ else if (sign === " ") result = " " + result;
604
+ } else if (typeChar === "c") {
605
+ const code = typeof value === "number" ? value : int(value);
606
+ result = String.fromCharCode(code);
607
+ } else if (typeChar === "%") {
608
+ const num = typeof value === "number" ? value : float(value);
609
+ const prec = precision ?? 6;
610
+ result = (num * 100).toFixed(prec) + "%";
611
+ if (sign === "+" && num >= 0) result = "+" + result;
612
+ else if (sign === " " && num >= 0) result = " " + result;
613
+ } else if (typeChar === "n") {
614
+ const num = typeof value === "number" ? value : float(value);
615
+ result = num.toLocaleString();
616
+ } else {
617
+ result = str(value);
618
+ }
619
+ if (width > result.length) {
620
+ const padding = fill.repeat(width - result.length);
621
+ if (align === "<") {
622
+ result = result + padding;
623
+ } else if (align === ">" || align === "") {
624
+ result = padding + result;
625
+ } else if (align === "^") {
626
+ const leftPad = Math.floor((width - result.length) / 2);
627
+ const rightPad = width - result.length - leftPad;
628
+ result = fill.repeat(leftPad) + result + fill.repeat(rightPad);
629
+ } else if (align === "=") {
630
+ const signMatch = /^([+\- ]|0[xXoObB])?(.*)$/.exec(result);
631
+ if (signMatch) {
632
+ const signPart = signMatch[1] ?? "";
633
+ const numPart = signMatch[2] ?? "";
634
+ result = signPart + padding + numPart;
635
+ }
636
+ }
637
+ }
638
+ return result;
639
+ }
640
+ function getattr(obj, name, defaultValue) {
641
+ if (obj === null || obj === void 0) {
642
+ if (arguments.length >= 3) {
643
+ return defaultValue;
644
+ }
645
+ throw new TypeError(
646
+ `'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
647
+ );
648
+ }
649
+ const target = obj;
650
+ if (name in target) {
651
+ return target[name];
652
+ }
653
+ if (arguments.length >= 3) {
654
+ return defaultValue;
655
+ }
656
+ throw new TypeError(`'${typeof obj}' object has no attribute '${name}'`);
657
+ }
658
+ function hasattr(obj, name) {
659
+ if (obj === null || obj === void 0) {
660
+ return false;
661
+ }
662
+ return name in obj;
663
+ }
664
+ function setattr(obj, name, value) {
665
+ if (obj === null || obj === void 0) {
666
+ throw new TypeError(
667
+ `'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
668
+ );
669
+ }
670
+ ;
671
+ obj[name] = value;
672
+ }
673
+
674
+ // src/list.ts
675
+ var list2 = {
676
+ /**
677
+ * Python list.append() - modifies array in place
678
+ */
679
+ append(arr, item) {
680
+ arr.push(item);
681
+ },
682
+ /**
683
+ * Python list.extend() - modifies array in place
684
+ */
685
+ extend(arr, items) {
686
+ arr.push(...items);
687
+ },
688
+ /**
689
+ * Python list.insert() - modifies array in place
690
+ */
691
+ insert(arr, index, item) {
692
+ arr.splice(index, 0, item);
693
+ },
694
+ /**
695
+ * Python list.remove() - removes first occurrence, modifies in place
696
+ */
697
+ remove(arr, value) {
698
+ const index = arr.indexOf(value);
699
+ if (index === -1) {
700
+ throw new Error("list.remove(x): x not in list");
701
+ }
702
+ arr.splice(index, 1);
703
+ },
704
+ /**
705
+ * Python list.pop() - removes and returns item at index
706
+ */
707
+ pop(arr, index) {
708
+ if (arr.length === 0) {
709
+ throw new Error("pop from empty list");
710
+ }
711
+ const i = index ?? arr.length - 1;
712
+ const normalizedIndex = i < 0 ? arr.length + i : i;
713
+ if (normalizedIndex < 0 || normalizedIndex >= arr.length) {
714
+ throw new Error("pop index out of range");
715
+ }
716
+ return arr.splice(normalizedIndex, 1)[0];
717
+ },
718
+ /**
719
+ * Python list.clear() - removes all items
720
+ */
721
+ clear(arr) {
722
+ arr.length = 0;
723
+ },
724
+ /**
725
+ * Python list.index() - finds first occurrence
726
+ */
727
+ index(arr, value, start, end) {
728
+ const searchStart = start ?? 0;
729
+ const searchEnd = end ?? arr.length;
730
+ for (let i = searchStart; i < searchEnd; i++) {
731
+ if (arr[i] === value) {
732
+ return i;
733
+ }
734
+ }
735
+ throw new Error("x not in list");
736
+ },
737
+ /**
738
+ * Python list.count() - counts occurrences
739
+ */
740
+ count(arr, value) {
741
+ let count = 0;
742
+ for (const item of arr) {
743
+ if (item === value) count++;
744
+ }
745
+ return count;
746
+ },
747
+ /**
748
+ * Python list.sort() with key function - modifies in place
749
+ */
750
+ sort(arr, options) {
751
+ const key = options?.key ?? ((x) => x);
752
+ const reverse = options?.reverse ?? false;
753
+ arr.sort((a, b) => {
754
+ const aKey = key(a);
755
+ const bKey = key(b);
756
+ let cmp = 0;
757
+ if (aKey < bKey) cmp = -1;
758
+ else if (aKey > bKey) cmp = 1;
759
+ return reverse ? -cmp : cmp;
760
+ });
761
+ },
762
+ /**
763
+ * Python list.reverse() - reverses in place
764
+ */
765
+ reverse(arr) {
766
+ arr.reverse();
767
+ },
768
+ /**
769
+ * Python list.copy() - shallow copy
770
+ */
771
+ copy(arr) {
772
+ return [...arr];
773
+ },
774
+ /**
775
+ * Python slice assignment: arr[start:end:step] = values
776
+ * Replaces a slice of the array with new values, modifying in place
777
+ */
778
+ sliceAssign(arr, start, end, step, values) {
779
+ const len2 = arr.length;
780
+ const actualStep = step ?? 1;
781
+ let actualStart = start ?? (actualStep > 0 ? 0 : len2 - 1);
782
+ let actualEnd = end ?? (actualStep > 0 ? len2 : -len2 - 1);
783
+ if (actualStart < 0) actualStart = Math.max(0, len2 + actualStart);
784
+ if (actualEnd < 0) actualEnd = Math.max(0, len2 + actualEnd);
785
+ actualStart = Math.min(actualStart, len2);
786
+ actualEnd = Math.min(actualEnd, len2);
787
+ if (actualStep === 1) {
788
+ const deleteCount = Math.max(0, actualEnd - actualStart);
789
+ arr.splice(actualStart, deleteCount, ...values);
790
+ } else {
791
+ const indices = [];
792
+ if (actualStep > 0) {
793
+ for (let i = actualStart; i < actualEnd; i += actualStep) {
794
+ indices.push(i);
795
+ }
796
+ } else {
797
+ for (let i = actualStart; i > actualEnd; i += actualStep) {
798
+ indices.push(i);
799
+ }
800
+ }
801
+ if (indices.length !== values.length) {
802
+ throw new Error(
803
+ `attempt to assign sequence of size ${String(values.length)} to extended slice of size ${String(indices.length)}`
804
+ );
805
+ }
806
+ for (let i = 0; i < indices.length; i++) {
807
+ const idx = indices[i];
808
+ if (idx !== void 0) {
809
+ arr[idx] = values[i];
810
+ }
811
+ }
812
+ }
813
+ }
814
+ };
815
+
816
+ // src/dict.ts
817
+ var dict2 = {
818
+ /**
819
+ * Python dict.get() - get value with optional default
820
+ */
821
+ get(obj, key, defaultValue) {
822
+ return key in obj ? obj[key] : defaultValue;
823
+ },
824
+ /**
825
+ * Python dict.setDefault() - get value or set default
826
+ */
827
+ setDefault(obj, key, defaultValue) {
828
+ if (!(key in obj)) {
829
+ obj[key] = defaultValue;
830
+ }
831
+ return obj[key];
832
+ },
833
+ /**
834
+ * Python dict.pop() - remove and return value
835
+ */
836
+ pop(obj, key, defaultValue) {
837
+ if (key in obj) {
838
+ const value = obj[key];
839
+ delete obj[key];
840
+ return value;
841
+ }
842
+ if (defaultValue !== void 0) {
843
+ return defaultValue;
844
+ }
845
+ throw new Error("KeyError");
846
+ },
847
+ /**
848
+ * Python dict.popItem() - remove and return last item
849
+ */
850
+ popItem(obj) {
851
+ const keys = Object.keys(obj);
852
+ const key = keys.pop();
853
+ if (key === void 0) {
854
+ throw new Error("dictionary is empty");
855
+ }
856
+ const value = obj[key];
857
+ delete obj[key];
858
+ return [key, value];
859
+ },
860
+ /**
861
+ * Python dict.update() - update with another dict
862
+ */
863
+ update(obj, other) {
864
+ if (Symbol.iterator in other) {
865
+ for (const [k, v] of other) {
866
+ obj[k] = v;
867
+ }
868
+ } else {
869
+ Object.assign(obj, other);
870
+ }
871
+ },
872
+ /**
873
+ * Python dict.clear() - remove all items
874
+ */
875
+ clear(obj) {
876
+ for (const key of Object.keys(obj)) {
877
+ delete obj[key];
878
+ }
879
+ },
880
+ /**
881
+ * Python dict.copy() - shallow copy
882
+ */
883
+ copy(obj) {
884
+ return { ...obj };
885
+ },
886
+ /**
887
+ * Python dict.keys() - returns iterable of keys
888
+ */
889
+ keys(obj) {
890
+ return Object.keys(obj);
891
+ },
892
+ /**
893
+ * Python dict.values() - returns iterable of values
894
+ */
895
+ values(obj) {
896
+ return Object.values(obj);
897
+ },
898
+ /**
899
+ * Python dict.items() - returns iterable of [key, value] pairs
900
+ */
901
+ items(obj) {
902
+ return Object.entries(obj);
903
+ },
904
+ /**
905
+ * Python dict.fromKeys() - create dict from keys
906
+ */
907
+ fromKeys(keys, value) {
908
+ const result = {};
909
+ for (const key of keys) {
910
+ result[key] = value;
911
+ }
912
+ return result;
913
+ }
914
+ };
915
+
916
+ // src/set.ts
917
+ var set2 = {
918
+ /**
919
+ * Python set.add() - add element
920
+ */
921
+ add(s, item) {
922
+ s.add(item);
923
+ },
924
+ /**
925
+ * Python set.remove() - remove element, raises error if not found
926
+ */
927
+ remove(s, item) {
928
+ if (!s.has(item)) {
929
+ throw new Error("KeyError");
930
+ }
931
+ s.delete(item);
932
+ },
933
+ /**
934
+ * Python set.discard() - remove element if present
935
+ */
936
+ discard(s, item) {
937
+ s.delete(item);
938
+ },
939
+ /**
940
+ * Python set.pop() - remove and return arbitrary element
941
+ */
942
+ pop(s) {
943
+ if (s.size === 0) {
944
+ throw new Error("pop from an empty set");
945
+ }
946
+ const item = s.values().next().value;
947
+ s.delete(item);
948
+ return item;
949
+ },
950
+ /**
951
+ * Python set.clear() - remove all elements
952
+ */
953
+ clear(s) {
954
+ s.clear();
955
+ },
956
+ /**
957
+ * Python set.copy() - shallow copy
958
+ */
959
+ copy(s) {
960
+ return new Set(s);
961
+ },
962
+ /**
963
+ * Python set.update() - add elements from iterable
964
+ */
965
+ update(s, ...iterables) {
966
+ for (const iterable of iterables) {
967
+ for (const item of iterable) {
968
+ s.add(item);
969
+ }
970
+ }
971
+ },
972
+ /**
973
+ * Python set.union() - returns new set with all elements
974
+ * Uses ES2024 Set.prototype.union()
975
+ */
976
+ union(a, ...others) {
977
+ let result = new Set(a);
978
+ for (const other of others) {
979
+ result = result.union(other instanceof Set ? other : new Set(other));
980
+ }
981
+ return result;
982
+ },
983
+ /**
984
+ * Python set.intersection() - returns new set with common elements
985
+ * Uses ES2024 Set.prototype.intersection()
986
+ */
987
+ intersection(a, b) {
988
+ return a.intersection(b);
989
+ },
990
+ /**
991
+ * Python set.intersection_update() - keep only common elements
992
+ */
993
+ intersectionUpdate(a, b) {
994
+ for (const item of a) {
995
+ if (!b.has(item)) a.delete(item);
996
+ }
997
+ },
998
+ /**
999
+ * Python set.difference() - returns new set with elements in a but not in b
1000
+ * Uses ES2024 Set.prototype.difference()
1001
+ */
1002
+ difference(a, b) {
1003
+ return a.difference(b);
1004
+ },
1005
+ /**
1006
+ * Python set.difference_update() - remove elements found in b
1007
+ */
1008
+ differenceUpdate(a, b) {
1009
+ for (const item of b) {
1010
+ a.delete(item);
1011
+ }
1012
+ },
1013
+ /**
1014
+ * Python set.symmetric_difference() - returns new set with elements in either but not both
1015
+ * Uses ES2024 Set.prototype.symmetricDifference()
1016
+ */
1017
+ symmetricDifference(a, b) {
1018
+ return a.symmetricDifference(b);
1019
+ },
1020
+ /**
1021
+ * Python set.symmetric_difference_update() - update with symmetric difference
1022
+ * Uses ES2024 Set.prototype.symmetricDifference()
1023
+ */
1024
+ symmetricDifferenceUpdate(a, b) {
1025
+ const result = a.symmetricDifference(b);
1026
+ a.clear();
1027
+ for (const item of result) a.add(item);
1028
+ },
1029
+ /**
1030
+ * Python set.isSubset() - test if all elements are in other
1031
+ * Uses ES2024 Set.prototype.isSubsetOf()
1032
+ */
1033
+ isSubset(a, b) {
1034
+ return a.isSubsetOf(b);
1035
+ },
1036
+ /**
1037
+ * Python set.isSuperset() - test if all other elements are in this set
1038
+ * Uses ES2024 Set.prototype.isSupersetOf()
1039
+ */
1040
+ isSuperset(a, b) {
1041
+ return a.isSupersetOf(b);
1042
+ },
1043
+ /**
1044
+ * Python set.isDisjoint() - test if no common elements
1045
+ * Uses ES2024 Set.prototype.isDisjointFrom()
1046
+ */
1047
+ isDisjoint(a, b) {
1048
+ return a.isDisjointFrom(b);
1049
+ }
1050
+ };
1051
+
1052
+ export {
1053
+ floorDiv,
1054
+ pow,
1055
+ mod,
1056
+ divMod,
1057
+ sprintf,
1058
+ strFormat,
1059
+ slice,
1060
+ at,
1061
+ repeat,
1062
+ contains,
1063
+ is,
1064
+ range,
1065
+ enumerate,
1066
+ zip,
1067
+ iter,
1068
+ reversed,
1069
+ sorted,
1070
+ map,
1071
+ filter,
1072
+ list,
1073
+ dict,
1074
+ set,
1075
+ tuple,
1076
+ len,
1077
+ abs,
1078
+ min,
1079
+ max,
1080
+ sum,
1081
+ all,
1082
+ any,
1083
+ round,
1084
+ ord,
1085
+ chr,
1086
+ hex,
1087
+ oct,
1088
+ bin,
1089
+ int,
1090
+ float,
1091
+ str,
1092
+ repr,
1093
+ bool,
1094
+ ascii,
1095
+ isinstance,
1096
+ type,
1097
+ input,
1098
+ format,
1099
+ getattr,
1100
+ hasattr,
1101
+ setattr,
1102
+ list2,
1103
+ dict2,
1104
+ set2
1105
+ };
1106
+ /* v8 ignore next -- fallback for unrecognized format types @preserve */