hsu-utils 0.0.26 → 0.0.28
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/LICENSE +21 -21
- package/README.md +82 -78
- package/dist/hsu-utils.js +7 -7
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/GetStrSize/index.d.ts +12 -0
- package/es/{GetStrWidth → GetStrSize}/index.js +3 -2
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/lib/GetStrSize/index.d.ts +12 -0
- package/lib/{GetStrWidth → GetStrSize}/index.js +4 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/package.json +59 -59
- package/es/GetStrWidth/index.d.ts +0 -9
- package/lib/GetStrWidth/index.d.ts +0 -9
package/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2023 VitaHsu
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 VitaHsu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1,78 +1,82 @@
|
|
1
|
-
# [Hsu Utils](https://github.com/VitaTsui/hsu-utils#hsu-utils)
|
2
|
-
|
3
|
-
## 前言
|
4
|
-
|
5
|
-
`hsu-utils` 一些前端的工具集
|
6
|
-
|
7
|
-
## 安装
|
8
|
-
|
9
|
-
```sh
|
10
|
-
npm install --save hsu-utils
|
11
|
-
# 或
|
12
|
-
yarn add hsu-utils
|
13
|
-
```
|
14
|
-
|
15
|
-
## 功能
|
16
|
-
|
17
|
-
| 方法 | 子方法 | 说明 | 类型
|
18
|
-
| ----------------- | ------------ | ------------------------------- |
|
19
|
-
| array_is_includes | - | 判断一个数组是否包含另一个数组 | \<T>(arr1: Array\<T>, arr2: Array\<T>) => boolean
|
20
|
-
| console_table | - | 在控制台打印像 MySql 一样的表格 | (data: [ConsoleData](#consoledata), callBack?: (str: string) => void) => void
|
21
|
-
| ConvertNumbers | toChineseNum | 数字转中文 | (num: number, options?: [C_Options](#c_options)) => string
|
22
|
-
| deepCopy | - | 深拷贝 | <T = any>(data: T) => T
|
23
|
-
| downloadFile | - | 文件下载 | (file: ArrayBuffer \| string, fileName: string) => void
|
24
|
-
| Equal | ValEqual | 判断值相等 | <T = unknown>(obj1: T, obj2: T) => boolean
|
25
|
-
| | TypeEqual | 判断类型相同 | <T = unknown>(obj1: T, obj2: T) => boolean
|
26
|
-
| | ObjEqual | 判断对象相等 | <T = object>(obj1: T, obj2: T) => boolean
|
27
|
-
|
|
28
|
-
| loadImage | - | 异步加载图片并缓存 | (url: string) => Promise\<HTMLImageElement>
|
29
|
-
| RenderPDF | load | 用于预加载 PDF | (pdfUrl: string) => Promise\<PDFDocumentProxy>
|
30
|
-
| | getNumPages | 获取 PDF 页数 | (pdfUrl: string): Promise\<number>
|
31
|
-
| | clear | 删除已渲染的 PDF | (containerId: string) => void
|
32
|
-
| | render | 渲染 PDF | (options: [RenderOption](#renderoption)) => Promise\<void>
|
33
|
-
| Typeof | - | 获取类型或判断类型 | \<T>(value: T, isType?: [Type](#type)) => boolean
|
34
|
-
|
35
|
-
## 类型
|
36
|
-
|
37
|
-
### ConsoleData
|
38
|
-
|
39
|
-
> type ConsoleData = Array<Array<string | number>>
|
40
|
-
|
41
|
-
### C_Options
|
42
|
-
|
43
|
-
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
44
|
-
| --------- | ------------ | -------- | --------- | ---- |
|
45
|
-
| benchmark | 乘数 | number | - | - |
|
46
|
-
| textType | 输出文字样式 | TextType | lowercase | - |
|
47
|
-
|
48
|
-
> type TextType = 'lowercase' | 'uppercase'
|
49
|
-
|
50
|
-
`lowercase` ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
|
51
|
-
`uppercase` ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
|
52
|
-
|
53
|
-
### Font
|
54
|
-
|
55
|
-
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
56
|
-
| ------- | -------- | ------ | -------- | ---- |
|
57
|
-
| size | 字体大小 | number | 12 | - |
|
58
|
-
| style | 字体样式 | string | normal | - |
|
59
|
-
| variant | 字体变体 | string | normal | - |
|
60
|
-
| weight | 字体粗细 | string | normal | - |
|
61
|
-
| family | 字体系列 | string | 微软雅黑 | - |
|
62
|
-
|
63
|
-
### RenderOption
|
64
|
-
|
65
|
-
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
66
|
-
| ------------ | ------------ | ------ | ------ | ---- |
|
67
|
-
| pdfUrl | pdf 文件地址 | string | - | 必填 |
|
68
|
-
| containerId | pdf 容器 id | string | normal | 必填 |
|
69
|
-
| startPageNum | 开始页码 | number | normal | - |
|
70
|
-
| endPageNum | 结束页码 | number | normal | - |
|
71
|
-
| pixelRatio | 像素比例 | number | 2 | - |
|
72
|
-
| scale | 缩放 | number | 1 | - |
|
73
|
-
|
74
|
-
### Type
|
75
|
-
|
76
|
-
> type BaseType = 'string' | 'number' | 'boolean' | 'undefined' | 'function' | 'symbol' | 'bigint'
|
77
|
-
> type ObjectType = 'object' | 'array' | 'null' | 'date' | 'formdata' | 'set' | 'map' | 'regexp' | 'arraybuffer' | 'blob'
|
78
|
-
> type Type = BaseType | ObjectType
|
1
|
+
# [Hsu Utils](https://github.com/VitaTsui/hsu-utils#hsu-utils)
|
2
|
+
|
3
|
+
## 前言
|
4
|
+
|
5
|
+
`hsu-utils` 一些前端的工具集
|
6
|
+
|
7
|
+
## 安装
|
8
|
+
|
9
|
+
```sh
|
10
|
+
npm install --save hsu-utils
|
11
|
+
# 或
|
12
|
+
yarn add hsu-utils
|
13
|
+
```
|
14
|
+
|
15
|
+
## 功能
|
16
|
+
|
17
|
+
| 方法 | 子方法 | 说明 | 类型 | 备注 |
|
18
|
+
| ----------------- | ------------ | ------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------- |
|
19
|
+
| array_is_includes | - | 判断一个数组是否包含另一个数组 | \<T>(arr1: Array\<T>, arr2: Array\<T>) => boolean | - |
|
20
|
+
| console_table | - | 在控制台打印像 MySql 一样的表格 | (data: [ConsoleData](#consoledata), callBack?: (str: string) => void) => void | - |
|
21
|
+
| ConvertNumbers | toChineseNum | 数字转中文 | (num: number, options?: [C_Options](#c_options)) => string | - |
|
22
|
+
| deepCopy | - | 深拷贝 | <T = any>(data: T) => T | - |
|
23
|
+
| downloadFile | - | 文件下载 | (file: ArrayBuffer \| string, fileName: string) => void | string 为 http(s) 地址或本地地址 |
|
24
|
+
| Equal | ValEqual | 判断值相等 | <T = unknown>(obj1: T, obj2: T) => boolean | - |
|
25
|
+
| | TypeEqual | 判断类型相同 | <T = unknown>(obj1: T, obj2: T) => boolean | - |
|
26
|
+
| | ObjEqual | 判断对象相等 | <T = object>(obj1: T, obj2: T) => boolean | - |
|
27
|
+
| get_string_size | - | 获取字符串大小 | (str: string, font?: [Font](#font), letterSpacing?: number) => { width: number; height: number } | - |
|
28
|
+
| loadImage | - | 异步加载图片并缓存 | (url: string) => Promise\<HTMLImageElement> | - |
|
29
|
+
| RenderPDF | load | 用于预加载 PDF | (pdfUrl: string) => Promise\<PDFDocumentProxy> | - |
|
30
|
+
| | getNumPages | 获取 PDF 页数 | (pdfUrl: string): Promise\<number> | - |
|
31
|
+
| | clear | 删除已渲染的 PDF | (containerId: string) => void | - |
|
32
|
+
| | render | 渲染 PDF | (options: [RenderOption](#renderoption)) => Promise\<void> | - |
|
33
|
+
| Typeof | - | 获取类型或判断类型 | \<T>(value: T, isType?: [Type](#type)) => boolean \| Type | - |
|
34
|
+
|
35
|
+
## 类型
|
36
|
+
|
37
|
+
### ConsoleData
|
38
|
+
|
39
|
+
> type ConsoleData = Array<Array<string | number>>
|
40
|
+
|
41
|
+
### C_Options
|
42
|
+
|
43
|
+
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
44
|
+
| --------- | ------------ | -------- | --------- | ---- |
|
45
|
+
| benchmark | 乘数 | number | - | - |
|
46
|
+
| textType | 输出文字样式 | TextType | lowercase | - |
|
47
|
+
|
48
|
+
> type TextType = 'lowercase' | 'uppercase'
|
49
|
+
|
50
|
+
`lowercase` ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
|
51
|
+
`uppercase` ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
|
52
|
+
|
53
|
+
### Font
|
54
|
+
|
55
|
+
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
56
|
+
| ------- | -------- | ------ | -------- | ---- |
|
57
|
+
| size | 字体大小 | number | 12 | - |
|
58
|
+
| style | 字体样式 | string | normal | - |
|
59
|
+
| variant | 字体变体 | string | normal | - |
|
60
|
+
| weight | 字体粗细 | string | normal | - |
|
61
|
+
| family | 字体系列 | string | 微软雅黑 | - |
|
62
|
+
|
63
|
+
### RenderOption
|
64
|
+
|
65
|
+
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
66
|
+
| ------------ | ------------ | ------ | ------ | ---- |
|
67
|
+
| pdfUrl | pdf 文件地址 | string | - | 必填 |
|
68
|
+
| containerId | pdf 容器 id | string | normal | 必填 |
|
69
|
+
| startPageNum | 开始页码 | number | normal | - |
|
70
|
+
| endPageNum | 结束页码 | number | normal | - |
|
71
|
+
| pixelRatio | 像素比例 | number | 2 | - |
|
72
|
+
| scale | 缩放 | number | 1 | - |
|
73
|
+
|
74
|
+
### Type
|
75
|
+
|
76
|
+
> type BaseType = 'string' | 'number' | 'boolean' | 'undefined' | 'function' | 'symbol' | 'bigint'
|
77
|
+
> type ObjectType = 'object' | 'array' | 'null' | 'date' | 'formdata' | 'set' | 'map' | 'regexp' | 'arraybuffer' | 'blob'
|
78
|
+
> type Type = BaseType | ObjectType
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
MIT
|
package/dist/hsu-utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* hsu-utils v0.0.
|
3
|
+
* hsu-utils v0.0.27
|
4
4
|
*
|
5
5
|
* some front-end utils
|
6
6
|
*
|
@@ -124,14 +124,14 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexpo
|
|
124
124
|
|
125
125
|
/***/ }),
|
126
126
|
|
127
|
-
/***/ "./tools/
|
128
|
-
|
129
|
-
!*** ./tools/
|
130
|
-
|
127
|
+
/***/ "./tools/GetStrSize/index.ts":
|
128
|
+
/*!***********************************!*\
|
129
|
+
!*** ./tools/GetStrSize/index.ts ***!
|
130
|
+
\***********************************/
|
131
131
|
/***/ ((__unused_webpack_module, exports) => {
|
132
132
|
|
133
133
|
"use strict";
|
134
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction
|
134
|
+
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction get_string_size(str, font, letterSpacing) {\n if (font === void 0) { font = {}; }\n if (letterSpacing === void 0) { letterSpacing = 0; }\n var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.variant, variant = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 12 : _d, _e = font.family, fontFamily = _e === void 0 ? '微软雅黑' : _e;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n ctx.font = \"\".concat(style, \" \").concat(variant, \" \").concat(weight, \" \").concat(size, \"px \").concat(fontFamily);\n var metrics = ctx.measureText(str);\n var width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);\n var height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);\n var _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;\n width += _letterSpacing;\n return { width: width, height: height };\n}\nexports[\"default\"] = get_string_size;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/GetStrSize/index.ts?");
|
135
135
|
|
136
136
|
/***/ }),
|
137
137
|
|
@@ -175,7 +175,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
175
175
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
176
176
|
|
177
177
|
"use strict";
|
178
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.array_is_includes = exports.downloadFile = exports.RenderPDF = exports.loadImage = exports.ConvertNumbers = exports.
|
178
|
+
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.array_is_includes = exports.downloadFile = exports.RenderPDF = exports.loadImage = exports.ConvertNumbers = exports.get_string_size = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\nvar GetStrSize_1 = __importDefault(__webpack_require__(/*! ./GetStrSize */ \"./tools/GetStrSize/index.ts\"));\nexports.get_string_size = GetStrSize_1.default;\nvar ConvertNumbers_1 = __importDefault(__webpack_require__(/*! ./ConvertNumbers */ \"./tools/ConvertNumbers/index.ts\"));\nexports.ConvertNumbers = ConvertNumbers_1.default;\nvar LoadImage_1 = __importDefault(__webpack_require__(/*! ./LoadImage */ \"./tools/LoadImage/index.ts\"));\nexports.loadImage = LoadImage_1.default;\nvar RenderPDF_1 = __importDefault(__webpack_require__(/*! ./RenderPDF */ \"./tools/RenderPDF/index.ts\"));\nexports.RenderPDF = RenderPDF_1.default;\nvar DownloadFile_1 = __importDefault(__webpack_require__(/*! ./DownloadFile */ \"./tools/DownloadFile/index.ts\"));\nexports.downloadFile = DownloadFile_1.default;\nvar ArrayIsIncludes_1 = __importDefault(__webpack_require__(/*! ./ArrayIsIncludes */ \"./tools/ArrayIsIncludes/index.ts\"));\nexports.array_is_includes = ArrayIsIncludes_1.default;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/index.ts?");
|
179
179
|
|
180
180
|
/***/ }),
|
181
181
|
|