Skip to content

Commit a90d624

Browse files
committed
docs(readme): update feature list and usage examples
Document newly added toolkit capabilities in README, including WebView2 cookie import/export, JSON validation and array parsing, console output capture for JavaScript runners, common utility helpers, and temporary request headers. Also fix namespace casing in code samples to keep examples accurate and consistent with the package name.
1 parent 1f1b3ff commit a90d624

13 files changed

Lines changed: 117 additions & 50 deletions

README.md

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
## 功能特性
88

99
- **HTTP请求处理**:简化HTTP客户端操作,支持各种HTTP方法和请求配置,支持HTTP/HTTPS和SOCKS4/SOCKS5代理
10-
- **Cookie管理**:完整的Cookie管理功能,支持添加、获取、删除和批量操作
11-
- **JSON解析**:灵活的JSON序列化和反序列化,支持动态类型和自定义类型
10+
- **Cookie管理**:完整的Cookie管理功能,支持添加、获取、删除和批量操作,支持导入/导出WebView2 Cookie
11+
- **JSON解析**:灵活的JSON序列化和反序列化,支持动态类型和自定义类型,支持JSON验证、数组解析、DateTime转换
1212
- **URL工具**:URL参数处理、排序和转换工具
1313
- **AES加密**:安全的AES加密和解密功能,支持多种加密模式和填充方式
1414
- **内存缓存**:基于内存的临时缓存实现,支持TTL设置和自动清理
1515
- **线程池管理**:简单高效的线程池实现,支持任务队列和任务等待
16-
- **JavaScript执行**:支持两种执行方式,JintRunner(纯.NET实现,无需Node.js)和NodeJsRunner(需要Node.js),支持代码字符串和文件执行、方法调用、变量管理、函数调用等丰富功能
16+
- **JavaScript执行**:支持两种执行方式,JintRunner(纯.NET实现,无需Node.js)和NodeJsRunner(需要Node.js),支持代码字符串和文件执行、方法调用、变量管理、函数调用、控制台输出捕获等丰富功能
1717
- **身份证验证**:提供中国身份证号码验证、地址提取、性别识别等功能,支持18位身份证号码的完整校验
1818
- **OCR 识别**:集成 UmiOCR,支持图片与文档文字识别,提供图片 OCR(`OCR`)与文档 OCR(`Doc`),可配置识别语言、输出格式、角度检测、忽略区域等参数
1919
- **Base64 编码**:提供文件、字节数组、字符串等多种数据格式的 Base64 编码功能
20+
- **通用工具**:随机Hex生成、生肖查询、文件扩展名提取、随机字符串生成等工具方法
21+
- **临时请求头**:支持临时请求头设置(仅对单次请求有效)
2022
- **.NET Standard 2.1兼容**:支持.NET Core、.NET Framework和其他兼容平台
2123
- **模块化设计**:各功能模块相互独立,便于扩展和维护
2224
- **持续更新**:计划逐步添加更多常用功能模块
@@ -40,7 +42,7 @@ dotnet add package WodToolKit
4042
### 内存缓存示例
4143

4244
```csharp
43-
using WodToolkit.src.Cache;
45+
using WodToolKit.src.Cache;
4446

4547
// 创建临时缓存实例(每30秒清理一次,默认TTL为300秒)
4648
var cache = new TempCache<string, string>(TimeSpan.FromSeconds(30), 300);
@@ -68,7 +70,7 @@ cache.Remove("key2");
6870
### 线程池使用示例
6971

7072
```csharp
71-
using WodToolkit.src.Thread;
73+
using WodToolKit.src.Thread;
7274

7375
// 创建线程池(4个工作线程)
7476
var threadPool = new SimpleThreadPool(4);
@@ -95,7 +97,7 @@ Console.WriteLine("所有任务执行完毕");
9597
### HTTP请求示例
9698

9799
```csharp
98-
using WodToolkit.Http;
100+
using WodToolKit.Http;
99101
using System.Net;
100102
using System.Collections.Generic;
101103

@@ -145,7 +147,7 @@ var asyncRequest = new HttpRequestClass();
145147
// 设置超时时间
146148
asyncRequest.SetTimeout(30); // 30秒
147149
// 设置UserAgent
148-
asyncRequest.SetUserAgent("Mozilla/5.0 WodToolkit");
150+
asyncRequest.SetUserAgent("Mozilla/5.0 WodToolKit");
149151
// 异步发送请求
150152
await asyncRequest.Open("https://api.example.com/data", HttpMethod.Get).SendAsync();
151153
var asyncResponse = asyncRequest.GetResponse();
@@ -221,15 +223,24 @@ string sessionId = cookieManager.GetCookieValue("sessionId");
221223
```csharp
222224
using WodToolKit.Json;
223225

224-
// 解析JSON字符串
226+
// 1. 解析JSON字符串为动态对象
225227
string json = "{\"name\": \"Example\", \"value\": 42}";
226228
dynamic result = EasyJson.ParseJsonToDynamic(json);
227-
228-
// 访问动态对象属性
229229
Console.WriteLine(result.name); // 输出: Example
230230
Console.WriteLine(result.value); // 输出: 42
231231
232-
// 解析为强类型对象
232+
// 2. 验证字符串是否为有效的JSON格式
233+
bool isValid = EasyJson.IsValidJson("{\"key\": \"value\"}");
234+
Console.WriteLine($"是否为有效JSON: {isValid}"); // 输出: True
235+
236+
// 3. 解析JSON数组为指定类型的数组
237+
string jsonArray = "[1, 2, 3, 4, 5]";
238+
int[] numbers = EasyJson.ParseJsonArray<int>(jsonArray);
239+
240+
// 4. 解析JSON数组为动态列表
241+
List<object> list = EasyJson.ParseAnyJsonArray(jsonArray);
242+
243+
// 5. 解析为强类型对象(支持自定义类型和DateTime转换)
233244
var obj = EasyJson.ParseJsonObject<MyClass>(json);
234245
```
235246

@@ -259,7 +270,7 @@ WodToolKit 提供了两种 JavaScript 执行器:`NodeJsRunner`(需要 Node.j
259270
#### 方式一:使用 JintRunner(推荐,无需 Node.js)
260271

261272
```csharp
262-
using WodToolkit.Script;
273+
using WodToolKit.Script;
263274

264275
// 创建 Jint 执行器(纯 .NET 实现,无需安装 Node.js)
265276
using (var jintRunner = new JintRunner())
@@ -382,7 +393,7 @@ using (var jintRunner = new JintRunner())
382393
#### 方式二:使用 NodeJsRunner(需要安装 Node.js)
383394

384395
```csharp
385-
using WodToolkit.Script;
396+
using WodToolKit.Script;
386397

387398
// 创建 Node.js 执行器(需要系统已安装 Node.js)
388399
using (var nodeRunner = new NodeJsRunner())
@@ -482,7 +493,7 @@ module.exports = {
482493
### 身份证验证示例
483494

484495
```csharp
485-
using WodToolkit.src.Common;
496+
using WodToolKit.src.Common;
486497

487498
// 1. 验证身份证号码是否合法
488499
string idCard = "110101199001011234";
@@ -570,7 +581,7 @@ Console.WriteLine(docResult.TextContent);
570581
### Base64 编码示例
571582

572583
```csharp
573-
using WodToolkit.src.Common;
584+
using WodToolKit.src.Common;
574585

575586
// 1. 从文件路径编码为 Base64
576587
string base64FromFile = Common.Base64Encode(@"C:\path\to\image.jpg");
@@ -585,6 +596,43 @@ string base64FromText = Common.Base64Encode("Hello World", null);
585596
string base64FromText2 = Common.Base64Encode("你好世界", Encoding.UTF8);
586597
```
587598

599+
### 通用工具方法示例
600+
601+
```csharp
602+
using WodToolKit.src.Common;
603+
604+
// 1. 生成随机 16 进制字符串(线程安全)
605+
string hex = Common.Generate(32, true);
606+
Console.WriteLine($"随机Hex: {hex}");
607+
608+
// 2. 获取指定年份的生肖
609+
string zodiac = Common.getChineseZodiac(2024);
610+
Console.WriteLine($"2024年生肖: {zodiac}");
611+
612+
// 3. 获取文件扩展名
613+
string ext = Common.GetFileExtension("document.pdf");
614+
Console.WriteLine($"扩展名: {ext}"); // 输出: pdf
615+
616+
// 4. 生成随机字符串(首位为字母)
617+
string randomStr = Common.GetRandomString(10);
618+
Console.WriteLine($"随机字符串: {randomStr}");
619+
```
620+
621+
### 临时请求头示例
622+
623+
```csharp
624+
using WodToolKit.Http;
625+
626+
// 设置临时请求头(仅对下一次请求有效)
627+
var request = new HttpRequestClass();
628+
request.SetTemporaryHeader("X-Custom-Header", "custom-value")
629+
.SetTemporaryHeader("Authorization", "Bearer token")
630+
.Open("https://api.example.com/data", HttpMethod.Get)
631+
.Send();
632+
// 请求发送后,临时头会自动清除
633+
var response = request.GetResponse();
634+
```
635+
588636
## 项目架构与组织
589637

590638
WodToolKit采用模块化设计,各功能模块相互独立,便于扩展和维护。整体架构围绕核心功能模块展开,通过清晰的命名空间和类层次结构提供统一的使用体验。
@@ -627,7 +675,7 @@ WodToolKit
627675
│ ├── Script/ # JavaScript执行和方法调用功能
628676
│ ├── Thread/ # 线程管理功能
629677
│ └── UmiOCR/ # OCR 识别功能
630-
├── WodToolkit.csproj # 项目文件
678+
├── WodToolKit.csproj # 项目文件
631679
└── README.md # 项目文档
632680
```
633681

WodToolkit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackAsTool>False</PackAsTool>
77
<!-- NuGet包元数据 -->
88
<PackageId>WodToolKit</PackageId>
9-
<Version>1.0.2.6</Version>
9+
<Version>1.0.2.7</Version>
1010
<Title>WodToolKit - 轻量级.NET工具库</Title>
1111
<Authors>Wod</Authors>
1212
<Company>Wod</Company>

WodToolkit.wiki

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/README_EN.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ A lightweight .NET toolkit that provides encapsulation of various common functio
88

99
- **HTTP Request Handling**: Simplified HTTP client operations, supporting various HTTP methods and request configurations, with support for HTTP/HTTPS and SOCKS4/SOCKS5 proxies
1010
- **Cookie Management**: Complete cookie management functionality, supporting addition, retrieval, deletion, and batch operations
11-
- **JSON Parsing**: Flexible JSON serialization and deserialization, supporting dynamic types and custom types
11+
- **JSON Parsing**: Flexible JSON serialization and deserialization, supporting dynamic types and custom types, with JSON validation, array parsing, and DateTime conversion support
1212
- **URL Tools**: URL parameter processing, sorting, and conversion utilities
1313
- **AES Encryption**: Secure AES encryption and decryption functionality, supporting multiple encryption modes and padding methods
1414
- **Memory Cache**: Memory-based temporary cache implementation with TTL settings and automatic cleanup
1515
- **Thread Pool Management**: Simple and efficient thread pool implementation supporting task queuing and waiting
16-
- **JavaScript Execution**: Supports two execution methods, JintRunner (pure .NET implementation, no Node.js required) and NodeJsRunner (requires Node.js), supporting code string and file execution, as well as calling specific methods with parameters
16+
- **JavaScript Execution**: Supports two execution methods, JintRunner (pure .NET implementation, no Node.js required) and NodeJsRunner (requires Node.js), supporting code string and file execution, method calls with parameters, variable management, and console output capture
17+
- **ID Card Verification**: Chinese ID card number verification, address extraction, and gender identification (supports 18-digit ID cards)
18+
- **OCR Recognition**: Integrated UmiOCR, supporting image and document text recognition with configurable language, output format, angle detection, and ignore regions
19+
- **Base64 Encoding**: Support for file, byte array, and string Base64 encoding
20+
- **Common Utilities**: Random hex generation, Chinese zodiac lookup, file extension extraction, and random string generation
1721
- **.NET Standard 2.1 Compatibility**: Supports .NET Core, .NET Framework, and other compatible platforms
1822
- **Modular Design**: Each functional module is independent, facilitating extension and maintenance
1923
- **Continuous Updates**: Plans to gradually add more common function modules
@@ -37,7 +41,7 @@ dotnet add package WodToolKit
3741
### Memory Cache Example
3842

3943
```csharp
40-
using WodToolkit.src.Cache;
44+
using WodToolKit.src.Cache;
4145

4246
// Create temporary cache instance (cleans every 30 seconds, default TTL is 300 seconds)
4347
var cache = new TempCache<string, string>(TimeSpan.FromSeconds(30), 300);
@@ -65,7 +69,7 @@ cache.Remove("key2");
6569
### Thread Pool Usage Example
6670

6771
```csharp
68-
using WodToolkit.src.Thread;
72+
using WodToolKit.src.Thread;
6973

7074
// Create thread pool (4 worker threads)
7175
var threadPool = new SimpleThreadPool(4);
@@ -92,7 +96,7 @@ Console.WriteLine("All tasks completed");
9296
### HTTP Request Example
9397

9498
```csharp
95-
using WodToolkit.Http;
99+
using WodToolKit.Http;
96100
using System.Net;
97101
using System.Collections.Generic;
98102

@@ -218,15 +222,24 @@ string sessionId = cookieManager.GetCookieValue("sessionId");
218222
```csharp
219223
using WodToolKit.Json;
220224

221-
// Parse JSON string
225+
// 1. Parse JSON string to dynamic object
222226
string json = "{\"name\": \"Example\", \"value\": 42}";
223227
dynamic result = EasyJson.ParseJsonToDynamic(json);
224-
225-
// Access dynamic object properties
226228
Console.WriteLine(result.name); // Output: Example
227229
Console.WriteLine(result.value); // Output: 42
228230
229-
// Parse to strongly typed object
231+
// 2. Validate if string is valid JSON format
232+
bool isValid = EasyJson.IsValidJson("{\"key\": \"value\"}");
233+
Console.WriteLine($"Is valid JSON: {isValid}"); // Output: True
234+
235+
// 3. Parse JSON array to array of specified type
236+
string jsonArray = "[1, 2, 3, 4, 5]";
237+
int[] numbers = EasyJson.ParseJsonArray<int>(jsonArray);
238+
239+
// 4. Parse JSON array to dynamic list
240+
List<object> list = EasyJson.ParseAnyJsonArray(jsonArray);
241+
242+
// 5. Parse JSON to strongly typed object (supports custom types and DateTime conversion)
230243
var obj = EasyJson.ParseJsonObject<MyClass>(json);
231244
```
232245

@@ -256,7 +269,7 @@ WodToolKit provides two JavaScript executors: `NodeJsRunner` (requires Node.js)
256269
#### Method 1: Using JintRunner (Recommended, No Node.js Required)
257270

258271
```csharp
259-
using WodToolkit.Script;
272+
using WodToolKit.Script;
260273

261274
// Create Jint executor (pure .NET implementation, no Node.js installation needed)
262275
using (var jintRunner = new JintRunner())
@@ -349,7 +362,7 @@ using (var jintRunner = new JintRunner())
349362
#### Method 2: Using NodeJsRunner (Requires Node.js Installation)
350363

351364
```csharp
352-
using WodToolkit.Script;
365+
using WodToolKit.Script;
353366

354367
// Create Node.js executor (requires Node.js to be installed on the system)
355368
using (var nodeRunner = new NodeJsRunner())
@@ -464,8 +477,15 @@ WodToolKit
464477
│ └── SimpleThreadPool # Thread pool implementation
465478
├── Encode/ # Encryption functionality
466479
│ └── AesCrypt # AES encryption and decryption
467-
└── Script/ # Script execution
468-
└── NodeJsRunner # Node.js script executor
480+
├── Script/ # Script execution
481+
│ ├── JintRunner # Jint JavaScript executor (pure .NET)
482+
│ └── NodeJsRunner # Node.js script executor
483+
├── UmiOCR/ # OCR recognition
484+
│ ├── OCR # Image OCR (/api/ocr)
485+
│ └── Doc # Document OCR (/api/doc)
486+
└── Common/ # Common utilities
487+
├── IDCard # ID card verification and info extraction
488+
└── Common # Common utility methods (Base64 encoding, etc.)
469489
```
470490

471491
### Project Structure
@@ -478,7 +498,7 @@ WodToolKit
478498
│ ├── Json/ # JSON processing functionality
479499
│ ├── Script/ # JavaScript execution and method call functionality
480500
│ └── Thread/ # Thread management functionality
481-
├── WodToolkit.csproj # Project file
501+
├── WodToolKit.csproj # Project file
482502
└── README.md # Project documentation
483503
```
484504

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: WodToolKit
22
description: 轻量级.NET工具库,提供各类常用功能的封装
3-
baseurl: "/WodToolkit"
3+
baseurl: "/WodToolKit"
44
url: "https://thiswod.github.io"
55

66
# 使用自定义布局

docs/cache.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WodToolKit 提供了基于内存的临时缓存实现,支持 TTL(生存时
1010
## 基本用法
1111

1212
```csharp
13-
using WodToolkit.src.Cache;
13+
using WodToolKit.src.Cache;
1414

1515
// 创建缓存实例(每30秒清理一次,默认TTL为300秒)
1616
var cache = new TempCache<string, string>(TimeSpan.FromSeconds(30), 300);
@@ -68,7 +68,7 @@ foreach (var key in keys)
6868
## 完整示例
6969

7070
```csharp
71-
using WodToolkit.src.Cache;
71+
using WodToolKit.src.Cache;
7272
using System;
7373

7474
var cache = new TempCache<string, string>(

docs/cookie.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WodToolKit 提供了完整的 Cookie 管理功能,支持添加、获取、删
1010
## 基本用法
1111

1212
```csharp
13-
using WodToolkit.Http;
13+
using WodToolKit.Http;
1414

1515
// 创建 Cookie 管理器
1616
var cookieManager = new CookieManager();
@@ -92,7 +92,7 @@ cookieManager.ClearCookies();
9292
## 在 HTTP 请求中使用
9393

9494
```csharp
95-
using WodToolkit.Http;
95+
using WodToolKit.Http;
9696

9797
var httpRequest = new HttpRequestClass();
9898

@@ -113,7 +113,7 @@ httpRequest.CookieManager().SetCookie(newCookies);
113113
## 完整示例
114114

115115
```csharp
116-
using WodToolkit.Http;
116+
using WodToolKit.Http;
117117

118118
var cookieManager = new CookieManager();
119119

docs/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dotnet add package WodToolKit
3232
### HTTP 请求示例
3333

3434
```csharp
35-
using WodToolkit.Http;
35+
using WodToolKit.Http;
3636
using System.Net;
3737

3838
// 创建 HTTP 请求实例
@@ -55,7 +55,7 @@ if (response.StatusCode == 200)
5555
### Cookie 管理示例
5656

5757
```csharp
58-
using WodToolkit.Http;
58+
using WodToolKit.Http;
5959

6060
// 创建 Cookie 管理器
6161
var cookieManager = new CookieManager();
@@ -72,7 +72,7 @@ Console.WriteLine(cookieString); // 输出: sessionId=abc123; userId=user456
7272
### JavaScript 执行示例
7373

7474
```csharp
75-
using WodToolkit.Script;
75+
using WodToolKit.Script;
7676

7777
// 使用 JintRunner(推荐,无需 Node.js)
7878
using (var jintRunner = new JintRunner())

0 commit comments

Comments
 (0)