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