python2ts 0.1.0 โ†’ 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +22 -92
  2. package/dist/chunk-M4HMEUNQ.js +4454 -0
  3. package/dist/chunk-M4HMEUNQ.js.map +1 -0
  4. package/dist/cli/index.js +1 -2
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1 -6
  8. package/dist/index.js.map +1 -1
  9. package/package.json +18 -3
  10. package/dist/acorn-CDFV7HXL.js +0 -3131
  11. package/dist/acorn-CDFV7HXL.js.map +0 -1
  12. package/dist/angular-PCJAXZFD.js +0 -3071
  13. package/dist/angular-PCJAXZFD.js.map +0 -1
  14. package/dist/babel-O6RKFHDQ.js +0 -7297
  15. package/dist/babel-O6RKFHDQ.js.map +0 -1
  16. package/dist/chunk-DTI6R2GT.js +0 -23942
  17. package/dist/chunk-DTI6R2GT.js.map +0 -1
  18. package/dist/chunk-PZ5AY32C.js +0 -10
  19. package/dist/chunk-PZ5AY32C.js.map +0 -1
  20. package/dist/estree-467CT4RF.js +0 -4613
  21. package/dist/estree-467CT4RF.js.map +0 -1
  22. package/dist/flow-FCFYGKSM.js +0 -27547
  23. package/dist/flow-FCFYGKSM.js.map +0 -1
  24. package/dist/glimmer-P46N72G3.js +0 -2895
  25. package/dist/glimmer-P46N72G3.js.map +0 -1
  26. package/dist/graphql-TFOZJU7B.js +0 -1267
  27. package/dist/graphql-TFOZJU7B.js.map +0 -1
  28. package/dist/html-KZKNLN3R.js +0 -2934
  29. package/dist/html-KZKNLN3R.js.map +0 -1
  30. package/dist/markdown-BS2B5AKD.js +0 -3554
  31. package/dist/markdown-BS2B5AKD.js.map +0 -1
  32. package/dist/meriyah-W6HUPGCY.js +0 -2685
  33. package/dist/meriyah-W6HUPGCY.js.map +0 -1
  34. package/dist/postcss-LMJBCD2Q.js +0 -5081
  35. package/dist/postcss-LMJBCD2Q.js.map +0 -1
  36. package/dist/typescript-Y5EPKFX5.js +0 -13204
  37. package/dist/typescript-Y5EPKFX5.js.map +0 -1
  38. package/dist/yaml-ZNP3H3BX.js +0 -4225
  39. package/dist/yaml-ZNP3H3BX.js.map +0 -1
package/README.md CHANGED
@@ -1,37 +1,32 @@
1
1
  # python2ts
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/python2ts.svg)](https://www.npmjs.com/package/python2ts)
4
+ [![npm downloads](https://img.shields.io/npm/dm/python2ts.svg)](https://www.npmjs.com/package/python2ts)
5
+ [![CI](https://github.com/sebastian-software/python2ts/actions/workflows/ci.yml/badge.svg)](https://github.com/sebastian-software/python2ts/actions/workflows/ci.yml)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
4
7
  [![License](https://img.shields.io/npm/l/python2ts.svg)](https://github.com/sebastian-software/python2ts/blob/main/LICENSE)
5
8
 
6
9
  **AST-based Python to TypeScript transpiler** โ€” Write Python, ship TypeScript.
7
10
 
8
- Converts Python code to clean, idiomatic TypeScript with full type preservation.
11
+ > Convert Python code to clean, idiomatic TypeScript with full type preservation.
9
12
 
10
- ## Installation
13
+ ## Quick Start
11
14
 
12
15
  ```bash
13
16
  npm install python2ts
14
17
  ```
15
18
 
16
- ## CLI Usage
17
-
18
19
  ```bash
19
20
  # Transpile a file
20
21
  npx python2ts input.py -o output.ts
21
22
 
22
23
  # Pipe from stdin
23
24
  cat script.py | npx python2ts > script.ts
24
-
25
- # Preview without runtime import
26
- npx python2ts input.py --no-runtime
27
25
  ```
28
26
 
29
- ## API Usage
30
-
31
- ```typescript
32
- import { transpile } from "python2ts"
27
+ ## Example
33
28
 
34
- const typescript = transpile(`
29
+ ```python
35
30
  def fibonacci(n: int) -> list[int]:
36
31
  a, b = 0, 1
37
32
  result = []
@@ -39,10 +34,9 @@ def fibonacci(n: int) -> list[int]:
39
34
  result.append(a)
40
35
  a, b = b, a + b
41
36
  return result
42
- `)
43
37
  ```
44
38
 
45
- **Output:**
39
+ Becomes:
46
40
 
47
41
  ```typescript
48
42
  import { range } from "pythonlib"
@@ -58,91 +52,27 @@ function fibonacci(n: number): number[] {
58
52
  }
59
53
  ```
60
54
 
61
- ## What Gets Transpiled?
62
-
63
- | Python | TypeScript |
64
- | ---------------------------- | ------------------------------------- |
65
- | `int`, `str`, `bool`, `None` | `number`, `string`, `boolean`, `null` |
66
- | `list[T]`, `dict[K,V]` | `T[]`, `Record<K,V>` |
67
- | `Optional[T]` | `T \| null` |
68
- | `def fn():` | `function fn()` |
69
- | `lambda x: x + 1` | `(x) => x + 1` |
70
- | `class Child(Parent):` | `class Child extends Parent` |
71
- | `@dataclass` | Auto-generated constructor |
72
- | `for x in items:` | `for (const x of items)` |
73
- | `if/elif/else` | `if/else if/else` |
74
- | `match/case` | `switch/case` |
75
- | `async def` / `await` | `async function` / `await` |
76
- | `//` (floor div) | `floordiv()` (Python semantics) |
77
- | `%` (modulo) | `mod()` (Python semantics) |
78
- | `arr[1:-1]` (slicing) | `slice()` (full support) |
79
- | `f"Hello {name}"` | `` `Hello ${name}` `` |
80
- | `"""docstring"""` | `/** JSDoc */` |
81
-
82
- ## Advanced API
55
+ ## Documentation
83
56
 
84
- ```typescript
85
- import { parse, transform, generate } from "python2ts"
86
-
87
- // Step-by-step transformation
88
- const ast = parse(pythonCode)
89
- const transformed = transform(ast)
90
- const { code, usedRuntimeFunctions } = generate(transformed, {
91
- includeRuntime: true,
92
- runtimeImportPath: "pythonlib"
93
- })
94
- ```
95
-
96
- ## Runtime Library
97
-
98
- python2ts uses [pythonlib](https://www.npmjs.com/package/pythonlib) for Python standard library
99
- functions:
100
-
101
- ```typescript
102
- // Generated imports (grouped by module)
103
- import { range, enumerate, len } from "pythonlib"
104
- import { chain, combinations } from "pythonlib/itertools"
105
- import { Counter } from "pythonlib/collections"
106
- ```
57
+ **[๐Ÿ“š View Full Documentation](https://sebastian-software.github.io/python2ts/)**
107
58
 
108
- pythonlib is automatically included as a dependency.
109
-
110
- ## Type Hints Preserved
111
-
112
- ```python
113
- from typing import Optional, Callable, TypeVar
114
-
115
- T = TypeVar('T')
116
-
117
- def process(
118
- items: list[T],
119
- callback: Callable[[T, int], bool],
120
- default: Optional[str] = None
121
- ) -> dict[str, T]:
122
- ...
123
- ```
124
-
125
- Becomes:
126
-
127
- ```typescript
128
- function process<T>(
129
- items: T[],
130
- callback: (arg0: T, arg1: number) => boolean,
131
- default_: string | null = null
132
- ): Record<string, T> {
133
- // ...
134
- }
135
- ```
59
+ | Resource | Description |
60
+ | ------------------------------------------------------------------------------ | ------------------------------------------- |
61
+ | [Homepage](https://sebastian-software.github.io/python2ts/) | Project overview, features, and quick start |
62
+ | [Getting Started](https://sebastian-software.github.io/python2ts/docs/) | Installation and first steps |
63
+ | [Syntax Reference](https://sebastian-software.github.io/python2ts/docs/syntax) | Python โ†’ TypeScript transformation rules |
64
+ | [Runtime Library](https://sebastian-software.github.io/python2ts/docs/runtime) | Using pythonlib for Python standard library |
65
+ | [API Reference](https://sebastian-software.github.io/python2ts/docs/api) | Complete API documentation |
136
66
 
137
- ## Requirements
67
+ ## Runtime Support
138
68
 
139
- - Node.js >= 22.0.0
69
+ Tested on every commit: **Node.js** (v22, v24) ยท **Bun** ยท **Deno** ยท **Browsers**
140
70
 
141
71
  ## Related
142
72
 
143
- - [pythonlib](https://www.npmjs.com/package/pythonlib) โ€” Python standard library for TypeScript
144
- (standalone runtime)
73
+ - [**pythonlib**](https://www.npmjs.com/package/pythonlib) โ€” Python standard library for TypeScript
74
+ - [**GitHub**](https://github.com/sebastian-software/python2ts) โ€” Source code and issue tracker
145
75
 
146
76
  ## License
147
77
 
148
- MIT
78
+ MIT ยฉ [Sebastian Software GmbH](https://sebastian-software.de)