@siyavuyachagi/typesharp 0.1.2 → 0.1.4

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 (2) hide show
  1. package/README.md +75 -37
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -14,34 +14,34 @@ Project structure: [docs/project-structure](docs/project-structure.md)
14
14
 
15
15
  ## Features
16
16
 
17
- **Automatic Type Generation** – Convert C# models to TypeScript interfaces
18
- 🎯 **Custom Attribute Targeting** – Use `[TypeSharp]` or any custom attribute
19
- 🔄 **Nullable Support** – `string?` → `string | null`
20
- 📦 **Collection Handling** – Supports `List<T>`, `IEnumerable<T>`, arrays **and generic collections**
21
- 🗺️ **Dictionary Mapping** – `Dictionary<K, V>` → `Record<K, V>`
22
- 🧬 **Generic Types** – Preserves generic type definitions like `Response<T>` → `Response<T>`
23
- 🧬 **Inheritance** – Preserves class inheritance using `extends`
24
- 🏗️ **Computed Properties** – Expression-bodied and block getter properties are included
25
- 🎨 **Naming Conventions** – Convert property names (camel, pascal, snake, kebab)
26
- 📁 **Flexible Output** – Single file or multiple files
27
- 🔢 **Enum Support** – Converts C# enums to TypeScript string enums
28
- 🗂️ **File Grouping** – Preserves C# file organization (multiple classes per file stay together)
29
- 🔗 **Auto Imports** – Automatically generates `import type` statements between output files
30
- 🏢 **Multi-Project** – Scan multiple `.csproj` files in a single run
31
- 🚫 **Obsolete Support** – `[Obsolete]` / `[Obsolete("...")]` → `/** @deprecated ... */` JSDoc
17
+ - **Automatic Type Generation** – Convert C# models to TypeScript interfaces
18
+ - **Custom Attribute Targeting** – Use `[TypeSharp]` or any custom attribute
19
+ - **Nullable Support** – `string?` → `string | null`
20
+ - **Collection Handling** – Supports `List<T>`, `IEnumerable<T>`, arrays **and generic collections**
21
+ - **Dictionary Mapping** – `Dictionary<K, V>` → `Record<K, V>`
22
+ - **Generic Types** – Preserves generic type definitions like `Response<T>` → `Response<T>`
23
+ - **Inheritance** – Preserves class inheritance using `extends`
24
+ - **Computed Properties** – Expression-bodied and block getter properties are included
25
+ - **Naming Conventions** – Convert property names (camel, pascal, snake, kebab)
26
+ - **Flexible Output** – Single file or multiple files
27
+ - **Enum Support** – Converts C# enums to TypeScript string enums
28
+ - **File Grouping** – Preserves C# file organization (multiple classes per file stay together)
29
+ - **Auto Imports** – Automatically generates `import type` statements between output files
30
+ - **Multi-Project** – Scan multiple `.csproj` files in a single run
31
+ - **Obsolete Support** – `[Obsolete]` / `[Obsolete("...")]` → `/** @deprecated ... */` JSDoc
32
32
 
33
33
  ## How TypeSharp Compares
34
34
 
35
35
  This is not an OpenApi-based tool !
36
36
  | Feature | TypeSharp | NSwag | openapi-typescript | TypeGen |
37
37
  | --------------------- | --------- | ----- | ------------------ | ------- |
38
- | Direct C# parsing | | | | |
39
- | Attribute targeting | | ⚠️ | | ⚠️ |
40
- | Non-API models | | | | |
41
- | Generics preserved | | ⚠️ | ⚠️ | ⚠️ |
42
- | File grouping | | | | |
43
- | Naming control | | ⚠️ | ⚠️ | |
44
- | API client generation | | | | |
38
+ | Direct C# parsing | | | | |
39
+ | Attribute targeting | | ! | | ! |
40
+ | Non-API models | | | | |
41
+ | Generics preserved | | ! | ! | ! |
42
+ | File grouping | | | | |
43
+ | Naming control | | ! | ! | |
44
+ | API client generation | | | | |
45
45
 
46
46
  Also see [docs/why-typesharp](docs/why-typesharp.md)
47
47
 
@@ -53,20 +53,18 @@ npm install -D @siyavuyachagi/typesharp
53
53
 
54
54
  ## Quick Start
55
55
 
56
- ### 1. Create an attribute to target
56
+ ### 1. Install the NuGet attributes package
57
57
 
58
- In your target project create the following attribute (`TypeSharp`)
58
+ In your C# project:
59
59
 
60
- ```cs
61
- namespace YourProject.Attribute
62
- {
63
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)]
64
- public class TypeSharpAttribute : Attribute { }
65
- }
60
+ ```bash
61
+ dotnet add package TypeSharp.Attributes
66
62
  ```
67
63
 
68
64
  ### 2. Decorate your C# models or DTOs
69
65
 
66
+ Use `[TypeSharp]` to include a class, or `[TypeSharp("name")]` to include it with a custom TypeScript type name:
67
+
70
68
  ```csharp
71
69
  [TypeSharp]
72
70
  public class User
@@ -263,7 +261,7 @@ TypeSharp supports multiple configuration formats:
263
261
 
264
262
  ```json
265
263
  {
266
- "projectFiles": ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
264
+ "source": ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
267
265
  "outputPath": "./src/types"
268
266
  }
269
267
  ```
@@ -274,7 +272,7 @@ TypeSharp supports multiple configuration formats:
274
272
  import { TypeSharpConfig } from "typesharp";
275
273
 
276
274
  const config: TypeSharpConfig = {
277
- projectFiles: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
275
+ source: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
278
276
  outputPath: "./src/types",
279
277
  };
280
278
 
@@ -285,7 +283,7 @@ export default config;
285
283
 
286
284
  ```javascript
287
285
  module.exports = {
288
- projectFiles: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
286
+ source: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
289
287
  outputPath: "./src/types",
290
288
  };
291
289
  ```
@@ -403,6 +401,7 @@ export interface PermissionMap {
403
401
  ### 4. Obsolete / Deprecated Properties
404
402
 
405
403
  **C#:**
404
+
406
405
  ```csharp
407
406
  [TypeSharp]
408
407
  public class Employee
@@ -419,6 +418,7 @@ public class Employee
419
418
  ```
420
419
 
421
420
  **Generated TypeScript:**
421
+
422
422
  ```typescript
423
423
  export interface Employee {
424
424
  id: number;
@@ -430,7 +430,45 @@ export interface Employee {
430
430
  }
431
431
  ```
432
432
 
433
- ### 5. Multi-Project
433
+ ### 5. Custom Type Name Override
434
+
435
+ Use `[TypeSharp("name")]` to override the generated TypeScript type name. The override takes precedence over `namingConvention`.
436
+
437
+ **C#:**
438
+
439
+ ```csharp
440
+ [TypeSharp("auth_response")]
441
+ public class AuthResponse
442
+ {
443
+ public string AccessToken { get; set; }
444
+ public string RefreshToken { get; set; }
445
+ }
446
+
447
+ [TypeSharp("user_role")]
448
+ public enum UserRole
449
+ {
450
+ Admin,
451
+ User,
452
+ Guest
453
+ }
454
+ ```
455
+
456
+ **Generated TypeScript:**
457
+
458
+ ```typescript
459
+ export interface auth_response {
460
+ accessToken: string;
461
+ refreshToken: string;
462
+ }
463
+
464
+ export enum user_role {
465
+ Admin = "Admin",
466
+ User = "User",
467
+ Guest = "Guest",
468
+ }
469
+ ```
470
+
471
+ ### 6. Multi-Project
434
472
 
435
473
  Scan multiple C# projects at once:
436
474
 
@@ -445,7 +483,7 @@ Scan multiple C# projects at once:
445
483
  }
446
484
  ```
447
485
 
448
- ### 6. Single Output File
486
+ ### 7. Single Output File
449
487
 
450
488
  **Config:**
451
489
 
@@ -459,7 +497,7 @@ const config: TypeSharpConfig = {
459
497
 
460
498
  All types will be generated in `src/types/types.ts`
461
499
 
462
- ### 7. Custom Naming Conventions
500
+ ### 8. Custom Naming Conventions
463
501
 
464
502
  **Config:**
465
503
 
@@ -517,7 +555,7 @@ generateTypes();
517
555
 
518
556
  ## Requirements
519
557
 
520
- - Node.js >= 14
558
+ - Node.js >= 20
521
559
  - TypeScript >= 4.5 (if using TypeScript config)
522
560
 
523
561
  ## License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@siyavuyachagi/typesharp",
3
3
  "description": "Generate TypeScript types from C# models with TypeSharp attribute",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "license": "MIT",
6
6
  "author": "Siyavuya Chagi <syavuya08@gmail.com>",
7
7
  "repository": {
@@ -40,11 +40,11 @@
40
40
  "devDependencies": {
41
41
  "@types/node": "^25.0.0",
42
42
  "@vitest/ui": "^4.0.18",
43
- "tsx": "^4.21.0",
44
43
  "typescript": "^5.9.3",
45
44
  "vitest": "^4.0.18"
46
45
  },
47
46
  "dependencies": {
47
+ "tsx": "^4.21.0",
48
48
  "chalk": "^5.6.2",
49
49
  "commander": "^14.0.2",
50
50
  "glob": "^13.0.0"