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
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Python operations for TypeScript
|
|
3
|
+
* Arithmetic operations with Python semantics, slicing, etc.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Floor division (Python //)
|
|
7
|
+
* Always rounds towards negative infinity, unlike Math.floor for negatives
|
|
8
|
+
*/
|
|
9
|
+
declare function floorDiv(a: number, b: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Power operator (Python **)
|
|
12
|
+
*/
|
|
13
|
+
declare function pow(base: number, exp: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Modulo (Python %)
|
|
16
|
+
* Python's % always returns a result with the same sign as the divisor
|
|
17
|
+
*/
|
|
18
|
+
declare function mod(a: number, b: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Python divMod()
|
|
21
|
+
*/
|
|
22
|
+
declare function divMod(a: number, b: number): [number, number];
|
|
23
|
+
/**
|
|
24
|
+
* Python %-style string formatting
|
|
25
|
+
* Handles %s, %d, %i, %f, %r, %x, %o, etc.
|
|
26
|
+
*/
|
|
27
|
+
declare function sprintf(template: string, args: unknown): string;
|
|
28
|
+
/**
|
|
29
|
+
* Python str.format() style string formatting
|
|
30
|
+
* Handles {} positional and {name} named placeholders
|
|
31
|
+
*/
|
|
32
|
+
declare function strFormat(template: string, ...args: unknown[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Python-style slice operation
|
|
35
|
+
* Supports negative indices and step
|
|
36
|
+
*/
|
|
37
|
+
declare function slice<T>(obj: string | T[], start?: number, stop?: number, step?: number): string | T[];
|
|
38
|
+
/**
|
|
39
|
+
* Python-style index access with support for negative indices
|
|
40
|
+
*/
|
|
41
|
+
declare function at<T>(obj: string | T[], index: number): T | string;
|
|
42
|
+
/**
|
|
43
|
+
* Python-style string/array repetition
|
|
44
|
+
*/
|
|
45
|
+
declare function repeat<T>(obj: string | T[], count: number): string | T[];
|
|
46
|
+
/**
|
|
47
|
+
* Python 'in' operator
|
|
48
|
+
*/
|
|
49
|
+
declare function contains<T>(item: T, container: Iterable<T> | string | Map<T, unknown> | Set<T>): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Python 'is' operator (identity comparison)
|
|
52
|
+
*/
|
|
53
|
+
declare function is(a: unknown, b: unknown): boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Python built-in functions for TypeScript
|
|
57
|
+
*
|
|
58
|
+
* Provides core Python built-in functions like len, range, enumerate, sorted, min, max, etc.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://docs.python.org/3/library/functions.html | Python built-in functions documentation}
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Return a sequence of numbers from start to stop (exclusive) by step.
|
|
64
|
+
*
|
|
65
|
+
* @param startOrStop - If only one argument, this is stop (start defaults to 0). Otherwise, this is start.
|
|
66
|
+
* @param stop - The end value (exclusive)
|
|
67
|
+
* @param step - The increment (default: 1)
|
|
68
|
+
* @returns An iterable of numbers
|
|
69
|
+
* @see {@link https://docs.python.org/3/library/functions.html#func-range | Python range()}
|
|
70
|
+
*/
|
|
71
|
+
declare function range(startOrStop: number, stop?: number, step?: number): Iterable<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Return an iterable of tuples containing (index, value) pairs.
|
|
74
|
+
*
|
|
75
|
+
* @param iterable - The sequence to enumerate
|
|
76
|
+
* @param start - The starting index (default: 0)
|
|
77
|
+
* @returns An iterable of [index, value] tuples
|
|
78
|
+
* @see {@link https://docs.python.org/3/library/functions.html#enumerate | Python enumerate()}
|
|
79
|
+
*/
|
|
80
|
+
declare function enumerate<T>(iterable: Iterable<T>, start?: number): Iterable<[number, T]>;
|
|
81
|
+
/**
|
|
82
|
+
* Iterate over multiple iterables in parallel, yielding tuples.
|
|
83
|
+
*
|
|
84
|
+
* Stops when the shortest iterable is exhausted.
|
|
85
|
+
*
|
|
86
|
+
* @param iterables - The iterables to zip together
|
|
87
|
+
* @returns An iterable of tuples containing elements from each input
|
|
88
|
+
* @see {@link https://docs.python.org/3/library/functions.html#zip | Python zip()}
|
|
89
|
+
*/
|
|
90
|
+
declare function zip<T extends unknown[][]>(...iterables: {
|
|
91
|
+
[K in keyof T]: Iterable<T[K]>;
|
|
92
|
+
}): Iterable<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Return an iterator object for the given iterable.
|
|
95
|
+
*
|
|
96
|
+
* For objects without Symbol.iterator, returns the object's keys.
|
|
97
|
+
*
|
|
98
|
+
* @param obj - The object to iterate over
|
|
99
|
+
* @returns An iterable
|
|
100
|
+
* @see {@link https://docs.python.org/3/library/functions.html#iter | Python iter()}
|
|
101
|
+
*/
|
|
102
|
+
declare function iter<T>(obj: Iterable<T> | Record<string, unknown> | null | undefined): Iterable<T> | string[];
|
|
103
|
+
/**
|
|
104
|
+
* Return a reversed iterator over the values of the given sequence.
|
|
105
|
+
*
|
|
106
|
+
* Uses ES2023 Array.prototype.toReversed() for immutable reversal.
|
|
107
|
+
*
|
|
108
|
+
* @param iterable - The sequence to reverse
|
|
109
|
+
* @returns An iterable yielding elements in reverse order
|
|
110
|
+
* @see {@link https://docs.python.org/3/library/functions.html#reversed | Python reversed()}
|
|
111
|
+
*/
|
|
112
|
+
declare function reversed<T>(iterable: Iterable<T>): Iterable<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Return a new sorted list from the items in the iterable.
|
|
115
|
+
*
|
|
116
|
+
* Uses ES2023 Array.prototype.toSorted() for immutable sorting.
|
|
117
|
+
*
|
|
118
|
+
* @param iterable - The sequence to sort
|
|
119
|
+
* @param options - Sorting options: key function and/or reverse flag
|
|
120
|
+
* @returns A new sorted array
|
|
121
|
+
* @see {@link https://docs.python.org/3/library/functions.html#sorted | Python sorted()}
|
|
122
|
+
*/
|
|
123
|
+
declare function sorted<T>(iterable: Iterable<T>, options?: {
|
|
124
|
+
key?: (x: T) => unknown;
|
|
125
|
+
reverse?: boolean;
|
|
126
|
+
}): T[];
|
|
127
|
+
/**
|
|
128
|
+
* Apply a function to every item of the iterable and yield the results.
|
|
129
|
+
*
|
|
130
|
+
* Uses ES2024 Iterator.prototype.map() for lazy evaluation.
|
|
131
|
+
*
|
|
132
|
+
* @param fn - The function to apply to each element
|
|
133
|
+
* @param iterable - The input iterable
|
|
134
|
+
* @returns An iterable of transformed values
|
|
135
|
+
* @see {@link https://docs.python.org/3/library/functions.html#map | Python map()}
|
|
136
|
+
*/
|
|
137
|
+
declare function map<T, U>(fn: (x: T) => U, iterable: Iterable<T>): Iterable<U>;
|
|
138
|
+
/**
|
|
139
|
+
* Return an iterable yielding items where the function returns true.
|
|
140
|
+
*
|
|
141
|
+
* If function is null, return items that are truthy.
|
|
142
|
+
* Uses ES2024 Iterator.prototype.filter() for lazy evaluation.
|
|
143
|
+
*
|
|
144
|
+
* @param fn - The predicate function (or null for truthiness check)
|
|
145
|
+
* @param iterable - The input iterable
|
|
146
|
+
* @returns An iterable of filtered values
|
|
147
|
+
* @see {@link https://docs.python.org/3/library/functions.html#filter | Python filter()}
|
|
148
|
+
*/
|
|
149
|
+
declare function filter<T>(fn: ((x: T) => boolean) | null, iterable: Iterable<T>): Iterable<T>;
|
|
150
|
+
/**
|
|
151
|
+
* Create an immutable tuple (frozen array).
|
|
152
|
+
*
|
|
153
|
+
* @param items - The elements to include in the tuple
|
|
154
|
+
* @returns A frozen (readonly) array
|
|
155
|
+
* @see {@link https://docs.python.org/3/library/functions.html#func-tuple | Python tuple()}
|
|
156
|
+
*/
|
|
157
|
+
declare function tuple<T extends unknown[]>(...items: T): Readonly<T>;
|
|
158
|
+
/**
|
|
159
|
+
* Return the number of items in an object.
|
|
160
|
+
*
|
|
161
|
+
* Works with strings, arrays, Maps, Sets, and objects with a length property.
|
|
162
|
+
*
|
|
163
|
+
* @param obj - The object to measure
|
|
164
|
+
* @returns The number of items
|
|
165
|
+
* @see {@link https://docs.python.org/3/library/functions.html#len | Python len()}
|
|
166
|
+
*/
|
|
167
|
+
declare function len(obj: string | unknown[] | Map<unknown, unknown> | Set<unknown> | {
|
|
168
|
+
length: number;
|
|
169
|
+
}): number;
|
|
170
|
+
/**
|
|
171
|
+
* Return the absolute value of a number.
|
|
172
|
+
*
|
|
173
|
+
* @param x - The number
|
|
174
|
+
* @returns The absolute value
|
|
175
|
+
* @see {@link https://docs.python.org/3/library/functions.html#abs | Python abs()}
|
|
176
|
+
*/
|
|
177
|
+
declare function abs(x: number): number;
|
|
178
|
+
/**
|
|
179
|
+
* Return the smallest item in an iterable or the smallest of two or more arguments.
|
|
180
|
+
*
|
|
181
|
+
* @param args - An iterable, or multiple values to compare
|
|
182
|
+
* @returns The minimum value
|
|
183
|
+
* @see {@link https://docs.python.org/3/library/functions.html#min | Python min()}
|
|
184
|
+
*/
|
|
185
|
+
declare function min<T>(...args: T[] | [Iterable<T>]): T;
|
|
186
|
+
/**
|
|
187
|
+
* Return the largest item in an iterable or the largest of two or more arguments.
|
|
188
|
+
*
|
|
189
|
+
* @param args - An iterable, or multiple values to compare
|
|
190
|
+
* @returns The maximum value
|
|
191
|
+
* @see {@link https://docs.python.org/3/library/functions.html#max | Python max()}
|
|
192
|
+
*/
|
|
193
|
+
declare function max<T>(...args: T[] | [Iterable<T>]): T;
|
|
194
|
+
/**
|
|
195
|
+
* Return the sum of all items in the iterable plus an optional start value.
|
|
196
|
+
*
|
|
197
|
+
* @param iterable - The numbers to sum
|
|
198
|
+
* @param start - The initial value (default: 0)
|
|
199
|
+
* @returns The sum
|
|
200
|
+
* @see {@link https://docs.python.org/3/library/functions.html#sum | Python sum()}
|
|
201
|
+
*/
|
|
202
|
+
declare function sum(iterable: Iterable<number>, start?: number): number;
|
|
203
|
+
/**
|
|
204
|
+
* Return True if all elements of the iterable are truthy (or if empty).
|
|
205
|
+
*
|
|
206
|
+
* @param iterable - The elements to test
|
|
207
|
+
* @returns True if all elements are truthy
|
|
208
|
+
* @see {@link https://docs.python.org/3/library/functions.html#all | Python all()}
|
|
209
|
+
*/
|
|
210
|
+
declare function all(iterable: Iterable<unknown>): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Return True if any element of the iterable is truthy.
|
|
213
|
+
*
|
|
214
|
+
* @param iterable - The elements to test
|
|
215
|
+
* @returns True if any element is truthy
|
|
216
|
+
* @see {@link https://docs.python.org/3/library/functions.html#any | Python any()}
|
|
217
|
+
*/
|
|
218
|
+
declare function any(iterable: Iterable<unknown>): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Round a number to a given precision in decimal digits.
|
|
221
|
+
*
|
|
222
|
+
* Uses banker's rounding (round half to even) for values exactly halfway.
|
|
223
|
+
*
|
|
224
|
+
* @param number - The number to round
|
|
225
|
+
* @param ndigits - Number of decimal places (default: 0)
|
|
226
|
+
* @returns The rounded number
|
|
227
|
+
* @see {@link https://docs.python.org/3/library/functions.html#round | Python round()}
|
|
228
|
+
*/
|
|
229
|
+
declare function round(number: number, ndigits?: number): number;
|
|
230
|
+
/**
|
|
231
|
+
* Return the Unicode code point for a one-character string.
|
|
232
|
+
*
|
|
233
|
+
* @param char - A single character
|
|
234
|
+
* @returns The Unicode code point
|
|
235
|
+
* @see {@link https://docs.python.org/3/library/functions.html#ord | Python ord()}
|
|
236
|
+
*/
|
|
237
|
+
declare function ord(char: string): number;
|
|
238
|
+
/**
|
|
239
|
+
* Return the string representing a character at the given Unicode code point.
|
|
240
|
+
*
|
|
241
|
+
* @param code - The Unicode code point
|
|
242
|
+
* @returns A single-character string
|
|
243
|
+
* @see {@link https://docs.python.org/3/library/functions.html#chr | Python chr()}
|
|
244
|
+
*/
|
|
245
|
+
declare function chr(code: number): string;
|
|
246
|
+
/**
|
|
247
|
+
* Convert an integer to a lowercase hexadecimal string prefixed with "0x".
|
|
248
|
+
*
|
|
249
|
+
* @param x - The integer to convert
|
|
250
|
+
* @returns Hexadecimal string (e.g., "0xff")
|
|
251
|
+
* @see {@link https://docs.python.org/3/library/functions.html#hex | Python hex()}
|
|
252
|
+
*/
|
|
253
|
+
declare function hex(x: number): string;
|
|
254
|
+
/**
|
|
255
|
+
* Convert an integer to an octal string prefixed with "0o".
|
|
256
|
+
*
|
|
257
|
+
* @param x - The integer to convert
|
|
258
|
+
* @returns Octal string (e.g., "0o17")
|
|
259
|
+
* @see {@link https://docs.python.org/3/library/functions.html#oct | Python oct()}
|
|
260
|
+
*/
|
|
261
|
+
declare function oct(x: number): string;
|
|
262
|
+
/**
|
|
263
|
+
* Convert an integer to a binary string prefixed with "0b".
|
|
264
|
+
*
|
|
265
|
+
* @param x - The integer to convert
|
|
266
|
+
* @returns Binary string (e.g., "0b1010")
|
|
267
|
+
* @see {@link https://docs.python.org/3/library/functions.html#bin | Python bin()}
|
|
268
|
+
*/
|
|
269
|
+
declare function bin(x: number): string;
|
|
270
|
+
/**
|
|
271
|
+
* Convert a value to an integer.
|
|
272
|
+
*
|
|
273
|
+
* Truncates floats toward zero. Parses strings in the given base.
|
|
274
|
+
*
|
|
275
|
+
* @param x - The value to convert
|
|
276
|
+
* @param base - The base for string conversion (default: 10)
|
|
277
|
+
* @returns The integer value
|
|
278
|
+
* @see {@link https://docs.python.org/3/library/functions.html#int | Python int()}
|
|
279
|
+
*/
|
|
280
|
+
declare function int(x: string | number | boolean, base?: number): number;
|
|
281
|
+
/**
|
|
282
|
+
* Convert a value to a floating-point number.
|
|
283
|
+
*
|
|
284
|
+
* @param x - The value to convert
|
|
285
|
+
* @returns The float value
|
|
286
|
+
* @see {@link https://docs.python.org/3/library/functions.html#float | Python float()}
|
|
287
|
+
*/
|
|
288
|
+
declare function float(x: string | number): number;
|
|
289
|
+
/**
|
|
290
|
+
* Convert a value to its string representation.
|
|
291
|
+
*
|
|
292
|
+
* Uses Python-style formatting for booleans (True/False), None, and collections.
|
|
293
|
+
*
|
|
294
|
+
* @param x - The value to convert
|
|
295
|
+
* @returns The string representation
|
|
296
|
+
* @see {@link https://docs.python.org/3/library/functions.html#func-str | Python str()}
|
|
297
|
+
*/
|
|
298
|
+
declare function str(x: unknown): string;
|
|
299
|
+
/**
|
|
300
|
+
* Return a string containing a printable representation of an object.
|
|
301
|
+
*
|
|
302
|
+
* Strings are quoted, other types use str() representation.
|
|
303
|
+
*
|
|
304
|
+
* @param x - The value to represent
|
|
305
|
+
* @returns A printable representation
|
|
306
|
+
* @see {@link https://docs.python.org/3/library/functions.html#repr | Python repr()}
|
|
307
|
+
*/
|
|
308
|
+
declare function repr(x: unknown): string;
|
|
309
|
+
/**
|
|
310
|
+
* Convert a value to a boolean using Python's truthiness rules.
|
|
311
|
+
*
|
|
312
|
+
* False values: null, undefined, false, 0, empty strings, empty arrays, empty Maps/Sets.
|
|
313
|
+
*
|
|
314
|
+
* @param x - The value to convert
|
|
315
|
+
* @returns The boolean value
|
|
316
|
+
* @see {@link https://docs.python.org/3/library/functions.html#bool | Python bool()}
|
|
317
|
+
*/
|
|
318
|
+
declare function bool(x: unknown): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Return a string containing a printable ASCII representation.
|
|
321
|
+
*
|
|
322
|
+
* Non-ASCII characters are escaped using \\xhh, \\uhhhh, or \\Uhhhhhhhh.
|
|
323
|
+
*
|
|
324
|
+
* @param x - The value to represent
|
|
325
|
+
* @returns ASCII-safe printable representation
|
|
326
|
+
* @see {@link https://docs.python.org/3/library/functions.html#ascii | Python ascii()}
|
|
327
|
+
*/
|
|
328
|
+
declare function ascii(x: unknown): string;
|
|
329
|
+
/**
|
|
330
|
+
* Return True if the object is an instance of the specified class.
|
|
331
|
+
*
|
|
332
|
+
* Supports JavaScript constructors (Number, String, etc.) and Python type names.
|
|
333
|
+
*
|
|
334
|
+
* @param obj - The object to check
|
|
335
|
+
* @param classInfo - The class or type name to check against
|
|
336
|
+
* @returns True if obj is an instance of classInfo
|
|
337
|
+
* @see {@link https://docs.python.org/3/library/functions.html#isinstance | Python isinstance()}
|
|
338
|
+
*/
|
|
339
|
+
declare function isinstance(obj: unknown, classInfo: unknown): boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Return the type name of an object as a string.
|
|
342
|
+
*
|
|
343
|
+
* Returns Python-style type names: 'int', 'float', 'str', 'bool', 'list', 'dict', 'set'.
|
|
344
|
+
*
|
|
345
|
+
* @param obj - The object to check
|
|
346
|
+
* @returns The type name
|
|
347
|
+
* @see {@link https://docs.python.org/3/library/functions.html#type | Python type()}
|
|
348
|
+
*/
|
|
349
|
+
declare function type(obj: unknown): string;
|
|
350
|
+
/**
|
|
351
|
+
* Read a line of input from the user.
|
|
352
|
+
*
|
|
353
|
+
* Note: This function requires async implementation in JavaScript environments.
|
|
354
|
+
*
|
|
355
|
+
* @param prompt - Optional prompt string to display
|
|
356
|
+
* @returns The input string
|
|
357
|
+
* @see {@link https://docs.python.org/3/library/functions.html#input | Python input()}
|
|
358
|
+
*/
|
|
359
|
+
declare function input(prompt?: string): string;
|
|
360
|
+
/**
|
|
361
|
+
* Convert a value to a formatted representation using a format specification.
|
|
362
|
+
*
|
|
363
|
+
* Supports Python format spec mini-language for numbers and strings.
|
|
364
|
+
*
|
|
365
|
+
* @param value - The value to format
|
|
366
|
+
* @param spec - The format specification string
|
|
367
|
+
* @returns The formatted string
|
|
368
|
+
* @see {@link https://docs.python.org/3/library/functions.html#format | Python format()}
|
|
369
|
+
*/
|
|
370
|
+
declare function format(value: unknown, spec: string): string;
|
|
371
|
+
/**
|
|
372
|
+
* Python getattr() function - get an attribute from an object
|
|
373
|
+
*
|
|
374
|
+
* @param obj - The object to get the attribute from
|
|
375
|
+
* @param name - The name of the attribute
|
|
376
|
+
* @param defaultValue - Optional default value if attribute doesn't exist
|
|
377
|
+
* @returns The attribute value or default value
|
|
378
|
+
*/
|
|
379
|
+
declare function getattr<T>(obj: unknown, name: string, defaultValue?: T): T | undefined;
|
|
380
|
+
/**
|
|
381
|
+
* Python hasattr() function - check if an object has an attribute
|
|
382
|
+
*
|
|
383
|
+
* @param obj - The object to check
|
|
384
|
+
* @param name - The name of the attribute
|
|
385
|
+
* @returns True if the attribute exists, false otherwise
|
|
386
|
+
*/
|
|
387
|
+
declare function hasattr(obj: unknown, name: string): boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Python setattr() function - set an attribute on an object
|
|
390
|
+
*
|
|
391
|
+
* @param obj - The object to set the attribute on
|
|
392
|
+
* @param name - The name of the attribute
|
|
393
|
+
* @param value - The value to set
|
|
394
|
+
*/
|
|
395
|
+
declare function setattr(obj: unknown, name: string, value: unknown): void;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Python list methods for TypeScript
|
|
399
|
+
* Usage: py.list.remove(), py.list.sort(), etc.
|
|
400
|
+
*/
|
|
401
|
+
declare const list: {
|
|
402
|
+
/**
|
|
403
|
+
* Python list.append() - modifies array in place
|
|
404
|
+
*/
|
|
405
|
+
append<T>(arr: T[], item: T): void;
|
|
406
|
+
/**
|
|
407
|
+
* Python list.extend() - modifies array in place
|
|
408
|
+
*/
|
|
409
|
+
extend<T>(arr: T[], items: Iterable<T>): void;
|
|
410
|
+
/**
|
|
411
|
+
* Python list.insert() - modifies array in place
|
|
412
|
+
*/
|
|
413
|
+
insert<T>(arr: T[], index: number, item: T): void;
|
|
414
|
+
/**
|
|
415
|
+
* Python list.remove() - removes first occurrence, modifies in place
|
|
416
|
+
*/
|
|
417
|
+
remove<T>(arr: T[], value: T): void;
|
|
418
|
+
/**
|
|
419
|
+
* Python list.pop() - removes and returns item at index
|
|
420
|
+
*/
|
|
421
|
+
pop<T>(arr: T[], index?: number): T;
|
|
422
|
+
/**
|
|
423
|
+
* Python list.clear() - removes all items
|
|
424
|
+
*/
|
|
425
|
+
clear(arr: unknown[]): void;
|
|
426
|
+
/**
|
|
427
|
+
* Python list.index() - finds first occurrence
|
|
428
|
+
*/
|
|
429
|
+
index<T>(arr: T[], value: T, start?: number, end?: number): number;
|
|
430
|
+
/**
|
|
431
|
+
* Python list.count() - counts occurrences
|
|
432
|
+
*/
|
|
433
|
+
count<T>(arr: T[], value: T): number;
|
|
434
|
+
/**
|
|
435
|
+
* Python list.sort() with key function - modifies in place
|
|
436
|
+
*/
|
|
437
|
+
sort<T>(arr: T[], options?: {
|
|
438
|
+
key?: (x: T) => unknown;
|
|
439
|
+
reverse?: boolean;
|
|
440
|
+
}): void;
|
|
441
|
+
/**
|
|
442
|
+
* Python list.reverse() - reverses in place
|
|
443
|
+
*/
|
|
444
|
+
reverse(arr: unknown[]): void;
|
|
445
|
+
/**
|
|
446
|
+
* Python list.copy() - shallow copy
|
|
447
|
+
*/
|
|
448
|
+
copy<T>(arr: T[]): T[];
|
|
449
|
+
/**
|
|
450
|
+
* Python slice assignment: arr[start:end:step] = values
|
|
451
|
+
* Replaces a slice of the array with new values, modifying in place
|
|
452
|
+
*/
|
|
453
|
+
sliceAssign<T>(arr: T[], start: number | undefined, end: number | undefined, step: number | undefined, values: T[]): void;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Python dict methods for TypeScript
|
|
458
|
+
* Usage: py.dict.get(), py.dict.keys(), etc.
|
|
459
|
+
*/
|
|
460
|
+
declare const dict: {
|
|
461
|
+
/**
|
|
462
|
+
* Python dict.get() - get value with optional default
|
|
463
|
+
*/
|
|
464
|
+
get<K extends string | number | symbol, V>(obj: Record<K, V>, key: K, defaultValue?: V): V | undefined;
|
|
465
|
+
/**
|
|
466
|
+
* Python dict.setDefault() - get value or set default
|
|
467
|
+
*/
|
|
468
|
+
setDefault<K extends string | number | symbol, V>(obj: Record<K, V>, key: K, defaultValue: V): V;
|
|
469
|
+
/**
|
|
470
|
+
* Python dict.pop() - remove and return value
|
|
471
|
+
*/
|
|
472
|
+
pop<K extends string | number | symbol, V>(obj: Record<K, V>, key: K, defaultValue?: V): V | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Python dict.popItem() - remove and return last item
|
|
475
|
+
*/
|
|
476
|
+
popItem<K extends string | number | symbol, V>(obj: Record<K, V>): [K, V];
|
|
477
|
+
/**
|
|
478
|
+
* Python dict.update() - update with another dict
|
|
479
|
+
*/
|
|
480
|
+
update<K extends string | number | symbol, V>(obj: Record<K, V>, other: Record<K, V> | Iterable<[K, V]>): void;
|
|
481
|
+
/**
|
|
482
|
+
* Python dict.clear() - remove all items
|
|
483
|
+
*/
|
|
484
|
+
clear<K extends string | number | symbol, V>(obj: Record<K, V>): void;
|
|
485
|
+
/**
|
|
486
|
+
* Python dict.copy() - shallow copy
|
|
487
|
+
*/
|
|
488
|
+
copy<K extends string | number | symbol, V>(obj: Record<K, V>): Record<K, V>;
|
|
489
|
+
/**
|
|
490
|
+
* Python dict.keys() - returns iterable of keys
|
|
491
|
+
*/
|
|
492
|
+
keys<K extends string | number | symbol, V>(obj: Record<K, V>): K[];
|
|
493
|
+
/**
|
|
494
|
+
* Python dict.values() - returns iterable of values
|
|
495
|
+
*/
|
|
496
|
+
values<K extends string | number | symbol, V>(obj: Record<K, V>): V[];
|
|
497
|
+
/**
|
|
498
|
+
* Python dict.items() - returns iterable of [key, value] pairs
|
|
499
|
+
*/
|
|
500
|
+
items<K extends string | number | symbol, V>(obj: Record<K, V>): [K, V][];
|
|
501
|
+
/**
|
|
502
|
+
* Python dict.fromKeys() - create dict from keys
|
|
503
|
+
*/
|
|
504
|
+
fromKeys<K extends string | number | symbol, V>(keys: K[], value?: V): Record<K, V | undefined>;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Python set methods for TypeScript
|
|
509
|
+
* Usage: py.set.intersection(), py.set.union(), etc.
|
|
510
|
+
*
|
|
511
|
+
* Uses ES2024 native Set methods where available for optimal performance.
|
|
512
|
+
*/
|
|
513
|
+
declare const set: {
|
|
514
|
+
/**
|
|
515
|
+
* Python set.add() - add element
|
|
516
|
+
*/
|
|
517
|
+
add<T>(s: Set<T>, item: T): void;
|
|
518
|
+
/**
|
|
519
|
+
* Python set.remove() - remove element, raises error if not found
|
|
520
|
+
*/
|
|
521
|
+
remove<T>(s: Set<T>, item: T): void;
|
|
522
|
+
/**
|
|
523
|
+
* Python set.discard() - remove element if present
|
|
524
|
+
*/
|
|
525
|
+
discard<T>(s: Set<T>, item: T): void;
|
|
526
|
+
/**
|
|
527
|
+
* Python set.pop() - remove and return arbitrary element
|
|
528
|
+
*/
|
|
529
|
+
pop<T>(s: Set<T>): T;
|
|
530
|
+
/**
|
|
531
|
+
* Python set.clear() - remove all elements
|
|
532
|
+
*/
|
|
533
|
+
clear<T>(s: Set<T>): void;
|
|
534
|
+
/**
|
|
535
|
+
* Python set.copy() - shallow copy
|
|
536
|
+
*/
|
|
537
|
+
copy<T>(s: Set<T>): Set<T>;
|
|
538
|
+
/**
|
|
539
|
+
* Python set.update() - add elements from iterable
|
|
540
|
+
*/
|
|
541
|
+
update<T>(s: Set<T>, ...iterables: Iterable<T>[]): void;
|
|
542
|
+
/**
|
|
543
|
+
* Python set.union() - returns new set with all elements
|
|
544
|
+
* Uses ES2024 Set.prototype.union()
|
|
545
|
+
*/
|
|
546
|
+
union<T>(a: Set<T>, ...others: Iterable<T>[]): Set<T>;
|
|
547
|
+
/**
|
|
548
|
+
* Python set.intersection() - returns new set with common elements
|
|
549
|
+
* Uses ES2024 Set.prototype.intersection()
|
|
550
|
+
*/
|
|
551
|
+
intersection<T>(a: Set<T>, b: Set<T>): Set<T>;
|
|
552
|
+
/**
|
|
553
|
+
* Python set.intersection_update() - keep only common elements
|
|
554
|
+
*/
|
|
555
|
+
intersectionUpdate<T>(a: Set<T>, b: Set<T>): void;
|
|
556
|
+
/**
|
|
557
|
+
* Python set.difference() - returns new set with elements in a but not in b
|
|
558
|
+
* Uses ES2024 Set.prototype.difference()
|
|
559
|
+
*/
|
|
560
|
+
difference<T>(a: Set<T>, b: Set<T>): Set<T>;
|
|
561
|
+
/**
|
|
562
|
+
* Python set.difference_update() - remove elements found in b
|
|
563
|
+
*/
|
|
564
|
+
differenceUpdate<T>(a: Set<T>, b: Set<T>): void;
|
|
565
|
+
/**
|
|
566
|
+
* Python set.symmetric_difference() - returns new set with elements in either but not both
|
|
567
|
+
* Uses ES2024 Set.prototype.symmetricDifference()
|
|
568
|
+
*/
|
|
569
|
+
symmetricDifference<T>(a: Set<T>, b: Set<T>): Set<T>;
|
|
570
|
+
/**
|
|
571
|
+
* Python set.symmetric_difference_update() - update with symmetric difference
|
|
572
|
+
* Uses ES2024 Set.prototype.symmetricDifference()
|
|
573
|
+
*/
|
|
574
|
+
symmetricDifferenceUpdate<T>(a: Set<T>, b: Set<T>): void;
|
|
575
|
+
/**
|
|
576
|
+
* Python set.isSubset() - test if all elements are in other
|
|
577
|
+
* Uses ES2024 Set.prototype.isSubsetOf()
|
|
578
|
+
*/
|
|
579
|
+
isSubset<T>(a: Set<T>, b: Set<T>): boolean;
|
|
580
|
+
/**
|
|
581
|
+
* Python set.isSuperset() - test if all other elements are in this set
|
|
582
|
+
* Uses ES2024 Set.prototype.isSupersetOf()
|
|
583
|
+
*/
|
|
584
|
+
isSuperset<T>(a: Set<T>, b: Set<T>): boolean;
|
|
585
|
+
/**
|
|
586
|
+
* Python set.isDisjoint() - test if no common elements
|
|
587
|
+
* Uses ES2024 Set.prototype.isDisjointFrom()
|
|
588
|
+
*/
|
|
589
|
+
isDisjoint<T>(a: Set<T>, b: Set<T>): boolean;
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
export { all as A, any as B, round as C, ord as D, chr as E, hex as F, oct as G, bin as H, int as I, float as J, str as K, repr as L, bool as M, ascii as N, isinstance as O, type as P, input as Q, format as R, getattr as S, hasattr as T, setattr as U, repeat as V, pow as W, divMod as a, sprintf as b, strFormat as c, dict as d, slice as e, floorDiv as f, at as g, contains as h, is as i, enumerate as j, iter as k, list as l, mod as m, reversed as n, sorted as o, map as p, filter as q, range as r, set as s, tuple as t, len as u, abs as v, min as w, max as x, sum as y, zip as z };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python shutil module for TypeScript - Browser version
|
|
3
|
+
*
|
|
4
|
+
* Browser stub - file operations are not available.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://docs.python.org/3/library/shutil.html | Python shutil documentation}
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Copy file from src to dst.
|
|
11
|
+
* Browser stub - throws error.
|
|
12
|
+
*/
|
|
13
|
+
declare function copy(_src: string, _dst: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Copy file with metadata from src to dst.
|
|
16
|
+
* Browser stub - throws error.
|
|
17
|
+
*/
|
|
18
|
+
declare function copy2(_src: string, _dst: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Copy an entire directory tree.
|
|
21
|
+
* Browser stub - throws error.
|
|
22
|
+
*/
|
|
23
|
+
declare function copytree(_src: string, _dst: string, _options?: {
|
|
24
|
+
symlinks?: boolean;
|
|
25
|
+
ignore?: (dir: string, files: string[]) => string[];
|
|
26
|
+
copyFunction?: (src: string, dst: string) => Promise<string>;
|
|
27
|
+
dirsExist_ok?: boolean;
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Move a file or directory.
|
|
31
|
+
* Browser stub - throws error.
|
|
32
|
+
*/
|
|
33
|
+
declare function move(_src: string, _dst: string): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Remove a directory tree.
|
|
36
|
+
* Browser stub - throws error.
|
|
37
|
+
*/
|
|
38
|
+
declare function rmtree(_path: string, _ignoreErrors?: boolean): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Find an executable in PATH.
|
|
41
|
+
* Browser stub - returns null.
|
|
42
|
+
*/
|
|
43
|
+
declare function which(_cmd: string, _mode?: number, _path?: string): Promise<string | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Return disk usage statistics.
|
|
46
|
+
* Browser stub - throws error.
|
|
47
|
+
*/
|
|
48
|
+
declare function diskUsage(_path: string): Promise<{
|
|
49
|
+
total: number;
|
|
50
|
+
used: number;
|
|
51
|
+
free: number;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Copy file permission bits.
|
|
55
|
+
* Browser stub - no-op.
|
|
56
|
+
*/
|
|
57
|
+
declare function copyMode(_src: string, _dst: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Copy file stat info.
|
|
60
|
+
* Browser stub - no-op.
|
|
61
|
+
*/
|
|
62
|
+
declare function copyStat(_src: string, _dst: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Copy file without metadata.
|
|
65
|
+
* Browser stub - throws error.
|
|
66
|
+
*/
|
|
67
|
+
declare function copyFile(_src: string, _dst: string): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Copy file object.
|
|
70
|
+
* Browser stub - throws error.
|
|
71
|
+
*/
|
|
72
|
+
declare function copyFileObj(_fsrc: {
|
|
73
|
+
read: (size: number) => Promise<Uint8Array | null>;
|
|
74
|
+
}, _fdst: {
|
|
75
|
+
write: (data: Uint8Array) => Promise<number>;
|
|
76
|
+
}, _length?: number): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Get terminal size.
|
|
79
|
+
*/
|
|
80
|
+
declare function getTerminalSize(fallback?: [number, number]): {
|
|
81
|
+
columns: number;
|
|
82
|
+
lines: number;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Make an archive file.
|
|
86
|
+
* Browser stub - throws error.
|
|
87
|
+
*/
|
|
88
|
+
declare function makeArchive(_baseName: string, _format: string, _rootDir: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Unpack an archive file.
|
|
91
|
+
* Browser stub - throws error.
|
|
92
|
+
*/
|
|
93
|
+
declare function unpackArchive(_filename: string, _extractDir?: string): void;
|
|
94
|
+
|
|
95
|
+
declare const shutilModule_copy: typeof copy;
|
|
96
|
+
declare const shutilModule_copy2: typeof copy2;
|
|
97
|
+
declare const shutilModule_copyFile: typeof copyFile;
|
|
98
|
+
declare const shutilModule_copyFileObj: typeof copyFileObj;
|
|
99
|
+
declare const shutilModule_copyMode: typeof copyMode;
|
|
100
|
+
declare const shutilModule_copyStat: typeof copyStat;
|
|
101
|
+
declare const shutilModule_copytree: typeof copytree;
|
|
102
|
+
declare const shutilModule_diskUsage: typeof diskUsage;
|
|
103
|
+
declare const shutilModule_getTerminalSize: typeof getTerminalSize;
|
|
104
|
+
declare const shutilModule_makeArchive: typeof makeArchive;
|
|
105
|
+
declare const shutilModule_move: typeof move;
|
|
106
|
+
declare const shutilModule_rmtree: typeof rmtree;
|
|
107
|
+
declare const shutilModule_unpackArchive: typeof unpackArchive;
|
|
108
|
+
declare const shutilModule_which: typeof which;
|
|
109
|
+
declare namespace shutilModule {
|
|
110
|
+
export { shutilModule_copy as copy, shutilModule_copy2 as copy2, shutilModule_copyFile as copyFile, shutilModule_copyFileObj as copyFileObj, shutilModule_copyMode as copyMode, shutilModule_copyStat as copyStat, shutilModule_copytree as copytree, shutilModule_diskUsage as diskUsage, shutilModule_getTerminalSize as getTerminalSize, shutilModule_makeArchive as makeArchive, shutilModule_move as move, shutilModule_rmtree as rmtree, shutilModule_unpackArchive as unpackArchive, shutilModule_which as which };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { copy2 as a, copytree as b, copy as c, diskUsage as d, copyMode as e, copyStat as f, copyFile as g, copyFileObj as h, getTerminalSize as i, makeArchive as j, move as m, rmtree as r, shutilModule as s, unpackArchive as u, which as w };
|