ilx1-x-tool 1.0.0 → 1.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 +94 -47
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,56 +1,112 @@
|
|
|
1
|
-
# x-tool
|
|
1
|
+
# ilx1-x-tool
|
|
2
2
|
|
|
3
3
|
一个实用的 TypeScript 工具函数库,包含各种常用的工具函数。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install x-tool
|
|
8
|
+
npm install ilx1-x-tool
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## 使用
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
// 数组去重
|
|
17
|
-
const uniqueArray = unique([1, 2, 2, 3, 3, 3]);
|
|
18
|
-
|
|
19
|
-
// 字符串首字母大写
|
|
20
|
-
const capitalized = capitalize('hello world');
|
|
21
|
-
|
|
22
|
-
// 防抖函数
|
|
23
|
-
const debouncedFn = debounce(() => {
|
|
24
|
-
console.log('防抖执行');
|
|
25
|
-
}, 300);
|
|
14
|
+
import { xxx } from 'ilx1-x-tool'
|
|
26
15
|
```
|
|
27
16
|
|
|
28
17
|
## API 文档
|
|
29
18
|
|
|
30
|
-
###
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- `
|
|
34
|
-
- `
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- `
|
|
40
|
-
- `
|
|
41
|
-
|
|
42
|
-
- `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- `
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
### 颜色工具 (color.ts)
|
|
20
|
+
|
|
21
|
+
#### 颜色解析与转换
|
|
22
|
+
- `parseColorString(str: string): ParsedColor | null` - 解析颜色字符串(支持 rgb/rgba/hsv/hsl 格式)
|
|
23
|
+
- `str`: 待解析的颜色字符串(如 "hsl(120, 100%, 50%)"、"hsla(240, 50%, 70%, 0.8)")
|
|
24
|
+
|
|
25
|
+
- `hslToRgb(hsl: ParsedHSL | ParsedHSLA | null): ParsedColor | null` - HSL 转 RGB 颜色转换
|
|
26
|
+
- `hsl`: HSL 颜色对象(分量范围 0-255)
|
|
27
|
+
|
|
28
|
+
- `rgbToHsl(rgb: ParsedRGB | ParsedRGBA | null): ParsedColor | null` - RGB 转 HSL 颜色转换
|
|
29
|
+
- `rgb`: RGB 颜色对象(分量范围 0-255)
|
|
30
|
+
|
|
31
|
+
- `hsvToHsl(hsv: ParsedHSV): ParsedColor` - HSV 转 HSL 颜色转换
|
|
32
|
+
- `hsv`: HSV 颜色对象(分量范围 0-255)
|
|
33
|
+
|
|
34
|
+
- `hslToHsv(hsl: ParsedHSL): ParsedColor` - HSL 转 HSV 颜色转换
|
|
35
|
+
- `hsl`: HSL 颜色对象(分量范围 0-255)
|
|
36
|
+
|
|
37
|
+
### 数据处理工具 (data.ts)
|
|
38
|
+
|
|
39
|
+
#### 字节序处理
|
|
40
|
+
- `Endianness` - 字节序枚举(LITTLE: 'little', BIG: 'big')
|
|
41
|
+
|
|
42
|
+
#### 数字与字节数组转换
|
|
43
|
+
- `numToBytes(number: number, byteCount: number, endian: Endianness = Endianness.BIG): number[]` - 将数字转换为指定字节序的字节数组
|
|
44
|
+
- `number`: 待转换的数字(自动截断为无符号整数)
|
|
45
|
+
- `byteCount`: 目标字节长度(必须为正整数)
|
|
46
|
+
- `endian`: 字节序(默认大端)
|
|
47
|
+
|
|
48
|
+
- `bytesToNum(bytes: number[], endian: Endianness = Endianness.BIG): number` - 将任意长度的字节数组转换为数字(支持不同字节序)
|
|
49
|
+
- `bytes`: 字节数组
|
|
50
|
+
- `endian`: 字节序(默认小端)
|
|
51
|
+
|
|
52
|
+
- `numToBits16(number: number, endian: Endianness = Endianness.BIG): [number, number]` - 将数字转换为16位无符号整数的指定字节序字节数组(固定2字节)
|
|
53
|
+
- `number`: 待转换的数字(自动截断为16位无符号整数范围)
|
|
54
|
+
- `endian`: 字节序(默认小端)
|
|
55
|
+
|
|
56
|
+
- `bits16ToNum(bytes: [number, number], endian: Endianness = Endianness.BIG): number` - 将16位字节数组转换为数字
|
|
57
|
+
- `bytes`: 长度为2的字节数组
|
|
58
|
+
- `endian`: 字节序(默认小端)
|
|
59
|
+
|
|
60
|
+
#### ASCII 码转换
|
|
61
|
+
- `numToAsciiArr(n: number): number[]` - 将数字转换为ASCII码值数组(每个数字转换为其对应的ASCII码)
|
|
62
|
+
- `n`: 待转换的数字(自动取绝对值)
|
|
63
|
+
|
|
64
|
+
- `asciiArrToNum(ascii: number[]): number` - 将ASCII码值数组转换为对应的数字
|
|
65
|
+
- `ascii`: ASCII码值数组(每个元素为0-255的整数)
|
|
66
|
+
|
|
67
|
+
### Gzip 压缩工具 (gzip.ts)
|
|
68
|
+
|
|
69
|
+
#### JSON 压缩与解压
|
|
70
|
+
- `compressJsonGzip(data: any): Blob` - gzip 压缩 JSON 数据(转成 Blob,适合导出)
|
|
71
|
+
- `data`: 待压缩的 JSON 数据
|
|
72
|
+
|
|
73
|
+
- `decompressJsonGzip(file: File): Promise<any>` - 解压 gzip 格式的 JSON 文件
|
|
74
|
+
- `file`: 待解压的 gzip 文件
|
|
75
|
+
|
|
76
|
+
### HID 键码工具 (hidKeyCode.ts)
|
|
77
|
+
|
|
78
|
+
#### 键码映射
|
|
79
|
+
- `hidKeyCode` - HID 键码数组,包含各种按键的键码信息
|
|
80
|
+
|
|
81
|
+
#### 键码映射获取
|
|
82
|
+
- `getHIDCodeMapStr(): Map<string, (typeof hidKeyCode)[0]>` - 获取 HID 键码映射(主键名 + 别名)
|
|
83
|
+
|
|
84
|
+
- `getHIDCodeMapStrNum(): Map<number, (typeof hidKeyCode)[0]>` - 获取 HID 键码映射(value 映射)
|
|
85
|
+
|
|
86
|
+
### 结果工具 (result.ts)
|
|
87
|
+
|
|
88
|
+
#### 结果对象创建
|
|
89
|
+
- `successResult<T = unknown>(data: T = null as unknown as T, message: string = '', code: number = 0): Result<T>` - 创建成功的结果对象
|
|
90
|
+
- `data`: 业务数据(可选,默认 null)
|
|
91
|
+
- `message`: 成功信息(可选,默认空字符串)
|
|
92
|
+
- `code`: 成功状态码(可选,默认 0)
|
|
93
|
+
|
|
94
|
+
- `errorResult<T = unknown>(message: string, code: number = -1, data: T = null as unknown as T): Result<T>` - 创建失败的结果对象
|
|
95
|
+
- `message`: 错误信息(必选)
|
|
96
|
+
- `code`: 错误码(可选,默认 -1)
|
|
97
|
+
- `data`: 错误相关数据(可选,默认 null)
|
|
98
|
+
|
|
99
|
+
### 常用工具 (usual.ts)
|
|
100
|
+
|
|
101
|
+
#### UI 相关
|
|
102
|
+
- `isShowPopover(popId: string): boolean` - 判断 popover 是否显示
|
|
103
|
+
- `popId`: popover 元素的 ID
|
|
104
|
+
|
|
105
|
+
#### 图片处理
|
|
106
|
+
- `isImageValid(src: string | File): Promise<boolean>` - 判断图片是否有效
|
|
107
|
+
- `src`: 图片 URL 或 File 对象
|
|
108
|
+
|
|
109
|
+
|
|
54
110
|
|
|
55
111
|
## 开发
|
|
56
112
|
|
|
@@ -58,17 +114,8 @@ const debouncedFn = debounce(() => {
|
|
|
58
114
|
# 安装依赖
|
|
59
115
|
npm install
|
|
60
116
|
|
|
61
|
-
# 开发模式(监听文件变化)
|
|
62
|
-
npm run dev
|
|
63
|
-
|
|
64
117
|
# 构建
|
|
65
118
|
npm run build
|
|
66
|
-
|
|
67
|
-
# 测试
|
|
68
|
-
npm test
|
|
69
|
-
|
|
70
|
-
# 代码检查
|
|
71
|
-
npm run lint
|
|
72
119
|
```
|
|
73
120
|
|
|
74
121
|
## 许可证
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilx1-x-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "工具库",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"author": "iLx1",
|
|
22
22
|
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"fflate": "^0.8.2"
|
|
25
|
+
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"@types/node": "^25.0.9",
|
|
25
28
|
"tsup": "^8.5.1",
|
|
@@ -32,8 +35,5 @@
|
|
|
32
35
|
"bugs": {
|
|
33
36
|
"url": "https://github.com/iLx11/x-tool/issues"
|
|
34
37
|
},
|
|
35
|
-
"homepage": "https://github.com/iLx11/x-tool#readme"
|
|
36
|
-
"dependencies": {
|
|
37
|
-
"fflate": "^0.8.2"
|
|
38
|
-
}
|
|
38
|
+
"homepage": "https://github.com/iLx11/x-tool#readme"
|
|
39
39
|
}
|